public class EhcacheManager extends java.lang.Object implements PersistentCacheManager, InternalCacheManager
CacheManager
and PersistentCacheManager
Ehcache
users should not have to depend on this type but rely exclusively on the api types in package
org.ehcache
.
Modifier and Type | Field and Description |
---|---|
protected ServiceLocator |
serviceLocator |
Constructor and Description |
---|
EhcacheManager(Configuration config) |
EhcacheManager(Configuration config,
java.util.Collection<Service> services) |
EhcacheManager(Configuration config,
java.util.Collection<Service> services,
boolean useLoaderInAtomics) |
EhcacheManager(Configuration config,
java.util.function.UnaryOperator<ServiceLocator.DependencySet> customization,
boolean useLoaderInAtomics) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Transitions this
CacheManager to UNINITIALIZED . |
protected void |
closeEhcache(java.lang.String alias,
InternalCache<?,?> ehcache)
Perform cache closure actions specific to a cache manager implementation.
|
<K,V> Cache<K,V> |
createCache(java.lang.String alias,
Builder<? extends CacheConfiguration<K,V>> configBuilder)
Creates a
Cache in this CacheManager according to the specified CacheConfiguration provided
through a Builder . |
<K,V> Cache<K,V> |
createCache(java.lang.String alias,
CacheConfiguration<K,V> config)
|
void |
deregisterListener(CacheManagerListener listener)
De-registers a
CacheManagerListener . |
void |
destroy()
Destroys all persistent data associated with this
PersistentCacheManager . |
void |
destroyCache(java.lang.String alias)
Destroys all data persistent data associated with the aliased
Cache instance managed
by this CacheManager . |
<K,V> Cache<K,V> |
getCache(java.lang.String alias,
java.lang.Class<K> keyType,
java.lang.Class<V> valueType)
Retrieves the
Cache associated with the given alias, if one is known. |
Configuration |
getRuntimeConfiguration()
Returns the current
Configuration used by this CacheManager . |
Status |
getStatus()
Returns the current
Status of this CacheManager . |
protected <K,V> Store<K,V> |
getStore(java.lang.String alias,
CacheConfiguration<K,V> config,
java.lang.Class<K> keyType,
java.lang.Class<V> valueType,
java.util.Collection<ServiceConfiguration<?,?>> serviceConfigs,
java.util.List<LifeCycled> lifeCycledList,
CacheLoaderWriter<? super K,V> loaderWriter)
Instantiates a
Store used for the cache data. |
void |
init()
Transitions this
CacheManager to AVAILABLE . |
void |
registerListener(CacheManagerListener listener)
Registers a
CacheManagerListener . |
void |
removeCache(java.lang.String alias)
Removes the
Cache associated with the alias provided, if one is known. |
protected final ServiceLocator serviceLocator
public EhcacheManager(Configuration config)
public EhcacheManager(Configuration config, java.util.Collection<Service> services)
public EhcacheManager(Configuration config, java.util.Collection<Service> services, boolean useLoaderInAtomics)
public EhcacheManager(Configuration config, java.util.function.UnaryOperator<ServiceLocator.DependencySet> customization, boolean useLoaderInAtomics)
public <K,V> Cache<K,V> getCache(java.lang.String alias, java.lang.Class<K> keyType, java.lang.Class<V> valueType)
CacheManager
Cache
associated with the given alias, if one is known.getCache
in interface CacheManager
K
- the key type for the cacheV
- the value type for the cachealias
- the alias under which to look the Cache
upkeyType
- the Cache
key classvalueType
- the Cache
value classCache
associated with the given alias, null
if no such cache existspublic void removeCache(java.lang.String alias)
CacheManager
Cache
associated with the alias provided, if one is known.
When the cache is removed, it will release all resources it used.
removeCache
in interface CacheManager
alias
- the alias for which to remove the Cache
protected void closeEhcache(java.lang.String alias, InternalCache<?,?> ehcache)
InternalCache
instance is closed.alias
- the cache aliasehcache
- the InternalCache
instance for the cache to closepublic <K,V> Cache<K,V> createCache(java.lang.String alias, Builder<? extends CacheConfiguration<K,V>> configBuilder)
CacheManager
Cache
in this CacheManager
according to the specified CacheConfiguration
provided
through a Builder
.
The returned Cache
will be in status AVAILABLE
.
createCache
in interface CacheManager
K
- the key type for the cacheV
- the value type for the cachealias
- the alias under which the cache will be createdconfigBuilder
- the builder for the configuration of the cache to createCache
public <K,V> Cache<K,V> createCache(java.lang.String alias, CacheConfiguration<K,V> config) throws java.lang.IllegalArgumentException
CacheManager
Cache
in this CacheManager
according to the specified CacheConfiguration
.
The returned Cache
will be in status AVAILABLE
.
createCache
in interface CacheManager
K
- the key type for the cacheV
- the value type for the cachealias
- the alias under which the cache will be createdconfig
- the configuration of the cache to createCache
java.lang.IllegalArgumentException
- if there is already a cache registered with the given aliasprotected <K,V> Store<K,V> getStore(java.lang.String alias, CacheConfiguration<K,V> config, java.lang.Class<K> keyType, java.lang.Class<V> valueType, java.util.Collection<ServiceConfiguration<?,?>> serviceConfigs, java.util.List<LifeCycled> lifeCycledList, CacheLoaderWriter<? super K,V> loaderWriter)
Store
used for the cache data.K
- the cache key typeV
- the cache value typealias
- the alias assigned to the cacheconfig
- the configuration used for the cachekeyType
- the cache key typevalueType
- the cache value typeserviceConfigs
- the List
of ServiceConfiguration
instances available to the cache;
this list may be augmented by the implementation of this methodlifeCycledList
- the List
of LifeCycled
instances used to manage components of the
cache; this list may be augmented by the implementation of this methodloaderWriter
- the CacheLoaderWriter
to be used by the Cache
Store
instance used to create the cachepublic void registerListener(CacheManagerListener listener)
InternalCacheManager
CacheManagerListener
.registerListener
in interface InternalCacheManager
listener
- the listener to registerpublic void deregisterListener(CacheManagerListener listener)
InternalCacheManager
CacheManagerListener
.deregisterListener
in interface InternalCacheManager
listener
- the listener to de-registerpublic void init()
CacheManager
to AVAILABLE
.
This will start all Service
s managed by this CacheManager
, as well
as initializing all Cache
s registered with it.
If an error occurs before the CacheManager
is AVAILABLE
, it will revert to
UNINITIALIZED
attempting to close all services it had already started.
init
in interface CacheManager
public Status getStatus()
CacheManager
Status
of this CacheManager
.getStatus
in interface CacheManager
Status
public void close()
CacheManager
CacheManager
to UNINITIALIZED
.
This will close all Cache
s known to this CacheManager
and stop all
Service
s managed by this CacheManager
.
Failure to close any Cache
or to stop any Service
will not prevent others from being closed or
stopped.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface CacheManager
public Configuration getRuntimeConfiguration()
CacheManager
Configuration
used by this CacheManager
.getRuntimeConfiguration
in interface CacheManager
CacheManager
public void destroyCache(java.lang.String alias) throws CachePersistenceException
PersistentCacheManager
Cache
instance managed
by this CacheManager
.
This requires the CacheManager
to be either in AVAILABLE
or
MAINTENANCE
mode.
CacheManager
is AVAILABLE
, the operation is executed without lifecycle interactions.CacheManager
is not AVAILABLE
then it attempts to go into MAINTENANCE
.
Upon success, the destroyCache
operation is performed and then MAINTENANCE
mode is exited.
On failure, an exception will be thrown and no destroy will have happened.destroyCache
in interface PersistentCacheManager
alias
- the Cache
's alias to destroy all persistent data fromCachePersistenceException
- when something goes wrong destroying the persistent datapublic void destroy() throws CachePersistenceException
PersistentCacheManager
PersistentCacheManager
.
This is achieved by putting the CacheManager
in MAINTENANCE
mode,
executing the destroy and then exiting the MAINTENANCE
mode.
destroy
in interface PersistentCacheManager
CachePersistenceException
- when something goes wrong destroying the persistent data