public interface CacheManager
Caching
new
of a concrete implementation, if
supported by an implementationCaching.getCacheManager()
. This is a
useful idiom if you only want to use one CacheManager.
Named CacheManagers can be obtained using Caching.getCacheManager(name)
.Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the CacheManager.
|
<K,V> Cache<K,V> |
configureCache(String cacheName,
Configuration<K,V> configuration)
Ensures that a
Cache conforming to the specified Configuration
is being managed by the CacheManager . |
void |
enableManagement(String cacheName,
boolean enabled)
Controls whether management is enabled.
|
void |
enableStatistics(String cacheName,
boolean enabled)
Enables or disables statistics gathering for a cache at runtime.
|
<K,V> Cache<K,V> |
getCache(String cacheName)
Looks up a
Cache given it's name. |
Iterable<Cache<?,?>> |
getCaches()
Returns an Iterable over the caches managed by this CacheManager.
|
CachingProvider |
getCachingProvider()
Obtain the CachingProvider that created and is responsible for
this CacheManager.
|
Properties |
getProperties()
Get the Properties that were used to create this CacheManager.
|
Status |
getStatus()
Returns the status of this CacheManager.
|
URI |
getURI()
Get the URI of this CacheManager.
|
UserTransaction |
getUserTransaction()
This method will return a UserTransaction.
|
boolean |
isSupported(OptionalFeature optionalFeature)
Indicates whether a optional feature is supported by this CacheManager.
|
boolean |
removeCache(String cacheName)
Remove a cache from the CacheManager.
|
<T> T |
unwrap(Class<T> cls)
Return an object of the specified type to allow access to the provider-specific API.
|
CachingProvider getCachingProvider()
null
if the CacheManager
was created without using a CachingProviderURI getURI()
Properties getProperties()
Status getStatus()
Status
<K,V> Cache<K,V> configureCache(String cacheName, Configuration<K,V> configuration)
Cache
conforming to the specified Configuration
is being managed by the CacheManager
. If such a Cache
is unknown
to the CacheManager
, one is created and configured according to the provided
configuration, after which it becomes managed by the said CacheManager
.
If such a Cache
already exists, it is simply returned.
Importantly Configuration
s provided to this method are always
validated with in the context of the CacheManager
implementation.
For example: Attempting use a Configuration
requiring transactional
support with an implementation that does not support transactions will result
in an UnsupportedOperationException
.
Note 1: Implementors of this method are required to make a copy of the provided
Configuration
so that it may be further used to configure and
ensure other Cache
s without causing side-effects.
Note 2: There's no requirement on the part of a developer to call this method
for each Cache
than an application may use. This is simply because
when instantiated a CacheManager
may be pre-configured with one or more
Cache
s, thus meaning there's no requirement to "configure" them
in an application. In such circumstances a developer may simply call
getCache(String)
to retrieve a pre-configured Cache
.cacheName
- the name of the cacheconfiguration
- the Configuration
Cache
IllegalStateException
- if the CacheManager is not in Status.STARTED
stateCacheException
- if there was an error adding the cache to the CacheManagerInvalidConfigurationException
- when the Configuration
is invalidUnsupportedOperationException
- when the Configuration
attempts
to use an unsupported featureNullPointerException
- if the cache configuration is null<K,V> Cache<K,V> getCache(String cacheName)
Cache
given it's name.cacheName
- the name of the cache to look forIllegalStateException
- if the CacheManager is not Status.STARTED
Iterable<Cache<?,?>> getCaches()
UnsupportedOperationException
- if an attempt it made to remove an elementboolean removeCache(String cacheName)
cacheName
- the cache nameIllegalStateException
- if the cache is not Status.STARTED
NullPointerException
- if cacheName is nullUserTransaction getUserTransaction()
UnsupportedOperationException
- if JTA is not supportedboolean isSupported(OptionalFeature optionalFeature)
optionalFeature
- the feature to check forvoid enableStatistics(String cacheName, boolean enabled)
javax.cache:type=CacheStatistics
Required Attributes:
cacheName
- the name of the cache to registerenabled
- true to enable statistics, false to disable.IllegalStateException
- if the cache is not Status.STARTED
NullPointerException
- if cacheName is nullvoid enableManagement(String cacheName, boolean enabled)
CacheMXBean
for each cache is registered
in the platform MBean server. THe platform MBeanServer is obtained using ManagementFactory
Managment information includes the name and configuration information for the cache.
Each cache's management object must be registered with an ObjectName that is unique and has the following type and attributes:
Type:
javax.cache:type=Cache
Required Attributes:
cacheName
- the name of the cache to registerenabled
- true to enable management, false to disable.void close()
CacheLifecycle.stop()
method will be invoked, in no guaranteed order.
If the stop throws an exception, the exception is ignored.
Calls to getStatus()
will block until shutdown completes.
On completion the CacheManager's status is changed to Status.STOPPED
,
and the manager's owned caches will be empty and getCaches()
will return an empty collection.
A given CacheManager instance cannot be restarted after it has been stopped. A new one must be created.IllegalStateException
- if an operation is performed on CacheManager while stopping or stopped.<T> T unwrap(Class<T> cls)
IllegalArgumentException
is thrown.cls
- the class of the object to be returned. This is normally either the
underlying implementation class or an interface that it implements.IllegalArgumentException
- if the provider doesn't support the specified class.Copyright © 2013. All Rights Reserved.