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#scan(DB)to compute an update of the available components, their properties and revisions#download(FSCRDC, File)to download a component's resources, if any, to a local file system folder
- Author:
- hb
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAbstractExtComponentRepository.Repostatic interfaceAbstractExtComponentRepository.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> Tas(java.lang.Class<T> clz)Simple type helper forResourceimplementations.protected voidcheckOfflineMode()Check offline mode and if so throw an exception.voidcomplete(ISynchronization sync)synchronizers implement this method to re-establish any desired system state after all invalidations have been performed.protected voidconfigure(int prio)Is actuallyconfigure(prio,null).protected voidconfigure(int prio, java.lang.Long evictionDelay)Is actuallyconfigure(prio,evictionDelay,this.name).protected voidconfigure(int prio, java.lang.Long evictionDelay, java.lang.String repoKey)Finish configuration.abstract voiddownload(FSCRC component, java.io.File folder)Download resources of a single component into the given folderjava.util.Collection<java.lang.String>findComponents(X x, boolean localOnly)finds all components satisfying a query condition.protected java.io.FilegetCacheRoot()IComponentDescriptorgetComponent(java.lang.String cn, boolean localOnly)retrieves a component descriptor for a fully qualified component, e.g.IComponentsRepositoryContextgetContext()gets the repository contextDBgetDB()returns the current DBprotected java.util.PropertiesgetExpectedConfiguration()provided expected repository configuration.java.util.Set<java.lang.String>getModules(boolean localOnly)Retrieve the set of modules provided by this repository.java.lang.StringgetName()protected longgetRevision()Overall revision of the repository - if availablelonggetRevision(java.lang.String cn, boolean localOnly)return the most current revision of the component as available by the provider.protected java.lang.StringgetURL()Some URL style information on the external data source the repository implementation relies onstatic booleanhas(java.lang.Class<?> clz)Simple type helper forResourceimplementations.protected booleanisRelaxedMode()Operational mode checksvoidpreInvalidation(ISynchronization sync)pre invalidation collection of outdated componentsprotected voidpreInvalidation(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.Fileretrieve(java.lang.String cn, boolean localOnly)Retrieve a component's resource folder.abstract DBscan(DB current)Provide an updated DB.protected voidsetEvictionDelay(long evictionDelay)Set eviction of old component copiesvoidstart()Start the repository and register it.voidstop()Stop and unregister the repo.voidtest_setContext(IComponentsRepositoryContext context)voidtest_setDb(DB db)voidtest_setInited(boolean inited)java.lang.StringtoString()-
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. SeeIComponentsRepository.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 theFSComponentRepositoryHelperto 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 actuallyconfigure(prio,evictionDelay,this.name).- Parameters:
prio- Repository priority. SeeIComponentsRepository.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 actuallyconfigure(prio,null).- Parameters:
prio- Repository priority. SeeIComponentsRepository.
-
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 forResourceimplementations. 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 forResourceimplementations. 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:
preInvalidationin interfaceISynchronizer
-
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:ISynchronizersynchronizers 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:
completein interfaceISynchronizer
-
getRevision
public long getRevision(java.lang.String cn, boolean localOnly) throws java.io.IOExceptionDescription copied from interface:IComponentsRepositoryreturn 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:
getRevisionin interfaceIComponentsRepository- 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:IComponentsRepositoryfinds 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:
findComponentsin interfaceIComponentsRepository- Throws:
java.io.IOException
-
getComponent
public IComponentDescriptor getComponent(java.lang.String cn, boolean localOnly)
Description copied from interface:IComponentsRepositoryretrieves a component descriptor for a fully qualified component, e.g.<module>/javafor 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:
getComponentin interfaceIComponentsRepository
-
retrieve
public java.io.File retrieve(java.lang.String cn, boolean localOnly) throws java.io.IOExceptionDescription copied from interface:IComponentsRepositoryRetrieve 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:
retrievein interfaceIComponentsRepository- 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.IOExceptionDescription copied from interface:IComponentsRepositoryRetrieve the set of modules provided by this repository. IflocalOnlyis true, the methods returns only those modules that are provided by the very repository.- Specified by:
getModulesin interfaceIComponentsRepository- 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:
toStringin classjava.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)
-
-