Top Description Fields Constructors Methods
net.sf.ehcache

public Class CacheManager

extends Object
Class Inheritance
Imports
net.sf.ehcache.cluster.CacheCluster, .ClusterScheme, .ClusterSchemeNotAvailableException, .NoopCacheCluster, net.sf.ehcache.concurrent.ConcurrencyUtil, net.sf.ehcache.config.CacheConfiguration, .Configuration, .ConfigurationFactory, .ConfigurationHelper, .DiskStoreConfiguration, .InvalidConfigurationException, .ManagementRESTServiceConfiguration, .SizeOfPolicyConfiguration, net.sf.ehcache.config.generator.ConfigurationSource, .ConfigurationUtil, net.sf.ehcache.distribution.CacheManagerPeerListener, .CacheManagerPeerProvider, net.sf.ehcache.event.CacheEventListener, .CacheManagerEventListener, .CacheManagerEventListenerRegistry, net.sf.ehcache.management.event.DelegatingManagementEventSink, .ManagementEventSink, net.sf.ehcache.management.ManagementServerLoader, net.sf.ehcache.management.provider.MBeanRegistrationProvider, .MBeanRegistrationProviderException, .MBeanRegistrationProviderFactory, .MBeanRegistrationProviderFactoryImpl, net.sf.ehcache.pool.Pool, .PoolEvictor, .SizeOfEngine, .SizeOfEngineLoader, net.sf.ehcache.pool.impl.BalancedAccessEvictor, .BoundedPool, net.sf.ehcache.store.Store, net.sf.ehcache.terracotta.ClusteredInstanceFactory, .TerracottaClient, net.sf.ehcache.transaction.DelegatingTransactionIDFactory, .ReadCommittedSoftLockFactory, .SoftLockFactory, .SoftLockManager, .SoftLockManagerImpl, .TransactionIDFactory, net.sf.ehcache.transaction.manager.TransactionManagerLookup, net.sf.ehcache.transaction.xa.processor.XARequestProcessor, net.sf.ehcache.util.FailSafeTimer, .PropertyUtil, net.sf.ehcache.writer.writebehind.WriteBehind, org.slf4j.Logger, .LoggerFactory, org.terracotta.statistics.StatisticsManager, java.io.File, .InputStream, .Serializable, java.lang.reflect.InvocationTargetException, java.net.URL, java.util.Collections, .HashMap, .IdentityHashMap, .Iterator, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, .CopyOnWriteArrayList, .Executors, .ScheduledExecutorService, .ThreadFactory, .TimeoutException, java.util.concurrent.atomic.AtomicInteger

A container for Ehcaches that maintain all aspects of their lifecycle.

CacheManager may be either be a singleton if created with factory methods, or multiple instances may exist, in which case resources required by each must be unique.

A CacheManager holds references to Caches and Ehcaches and manages their creation and lifecycle.

Author
Greg Luck
Version
$Id: CacheManager.java 10789 2018-04-26 02:08:13Z adahanne $

Field Summary

Modifier and TypeField and Description
public static final List<CacheManager>
ALL_CACHE_MANAGERS

Keeps track of all known CacheManagers.

private static final Map<String, CacheManager>
private static final IdentityHashMap<CacheManager, String>
protected final CacheManagerEventListenerRegistry
cacheManagerEventListenerRegistry

The listener registry

protected final Map<String, CacheManagerPeerListener>
cacheManagerPeerListeners

The map of listeners

protected final Map<String, CacheManagerPeerProvider>
cacheManagerPeerProviders

The map of providers

private FailSafeTimer
public static final String
DEFAULT_NAME

Default name if not specified in the configuration/

private Ehcache
defaultCache

Default cache cache.

private static final long
DELAY_UPDATE_CHECK

delay period before doing update check

private DiskStorePathManager
diskStorePathManager

The path for the directory in which disk caches are created.

private final ConcurrentMap<String, Ehcache>
ehcaches

Ehcaches managed by this manager.

public static final String
ENABLE_SHUTDOWN_HOOK_PROPERTY

System property to enable creation of a shutdown hook for CacheManager.

private static final long
EVERY_WEEK

Update check interval - one week in milliseconds

private volatile FeaturesManager
private static final Map<String, CacheManager>
private final Map<String, Ehcache>
pack-priv static final String
private static final long
private volatile Thread
private static final Logger
private volatile ManagementEventSink
private static final MBeanRegistrationProviderFactory
MBEAN_REGISTRATION_PROVIDER_FACTORY

The factory to use for creating MBeanRegistrationProvider's

private MBeanRegistrationProvider
private static final String
public static final double
ON_HEAP_THRESHOLD

Threshold, in percent of the available heap, above which the CacheManager will warn if the configured memory

private volatile Pool
private volatile Pool
private static final int
POOL_SHUTDOWN_TIMEOUT_SECS

Default timeout in seconds to wait for stats thread pool to shutdown

private String
private volatile Configuration.RuntimeCfg
protected Thread
shutdownHook

The shutdown hook thread for CacheManager.

private static volatile CacheManager
singleton

The Singleton Instance.

private final ConcurrentMap<String, SoftLockManager>
private ScheduledExecutorService
statisticsExecutor

Statistics thread pool.

protected volatile Status
status

Status of the Cache Manager

private volatile TerracottaClient
private volatile TransactionController
private volatile DelegatingTransactionIDFactory
private volatile TransactionManagerLookup

Constructor Summary

AccessConstructor and Description
public
CacheManager(Configuration configuration)

An constructor for CacheManager, which takes a configuration object, rather than one created by parsing an ehcache.xml file.

public
CacheManager(String
an xml configuration file available through a file name. The configuration File is created using new File(configurationFileName)
configurationFileName
)

An ordinary constructor for CacheManager.

public
CacheManager(URL
an xml configuration available through a URL.
configurationURL
)

An ordinary constructor for CacheManager.

public
CacheManager(InputStream
an xml configuration file available through an inputstream
configurationInputStream
)

An ordinary constructor for CacheManager.

public
CacheManager()

Constructor.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addCache(String
the name for the cache
cacheName
)

Adds a Ehcache based on the defaultCache with the given name.

public void
addCache(Cache cache)

Adds a Cache to the CacheManager.

public synchronized void
addCache(Ehcache cache)

Adds an Ehcache to the CacheManager.

public synchronized Ehcache

Returns:

the instance registered with the CacheManager, the cache instance passed in if it was added; or null if Ehcache is null
addCacheIfAbsent
(final Ehcache
The Ehcache to be added
cache
)

Only adds the cache to the CacheManager should not one with the same name already be present

public synchronized Ehcache

Returns:

the Ehcache instance created and registered; null if cacheName was null or of length 0
addCacheIfAbsent
(final String
the name of the Cache to be created
cacheName
)

Only creates and adds the cache to the CacheManager should not one with the same name already be present

private Ehcache
addCacheNoCheck(final Ehcache cache, final boolean strict)

private void
public synchronized void
addDecoratedCache(Ehcache decoratedCache)

Adds a decorated Ehcache to the CacheManager.

public synchronized void
addDecoratedCacheIfAbsent(Ehcache decoratedCache)

Same as addDecoratedCache(Ehcache) but does not throw exception if another cache with same name already exists.

private void
addOrReplaceDecoratedCache(final Ehcache underlyingCache, final Ehcache decoratedCache)

private void
addShutdownHookIfRequired()

Some caches might be persistent, so we want to add a shutdown hook if that is the case, so that the data and index can be written to disk.

private void
private void
private void
public boolean

Returns:

true if it exists
cacheExists
(String
the cache name to check for
cacheName
)

Checks whether a cache of type ehcache exists.

protected void
checkStatus()

Checks the state of the CacheManager for legal operation

public void
clearAll()

Clears the contents of all caches in the CacheManager, but without removing any caches.

public void
clearAllStartingWith(String
The prefix the cache name should start with
prefix
)

Clears the contents of all caches in the CacheManager with a name starting with the prefix, but without removing them.

private Ehcache
cloneDefaultCache(final String cacheName)

private void
configure(ConfigurationHelper configurationHelper)

public static CacheManager

Returns:

the singleton CacheManager
create
()

A factory method to create a singleton CacheManager with default config, or return it if it exists.

public static CacheManager
create(String
an xml file compliant with the ehcache.xsd schema

The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

configurationFileName
)

A factory method to create a singleton CacheManager with a specified configuration.

public static CacheManager
create(URL
an URL to an xml file compliant with the ehcache.xsd schema

The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

configurationFileURL
)

A factory method to create a singleton CacheManager from an URL.

public static CacheManager
create(InputStream
InputStream of xml compliant with the ehcache.xsd schema

The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

inputStream
)

A factory method to create a singleton CacheManager from a java.io.InputStream.

public static CacheManager
create(Configuration config)

A factory method to create a singleton CacheManager from a net.sf.ehcache.config.Configuration.

private List<Ehcache>
pack-priv SizeOfEngine

Returns:

a SizeOfEngine instance
createSizeOfEngine
(final Cache
The cache to be sized by the engine
cache
)

Creates a SizeOfEngine for a cache.

pack-priv SoftLockManager

Returns:

a SoftLockManager
createSoftLockManager
(Ehcache
the cache to create the soft lock manager for
cache
)

Create a soft lock manager for a specific cache

public CacheEventListener

Returns:

a new cache event replicator
createTerracottaEventReplicator
(Ehcache
The cache for which the clustered event replicator should be created
cache
)

Create/access the appropriate clustered cache event replicator for the given cache

public Store

Returns:

a new (or existing) clustered store
createTerracottaStore
(Ehcache
The cache for which the Store should be created
cache
)

Create/access the appropriate terracotta clustered store for the given cache

public WriteBehind

Returns:

a new (or existing) write behind queue
createTerracottaWriteBehind
(Ehcache
The cache for which the write behind queue should be created
cache
)

Create/access the appropriate clustered write behind queue for the given cache

private void
private void
doInit(Configuration configuration)

public String

Returns:

Returns the active configuration text for this CacheManager
getActiveConfigurationText
()

Returns the active configuration text for this CacheManager

public String

Returns:

Returns the active configuration text for the input cacheName
getActiveConfigurationText
(String cacheName)

Returns the active configuration text for the input cacheName

public Cache

Returns:

a Cache, if an object of that type exists by that name, else null
getCache
(String name)

Returns a concrete implementation of Cache, it it is available in the CacheManager.

public static CacheManager

Returns:

if a cacheManager exists with given name returns the CacheManager, otherwise returns null. If name is null, returns the default unnamed cacheManager if it has been created already otherwise returns null
getCacheManager
(String
the cacheManager name.
name
)

Checks if a cacheManager already exists for a given name and gets it.

public CacheManagerEventListener

Returns:

null if none
getCacheManagerEventListener
()

Returns the composite listener.

public CacheManagerEventListenerRegistry
getCacheManagerEventListenerRegistry()

Gets the CacheManagerEventListenerRegistry.

public CacheManagerPeerProvider

Returns:

the provider, or null if one does not exist
getCacheManagerPeerProvider
(String
the replication scheme to use. Schemes shipped with ehcache are RMI, JGROUPS, JMS
scheme
)

Gets the CacheManagerPeerProvider, matching the given scheme For distributed caches, the peer provider finds other cache managers and their caches in the same cluster

public Map<String, CacheManagerPeerProvider>

Returns:

Read-only map of the registered CacheManagerPeerProviders keyed by scheme.
getCacheManagerPeerProviders
()

public String[]

Returns:

an array of Strings
getCacheNames
()

Returns a list of the current cache names.

public CacheManagerPeerListener

Returns:

the listener, or null if one does not exist
getCachePeerListener
(String
the replication scheme to use. Schemes shipped with ehcache are RMI, JGROUPS, JMS
scheme
)

When CacheManage is configured as part of a cluster, a CacheManagerPeerListener will be registered in it.

private ClassLoader
private static String
getClientUUID(ClusteredInstanceFactory clusteredInstanceFactory)

public CacheCluster

Returns:

Cluster API (never null, but possibly a simple single node implementation)
getCluster
(ClusterScheme
The clustering scheme to retrieve information about (such as "Terracotta")
scheme
)

Returns access to information about the cache cluster.

protected ClusteredInstanceFactory

Returns:

the clustered instance factory
getClusteredInstanceFactory
()

Return the clustered instance factory for a cache of this cache manager.

public String

Returns:

Returns unique cluster-wide id for this cache-manager when it contains clustered caches (e.g. Terracotta clustered caches). Otherwise returns blank string.
getClusterUUID
()

Returns unique cluster-wide id for this cache-manager.

public Configuration

Returns:

the configuration
getConfiguration
()

Get the CacheManager configuration

private ManagementRESTServiceConfiguration
public DiskStorePathManager

Returns:

the disk store path manager.
getDiskStorePathManager
()

Returns the disk store path manager.

public Ehcache

Returns:

a Cache, if an object of type Cache exists by that name, else null
getEhcache
(String name)

Gets an Ehcache

public FeaturesManager

Returns:

the features manager
getFeaturesManager
()

Get the features manager.

pack-priv static CacheManager

Returns:

the CacheManager if it exists.
getInitializingCacheManager
(String
name of the CacheManager; can be null
name
)

Get a currently initializing CacheManager.

public static CacheManager

Returns:

the singleton CacheManager
getInstance
()

A factory method to create a singleton CacheManager with default config, or return it if it exists.

public String

Returns:

the name, or the output of toString() if it is not set.
getName
()

Gets the name of the CacheManager.

public Pool

Returns:

this cache manager's shared on-disk pool
getOnDiskPool
()

Return this cache manager's shared on-disk pool

public Pool

Returns:

this cache manager's shared on-heap pool
getOnHeapPool
()

Return this cache manager's shared on-heap pool

private ManagementEventSink
public TransactionIDFactory

Returns:

a TransactionIDFactory
getOrCreateTransactionIDFactory
()

Get or create a TransactionIDFactory

public String

Returns:

Returns the original configuration text for this CacheManager
getOriginalConfigurationText
()

Returns the original configuration text for this CacheManager

public String

Returns:

Returns the original configuration text for the input cacheName
getOriginalConfigurationText
(String cacheName)

Returns the original configuration text for the input cacheName

private String
pack-priv ScheduledExecutorService

Returns:

this cache manager's statistics executor
getStatisticsExecutor
()

Return this cache manager's statistics executor

public Status

Returns:

The status value from the Status enum class
getStatus
()

Gets the status attribute of the Ehcache

public FailSafeTimer

Returns:

The FailSafeTimer associated with this cache manager
getTimer
()

Returns a FailSafeTimer associated with this CacheManager

public TransactionController

Returns:

the TransactionController
getTransactionController
()

Get the TransactionController

protected synchronized void
init(Configuration
the initial configuration
initialConfiguration
,
String
the name of the configuration file
configurationFileName
,
URL
the configuration URL
configurationURL
,
InputStream
the configuration input stream
configurationInputStream
)

initialises the CacheManager

pack-priv void
initializeEhcache(final Ehcache cache, final boolean registerCacheConfig)

Initialize the given Ehcache without adding it to the CacheManager.

private void
private void
internalAddDecoratedCache(final Ehcache decoratedCache, final boolean strict)

public boolean

Returns:

True if named
isNamed
()

Indicate whether the CacheManager is named or not.

public static CacheManager

Returns:

the singleton CacheManager
newInstance
()

A factory method to create a CacheManager with default config, or return it if it exists.

public static CacheManager
newInstance(String
an xml file compliant with the ehcache.xsd schema

The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

configurationFileName
)

A factory method to create a CacheManager with a specified configuration.

public static CacheManager
newInstance(URL
an URL to an xml file compliant with the ehcache.xsd schema

The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

configurationFileURL
)

A factory method to create a CacheManager from an URL.

public static CacheManager
newInstance(InputStream
InputStream of xml compliant with the ehcache.xsd schema

The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

inputStream
)

A factory method to create a CacheManager from a java.io.InputStream.

public static CacheManager
newInstance(Configuration config)

A factory method to create a CacheManager from a net.sf.ehcache.config.Configuration.

private static CacheManager

Returns:

a new cacheManager or an already existing one in the VM with same name
newInstance
(Configuration
the configuration object
configuration
,
String
Message printed when creating new cacheManager
msg
)

Returns a new cacheManager or returns already created one.

private synchronized Configuration

Returns:

the loaded configuration
parseConfiguration
(String
the file name to parse, or null
configurationFileName
,
URL
the URL to pass, or null
configurationURL
,
InputStream
, the InputStream to parse, or null
configurationInputStream
)

Loads configuration, either from the supplied ConfigurationHelper or by creating a new Configuration instance from the configuration file referred to by file, inputstream or URL.

private void
public void
removalAll()

Deprecated use removeAllCaches instead
Removes all caches using removeCache(String) for each cache.
public void
removeAllCaches()

Removes all caches using removeCache(String) for each cache.

public synchronized void
removeCache(String
the cache name
cacheName
)

Remove a cache from the CacheManager.

private void
removeShutdownHook()

Remove the shutdown hook to prevent leaving orphaned CacheManagers around.

public synchronized void
replaceCacheWithDecoratedCache(Ehcache ehcache, Ehcache
An implementation of Ehcache that wraps the original cache.
decoratedCache
)

Replaces in the map of Caches managed by this CacheManager an Ehcache with a decorated version of the same Ehcache.

private FeaturesManager
public void
sendManagementEvent(Serializable
the event (most probably an EventEntity)
event
,
String
the type of the event
type
)

Send a management event to the cluster

public void
setCacheManagerEventListener(CacheManagerEventListener
the listener to set.
cacheManagerEventListener
)

Same as getCacheManagerEventListenerRegistry().registerListener(cacheManagerEventListener); Left for backward compatiblity

public void
shutdown()

Shuts down the CacheManager.

public String

Returns:

either the name of this CacheManager, or if unset, Object.toString()
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait