Class AbstractExtComponentRepository<FSCRC extends FSCRDBComponent,DB extends FSComponentExtRepositoryDB<FSCRC>>

java.lang.Object
com.zfabrik.components.provider.util.AbstractExtComponentRepository<FSCRC,DB>
All Implemented Interfaces:
IComponentsRepository, ISynchronizer
Direct Known Subclasses:
AbstractComponentRepository

public abstract class AbstractExtComponentRepository<FSCRC extends FSCRDBComponent,DB extends FSComponentExtRepositoryDB<FSCRC>> extends Object implements IComponentsRepository, ISynchronizer
Abstract implementation of a component repository. This is by far the easiest way of implementing a component repository. The only methods needed to implement are
  1. scan(DB) to compute an update of the available components, their properties and revisions
  2. download(FSCRDC, File) to download a component's resources, if any, to a local file system folder
where FSCRC extends FSCRDBComponent and DB extends FSComponentRepositoryDB<FSCRC>.
Author:
hb
  • Field Details

  • Constructor Details

    • AbstractExtComponentRepository

      public AbstractExtComponentRepository(String name, Class<DB> clz)
  • Method Details

    • configure

      protected void configure(int prio, Long evictionDelay, String repoKey)
      Finish configuration. Must be called before using as repo and using root (not roots!) information. I.e. this should be called as early as possible BUT after determining the expected configuration that is used to decide whether a repo cache is to be evicted.
      Parameters:
      prio - Repository priority. See IComponentsRepository.
      evictionDelay - Delay of eviction for old component versions. This should be so high that concurrent home usage may not really happen. Defaults to 24h.
      repoKey - A key of the repo that identifies its cache space. For different usages, same name, repo key should. For example the dev repo may be used for different workspaces and is still one repo
    • getExpectedConfiguration

      protected Properties getExpectedConfiguration()
      provided expected repository configuration. This property set is used by the FSComponentRepositoryHelper to make a decision on whether the repository cache is still valid. Any change in repository configuration between repository initialization will be taken as reason to completely purge the local repository. By default this method returns the complete repository configuration.
    • configure

      protected void configure(int prio, Long evictionDelay)
      Is actually configure(prio,evictionDelay,this.name).
      Parameters:
      prio - Repository priority. See IComponentsRepository.
      evictionDelay - Delay of eviction for old component versions. This should be so high that concurrent home usage may not really happen. Defaults to 24h.
    • configure

      protected void configure(int prio)
      Is actually configure(prio,null).
      Parameters:
      prio - Repository priority. See IComponentsRepository.
    • getName

      public String getName()
    • getCacheRoot

      protected File getCacheRoot()
    • setEvictionDelay

      protected void setEvictionDelay(long evictionDelay)
      Set eviction of old component copies
    • has

      public static boolean has(Class<?> clz)
      Simple type helper for Resource implementations. Call this to check whether delegation to the component repository should be implemented
    • as

      public <T> T as(Class<T> clz)
      Simple type helper for Resource implementations. Call this to check whether delegation to the component repository should be implemented
    • getContext

      public IComponentsRepositoryContext getContext()
      gets the repository context
    • stop

      public void stop()
      Stop and unregister the repo. The instance becomes unusable after that
    • start

      public void start()
      Start the repository and register it.
    • preInvalidation

      public void preInvalidation(ISynchronization sync)
      pre invalidation collection of outdated components
      Specified by:
      preInvalidation in interface ISynchronizer
    • preInvalidation

      protected void preInvalidation(DB currentDB, DB newDB, ISynchronization sync)
      Can be overridden to add additional invalidation behavior based on the current DB and the new DB. Standard behavior has already applied when this method is called
      Parameters:
      currentDB -
      newDB -
      sync -
    • complete

      public void complete(ISynchronization sync)
      Description copied from interface: ISynchronizer
      synchronizers implement this method to re-establish any desired system state after all invalidations have been performed. Note that the set of synchronizer in this call may be different to before, due to new system content.
      Specified by:
      complete in interface ISynchronizer
    • getRevision

      public long getRevision(String cn, boolean localOnly) throws IOException
      Description copied from interface: IComponentsRepository
      return the most current revision of the component as available by the provider. providers must be able to count revs. A rev <0 indicates that the package is not known to the repository.

      If localOnly is set to true, only this repository is looked up. Otherwise all repositories in the chain with lower priority are considered too.

      Specified by:
      getRevision in interface IComponentsRepository
      Throws:
      IOException
    • findComponents

      public Collection<String> findComponents(X x, boolean localOnly) throws IOException
      Description copied from interface: IComponentsRepository
      finds all components satisfying a query condition. If localOnly is set to true, only this repository is queried. Otherwise all repositories in the chain with lower priority are considered too.

      If localOnly is set to true, only this repository is looked up. Otherwise all repositories in the chain with lower priority are considered too.

      Specified by:
      findComponents in interface IComponentsRepository
      Throws:
      IOException
    • getComponent

      public IComponentDescriptor getComponent(String cn, boolean localOnly)
      Description copied from interface: IComponentsRepository
      retrieves a component descriptor for a fully qualified component, e.g. <module>/java for a Java component. If localOnly is set to true, only this repository is looked up. Otherwise all repositories in the chain with lower priority are considered too.

      If localOnly is set to true, only this repository is looked up. Otherwise all repositories in the chain with lower priority are considered too.

      Specified by:
      getComponent in interface IComponentsRepository
    • retrieve

      public File retrieve(String cn, boolean localOnly) throws IOException
      Description copied from interface: IComponentsRepository
      Retrieve a component's resource folder. Every component has by definition a resource folder that reflects its repository defined content if any, or may be empty. This folder is a temporary structure, valid until the next time a component update will be fetched. Assuming these constraints this folder may be used to store temporary component data (e.g. as cache content).

      A call to this method always returns a folder. Depending on the component type however, this folder may be empty, contain a single z.properties file or more.

      If localOnly is set to true, only this repository is looked up. Otherwise all repositories in the chain with lower priority are considered too.

      Specified by:
      retrieve in interface IComponentsRepository
      Returns:
      the component's folder resource folder or null, if the component does not exist.
      Throws:
      IOException
    • getModules

      public Set<String> getModules(boolean localOnly) throws IOException
      Description copied from interface: IComponentsRepository
      Retrieve the set of modules provided by this repository. If localOnly is true, the methods returns only those modules that are provided by the very repository.
      Specified by:
      getModules in interface IComponentsRepository
      Throws:
      IOException
    • getRevision

      protected long getRevision()
      Overall revision of the repository - if available
    • getURL

      protected String getURL()
      Some URL style information on the external data source the repository implementation relies on
    • isRelaxedMode

      protected boolean isRelaxedMode()
      Operational mode checks
    • checkOfflineMode

      protected void checkOfflineMode()
      Check offline mode and if so throw an exception. This is to used in repository implementations in conjunction with the relaxed mode. That is: We consider the offline mode as one particular failure mode when trying to access remote resources. Only when in relaxed mode and sensible data is present, continuing in offline mode is advisable - as for any other remote access failure.
    • scan

      public abstract DB scan(DB current)
      Provide an updated DB. This DB will be used to compute invalidations on synchronization and it will be used to serve component meta-data. If the repository implementation needs to attach additional meta-data to the DB, it should overwrite the DB class to do so, as the result of a scan potentially will be discarded.
    • download

      public abstract void download(FSCRC component, File folder)
      Download resources of a single component into the given folder
    • getDB

      public final DB getDB() throws IOException
      returns the current DB
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • test_setInited

      public void test_setInited(boolean inited)
    • test_setContext

      public void test_setContext(IComponentsRepositoryContext context)
    • test_setDb

      public void test_setDb(DB db)