Class AbstractCachingRuntimeRepository
- java.lang.Object
-
- org.faktorips.runtime.internal.AbstractRuntimeRepository
-
- org.faktorips.runtime.internal.AbstractCachingRuntimeRepository
-
- All Implemented Interfaces:
IRuntimeRepository
- Direct Known Subclasses:
AbstractTocBasedRuntimeRepository
public abstract class AbstractCachingRuntimeRepository extends AbstractRuntimeRepository
This abstract runtime repository handles the caching for already loaded instances. The caching have to be thread safe for every cache instance that we do not load an object twice. That means, the regular way we load an object is to have a look in the cache if it is already there if not we call the getNotCached... method.To be performant and thread safe we use the double checking ideom as it is discribed by doug lea. Since we use Java 5 there is a threadsafe way to do so:
First of all we have a not synchronized look in the cache. As we assume that the cache itself is implemented with aConcurrentHashMapthis lookup would see the real state of the map. If there is no object yet we have to enter a synchronized block. This block is synchronized for every cache instance so we could handle calls for different objects at same time. In this synchonized block it is important to check again if there is an cached object now because another thread may created one meantime (double-check). Again this only works forConcurrentHashMap. If there still is no object cached we create a new one. As long we are in the synchronized block, every other thread is blocked. After the new object is created we put it in the cache and theConcurrentHashMapensures that it is stored completely initialized before another thread would get access.There is still potentially more performance by synchronizing for different keys instead of blocking for every cache instance. This would be more complicated and should be well-considered.
- Author:
- dirmeier
-
-
Constructor Summary
Constructors Constructor Description AbstractCachingRuntimeRepository(java.lang.String name, ICacheFactory cacheFactory, java.lang.ClassLoader cl)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.List<javax.xml.bind.annotation.adapters.XmlAdapter<?,?>>getAllInternalEnumXmlAdapters(IRuntimeRepository repository)Returns all enumeration XmlAdapters available in this repository that generated by Faktor-IPS.protected <T> TgetCustomRuntimeObjectInternal(java.lang.Class<T> type, java.lang.String ipsObjectQualifiedName)Same asAbstractRuntimeRepository.getCustomRuntimeObject(Class, String)but searches only in this repository and not the ones this repository depends on.protected <T> java.util.List<T>getEnumValuesInternal(java.lang.Class<T> clazz)Returns the list of enumeration values of the enumeration type that is identified by its class which is provided to it.protected abstract <T> TgetNotCachedCustomObject(java.lang.Class<T> type, java.lang.String ipsObjectQualifiedName)protected abstract <T> java.util.List<T>getNotCachedEnumValues(java.lang.Class<T> clazz)protected abstract java.util.List<javax.xml.bind.annotation.adapters.XmlAdapter<?,?>>getNotCachedEnumXmlAdapter(IRuntimeRepository repository)protected abstract IProductComponentgetNotCachedProductComponent(java.lang.String id)protected abstract IProductComponentGenerationgetNotCachedProductComponentGeneration(GenerationId generationId)protected abstract ITable<?>getNotCachedTable(java.lang.String qualifiedTableName)protected IProductComponentGenerationgetProductComponentGenerationInternal(java.lang.String id, DateTime validFrom)protected IProductComponentgetProductComponentInternal(java.lang.String id)Same as getProductComponent(String id) but searches only in this repository and not the ones this repository depends on.protected ITable<?>getTableInternal(java.lang.String qualifiedTableName)Same asAbstractRuntimeRepository.getTable(String)) but searches only in this repository and not the ones this repository depends on.protected voidinitCaches(java.lang.ClassLoader cl)-
Methods inherited from class org.faktorips.runtime.internal.AbstractRuntimeRepository
addDirectlyReferencedRepository, addEnumValueLookupService, getAllEnumClasses, getAllEnumClasses, getAllIpsTestCases, getAllIpsTestCases, getAllModelTypeImplementationClasses, getAllModelTypeImplementationClasses, getAllProductComponentIds, getAllProductComponentIds, getAllProductComponents, getAllProductComponents, getAllProductComponents, getAllProductComponents, getAllProductComponents, getAllProductComponentsInternal, getAllReferencedRepositories, getAllTables, getAllTables, getClassLoader, getCustomRuntimeObject, getDirectlyReferencedRepositories, getEnumValue, getEnumValue, getEnumValueLookupService, getEnumValues, getEnumValuesDefinedInType, getExistingEnumValue, getExistingProductComponent, getExistingProductComponentGeneration, getFormulaEvaluatorFactory, getIpsTest, getIpsTest, getIpsTestCase, getIpsTestCase, getIpsTestCaseInternal, getIpsTestCasesStartingWith, getIpsTestCasesStartingWith, getIpsTestSuite, getIpsTestSuite, getLatestProductComponentGeneration, getLatestProductComponentGenerationInternal, getModelType, getModelType, getModelType, getName, getNextProductComponentGeneration, getNextProductComponentGenerationInternal, getNumberOfProductComponentGenerations, getNumberOfProductComponentGenerationsInternal, getPreviousProductComponentGeneration, getPreviousProductComponentGenerationInternal, getProductComponent, getProductComponent, getProductComponentGeneration, getProductComponentGenerationInternal, getProductComponentGenerations, getProductComponentGenerations, getProductComponentInternal, getRuntimeRepositoryLookup, getTable, getTable, getTableInternal, newJAXBContext, newJAXBContext, removeEnumValueLookupService, setFormulaEvaluatorFactory, setRuntimeRepositoryLookup, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.faktorips.runtime.IRuntimeRepository
isModifiable
-
-
-
-
Constructor Detail
-
AbstractCachingRuntimeRepository
public AbstractCachingRuntimeRepository(java.lang.String name, ICacheFactory cacheFactory, java.lang.ClassLoader cl)
-
-
Method Detail
-
initCaches
protected void initCaches(java.lang.ClassLoader cl)
-
getProductComponentInternal
protected IProductComponent getProductComponentInternal(java.lang.String id)
Description copied from class:AbstractRuntimeRepositorySame as getProductComponent(String id) but searches only in this repository and not the ones this repository depends on.- Specified by:
getProductComponentInternalin classAbstractRuntimeRepository
-
getNotCachedProductComponent
protected abstract IProductComponent getNotCachedProductComponent(java.lang.String id)
-
getProductComponentGenerationInternal
protected IProductComponentGeneration getProductComponentGenerationInternal(java.lang.String id, DateTime validFrom)
-
getNotCachedProductComponentGeneration
protected abstract IProductComponentGeneration getNotCachedProductComponentGeneration(GenerationId generationId)
-
getEnumValuesInternal
protected <T> java.util.List<T> getEnumValuesInternal(java.lang.Class<T> clazz)
Description copied from class:AbstractRuntimeRepositoryReturns the list of enumeration values of the enumeration type that is identified by its class which is provided to it.- Specified by:
getEnumValuesInternalin classAbstractRuntimeRepository
-
getNotCachedEnumValues
protected abstract <T> java.util.List<T> getNotCachedEnumValues(java.lang.Class<T> clazz)
-
getTableInternal
protected ITable<?> getTableInternal(java.lang.String qualifiedTableName)
Description copied from class:AbstractRuntimeRepositorySame asAbstractRuntimeRepository.getTable(String)) but searches only in this repository and not the ones this repository depends on.- Specified by:
getTableInternalin classAbstractRuntimeRepository
-
getNotCachedTable
protected abstract ITable<?> getNotCachedTable(java.lang.String qualifiedTableName)
-
getAllInternalEnumXmlAdapters
protected java.util.List<javax.xml.bind.annotation.adapters.XmlAdapter<?,?>> getAllInternalEnumXmlAdapters(IRuntimeRepository repository)
Description copied from class:AbstractRuntimeRepositoryReturns all enumeration XmlAdapters available in this repository that generated by Faktor-IPS.- Specified by:
getAllInternalEnumXmlAdaptersin classAbstractRuntimeRepository- Parameters:
repository- the runtime repository that needs to be used by the XmlAdapters that are returned by this method
-
getNotCachedEnumXmlAdapter
protected abstract java.util.List<javax.xml.bind.annotation.adapters.XmlAdapter<?,?>> getNotCachedEnumXmlAdapter(IRuntimeRepository repository)
-
getCustomRuntimeObjectInternal
protected <T> T getCustomRuntimeObjectInternal(java.lang.Class<T> type, java.lang.String ipsObjectQualifiedName)Description copied from class:AbstractRuntimeRepositorySame asAbstractRuntimeRepository.getCustomRuntimeObject(Class, String)but searches only in this repository and not the ones this repository depends on.- Specified by:
getCustomRuntimeObjectInternalin classAbstractRuntimeRepository
-
getNotCachedCustomObject
protected abstract <T> T getNotCachedCustomObject(java.lang.Class<T> type, java.lang.String ipsObjectQualifiedName)
-
-