Package com.zfabrik.components.provider.util

## 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 java.lang.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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `class` | `AbstractExtComponentRepository.Repo` |
    `static interface` | `AbstractExtComponentRepository.RepoMBean` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static java.util.Map<java.lang.String,​AbstractExtComponentRepository<?,​?>>` | `ALL` |

    - ### Fields inherited from interface com.zfabrik.components.provider.IComponentsRepository

      `COMPONENT_REPO_IMPLEMENTATION, COMPONENT_REPO_MODE, COMPONENT_REPO_MODE_RELAXED, COMPONENT_REPO_MODE_STRICT`

    - ### Fields inherited from interface com.zfabrik.util.sync.ISynchronizer

      `PRIO, TYPE`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `AbstractExtComponentRepository​(java.lang.String name, java.lang.Class<DB> clz)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `<T> T` | `as​(java.lang.Class<T> clz)` | Simple type helper for `Resource` implementations.
    `protected void` | `checkOfflineMode()` | Check offline mode and if so throw an exception.
    `void` | `complete​(ISynchronization sync)` | synchronizers implement this method to re-establish any desired system state after all invalidations have been performed.
    `protected void` | `configure​(int prio)` | Is actually `configure(prio,null)`.
    `protected void` | `configure​(int prio, java.lang.Long evictionDelay)` | Is actually `configure(prio,evictionDelay,this.name)`.
    `protected void` | `configure​(int prio, java.lang.Long evictionDelay, java.lang.String repoKey)` | Finish configuration.
    `abstract void` | `download​(FSCRC component, java.io.File folder)` | Download resources of a single component into the given folder
    `java.util.Collection<java.lang.String>` | `findComponents​(X x, boolean localOnly)` | finds all components satisfying a query condition.
    `protected java.io.File` | `getCacheRoot()` |
    `IComponentDescriptor` | `getComponent​(java.lang.String cn, boolean localOnly)` | retrieves a component descriptor for a fully qualified component, e.g.
    `IComponentsRepositoryContext` | `getContext()` | gets the repository context
    `DB` | `getDB()` | returns the current DB
    `protected java.util.Properties` | `getExpectedConfiguration()` | provided expected repository configuration.
    `java.util.Set<java.lang.String>` | `getModules​(boolean localOnly)` | Retrieve the set of modules provided by this repository.
    `java.lang.String` | `getName()` |
    `protected long` | `getRevision()` | Overall revision of the repository - if available
    `long` | `getRevision​(java.lang.String cn, boolean localOnly)` | return the most current revision of the component as available by the provider.
    `protected java.lang.String` | `getURL()` | Some URL style information on the external data source the repository implementation relies on
    `static boolean` | `has​(java.lang.Class<?> clz)` | Simple type helper for `Resource` implementations.
    `protected boolean` | `isRelaxedMode()` | Operational mode checks
    `void` | `preInvalidation​(ISynchronization sync)` | pre invalidation collection of outdated components
    `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.
    `java.io.File` | `retrieve​(java.lang.String cn, boolean localOnly)` | Retrieve a component's resource folder.
    `abstract DB` | `scan​(DB current)` | Provide an updated DB.
    `protected void` | `setEvictionDelay​(long evictionDelay)` | Set eviction of old component copies
    `void` | `start()` | Start the repository and register it.
    `void` | `stop()` | Stop and unregister the repo.
    `void` | `test_setContext​(IComponentsRepositoryContext context)` |
    `void` | `test_setDb​(DB db)` |
    `void` | `test_setInited​(boolean inited)` |
    `java.lang.String` | `toString()` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface com.zfabrik.components.provider.IComponentsRepository

      `findComponents, getComponent, getModules, getRevision, retrieve`

- - ### Field Detail

    - #### ALL

          public static java.util.Map<java.lang.String,​AbstractExtComponentRepository<?,​?>> ALL

  - ### Constructor Detail

    - #### AbstractExtComponentRepository

          public AbstractExtComponentRepository​(java.lang.String name,
                                                java.lang.Class<DB> clz)

  - ### Method Detail

    - #### configure

          protected void configure​(int prio,
                                   java.lang.Long evictionDelay,
                                   java.lang.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 java.util.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,
                                   java.lang.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 java.lang.String getName()

    - #### getCacheRoot

          protected java.io.File getCacheRoot()

    - #### setEvictionDelay

          protected void setEvictionDelay​(long evictionDelay)

      Set eviction of old component copies

    - #### has

          public static boolean has​(java.lang.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​(java.lang.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​(java.lang.String cn,
                                  boolean localOnly)
                           throws java.io.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:
        `java.io.IOException`

    - #### findComponents

          public java.util.Collection<java.lang.String> findComponents​(X x,
                                                                       boolean localOnly)
                                                                throws java.io.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:
        `java.io.IOException`

    - #### getComponent

          public IComponentDescriptor getComponent​(java.lang.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 java.io.File retrieve​(java.lang.String cn,
                                       boolean localOnly)
                                throws java.io.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:
        `java.io.IOException`

    - #### getModules

          public java.util.Set<java.lang.String> getModules​(boolean localOnly)
                                                     throws java.io.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:
        `java.io.IOException`

    - #### getRevision

          protected long getRevision()

      Overall revision of the repository - if available

    - #### getURL

          protected java.lang.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,
                                        java.io.File folder)

      Download resources of a single component into the given folder

    - #### getDB

          public final DB getDB()
                         throws java.io.IOException

      returns the current DB
      Throws:
        `java.io.IOException`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.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)