|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.infinispan.manager.DefaultCacheManager
public class DefaultCacheManager
A CacheManager is the primary mechanism for retrieving a
Cache
instance, and is often used as a starting point to using the
Cache
.
Configuration
or a
path or URL to a configuration XML file.
Lifecycle - CacheManagers have a lifecycle (it implements
Lifecycle
) and the default constructors also call start()
.
Overloaded versions of the constructors are available, that do not start the
CacheManager, although it must be kept in mind that
CacheManagers need to be started before they can be used to create
Cache instances.
Once constructed, CacheManagers should be made available to any
component that requires a Cache, via JNDI or via some other
mechanism such as an IoC container.
You obtain Cache instances from the CacheManager by using
one of the overloaded getCache(), methods. Note that with
getCache(), there is no guarantee that the instance you get is
brand-new and empty, since caches are named and shared. Because of this, the
CacheManager also acts as a repository of Caches, and is an
effective mechanism of looking up or creating Caches on demand.
When the system shuts down, it should call stop()
on the
CacheManager. This will ensure all caches within its scope are
properly stopped as well.
Sample usage:
CacheManager manager = CacheManager.getInstance("my-config-file.xml"); Cache entityCache =
manager.getCache("myEntityCache"); entityCache.put("aPerson", new Person());
Configuration myNewConfiguration = new Configuration(); myNewConfiguration.setCacheMode(Configuration.CacheMode.LOCAL);
manager.defineConfiguration("myLocalCache", myNewConfiguration); Cache localCache = manager.getCache("myLocalCache");
Field Summary | |
---|---|
static String |
DEFAULT_CACHE_NAME
|
protected Configuration |
defaultConfiguration
|
protected GlobalConfiguration |
globalConfiguration
|
static String |
OBJECT_NAME
|
Constructor Summary | |
---|---|
DefaultCacheManager()
Constructs and starts a default instance of the CacheManager, using configuration defaults. |
|
DefaultCacheManager(boolean start)
Constructs a default instance of the CacheManager, using configuration defaults. |
|
DefaultCacheManager(Configuration defaultConfiguration)
Constructs and starts a new instance of the CacheManager, using the default configuration passed in. |
|
DefaultCacheManager(Configuration defaultConfiguration,
boolean start)
Constructs a new instance of the CacheManager, using the default configuration passed in. |
|
DefaultCacheManager(GlobalConfiguration globalConfiguration)
Constructs and starts a new instance of the CacheManager, using the global configuration passed in, and system defaults for the default named cache configuration. |
|
DefaultCacheManager(GlobalConfiguration globalConfiguration,
boolean start)
Constructs a new instance of the CacheManager, using the global configuration passed in, and system defaults for the default named cache configuration. |
|
DefaultCacheManager(GlobalConfiguration globalConfiguration,
Configuration defaultConfiguration)
Constructs and starts a new instance of the CacheManager, using the global and default configurations passed in. |
|
DefaultCacheManager(GlobalConfiguration globalConfiguration,
Configuration defaultConfiguration,
boolean start)
Constructs a new instance of the CacheManager, using the global and default configurations passed in. |
|
DefaultCacheManager(InputStream configurationStream)
Constructs and starts a new instance of the CacheManager, using the input stream passed in to read configuration file contents. |
|
DefaultCacheManager(InputStream configurationStream,
boolean start)
Constructs a new instance of the CacheManager, using the input stream passed in to read configuration file contents. |
|
DefaultCacheManager(String configurationFile)
Constructs and starts a new instance of the CacheManager, using the configuration file name passed in. |
|
DefaultCacheManager(String configurationFile,
boolean start)
Constructs a new instance of the CacheManager, using the configuration file name passed in. |
|
DefaultCacheManager(String globalConfigurationFile,
String defaultConfigurationFile,
String namedCacheFile,
boolean start)
Constructs a new instance of the CacheManager, using the two configuration file names passed in. |
Method Summary | ||
---|---|---|
void |
addListener(Object listener)
Adds a listener to the component. |
|
Configuration |
defineConfiguration(String cacheName,
Configuration configurationOverride)
Defines a named cache's configuration using the following algorithm: If cache name hasn't been defined before, this method creates a clone of the default cache's configuration, applies a clone of the configuration overrides passed in and returns this configuration instance. |
|
Configuration |
defineConfiguration(String cacheName,
String templateName,
Configuration configurationOverride)
Defines a named cache's configuration using the following algorithm: Regardless of whether the cache name has been defined or not, this method creates a clone of the configuration of the cache whose name matches the given template cache name, then applies a clone of the configuration overrides passed in and finally returns this configuration instance. |
|
Address |
getAddress()
|
|
|
getCache()
Retrieves the default cache associated with this cache manager. |
|
|
getCache(String cacheName)
Retrieves a named cache from the system. |
|
String |
getCacheManagerStatus()
|
|
Set<String> |
getCacheNames()
If no named caches are registered, this method returns an empty set. |
|
String |
getClusterName()
|
|
String |
getCreatedCacheCount()
|
|
Configuration |
getDefaultConfiguration()
Returns default configuration for this CacheManager |
|
String |
getDefinedCacheCount()
|
|
String |
getDefinedCacheNames()
|
|
GlobalConfiguration |
getGlobalConfiguration()
Returns global configuration for this CacheManager |
|
Set<Object> |
getListeners()
|
|
List<Address> |
getMembers()
|
|
String |
getName()
|
|
String |
getRunningCacheCount()
|
|
ComponentStatus |
getStatus()
|
|
String |
getVersion()
|
|
boolean |
isCoordinator()
|
|
void |
removeListener(Object listener)
Removes a listener from the component. |
|
void |
start()
|
|
void |
startCache()
|
|
void |
startCache(String cacheName)
|
|
void |
stop()
|
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_CACHE_NAME
public static final String OBJECT_NAME
protected final GlobalConfiguration globalConfiguration
protected final Configuration defaultConfiguration
Constructor Detail |
---|
public DefaultCacheManager()
public DefaultCacheManager(boolean start)
start
- if true, the cache manager is startedpublic DefaultCacheManager(Configuration defaultConfiguration)
GlobalConfiguration
.
defaultConfiguration
- configuration to use as a template for all caches createdpublic DefaultCacheManager(Configuration defaultConfiguration, boolean start)
GlobalConfiguration
.
defaultConfiguration
- configuration file to use as a template for all caches createdstart
- if true, the cache manager is startedpublic DefaultCacheManager(GlobalConfiguration globalConfiguration)
globalConfiguration
- GlobalConfiguration to use for all caches createdpublic DefaultCacheManager(GlobalConfiguration globalConfiguration, boolean start)
globalConfiguration
- GlobalConfiguration to use for all caches createdstart
- if true, the cache manager is started.public DefaultCacheManager(GlobalConfiguration globalConfiguration, Configuration defaultConfiguration)
globalConfiguration
- global configuration to use. If null, a default instance is
created.defaultConfiguration
- default configuration to use. If null, a default instance is
created.public DefaultCacheManager(GlobalConfiguration globalConfiguration, Configuration defaultConfiguration, boolean start)
globalConfiguration
- global configuration to use. If null, a default instance is
created.defaultConfiguration
- default configuration to use. If null, a default instance is
created.start
- if true, the cache manager is startedpublic DefaultCacheManager(String configurationFile) throws IOException
configurationFile
- name of configuration file to use as a template for all caches
created
IOException
- if there is a problem with the configuration file.public DefaultCacheManager(String configurationFile, boolean start) throws IOException
configurationFile
- name of configuration file to use as a template for all caches
createdstart
- if true, the cache manager is started
IOException
- if there is a problem with the configuration file.public DefaultCacheManager(InputStream configurationStream) throws IOException
configurationStream
- stream containing configuration file contents, to use as a
template for all caches created
IOException
- if there is a problem with the configuration stream.public DefaultCacheManager(InputStream configurationStream, boolean start) throws IOException
configurationStream
- stream containing configuration file contents, to use as a
template for all caches createdstart
- if true, the cache manager is started
IOException
- if there is a problem reading the configuration streampublic DefaultCacheManager(String globalConfigurationFile, String defaultConfigurationFile, String namedCacheFile, boolean start) throws IOException
start
- if true, the cache manager is startedglobalConfigurationFile
- name of file that contains the global configurationdefaultConfigurationFile
- name of file that contains the default configurationnamedCacheFile
- name of file that contains the named cache configuration
IOException
- if there is a problem with the configuration file.Method Detail |
---|
public Configuration defineConfiguration(String cacheName, Configuration configurationOverride)
defineConfiguration
in interface CacheManager
cacheName
- name of cache whose configuration is being definedconfigurationOverride
- configuration overrides to use
public Configuration defineConfiguration(String cacheName, String templateName, Configuration configurationOverride)
CacheManager.defineConfiguration(String, Configuration)
in the sense that the base configuration used is the default cache
configuration.
defineConfiguration
in interface CacheManager
cacheName
- name of cache whose configuration is being definedtemplateName
- name of cache to which to which apply overrides if cache name has not been previously
definedconfigurationOverride
- configuration overrides to use
public <K,V> Cache<K,V> getCache()
createCache(String)
since it is automatically created lazily
when first used.
As such, this method is always guaranteed to return the default cache.
getCache
in interface CacheManager
public <K,V> Cache<K,V> getCache(String cacheName)
defineConfiguration(String, Configuration)
or
defineConfiguration(String, String, Configuration)
methods, or
declared in the configuration file.
getCache
in interface CacheManager
cacheName
- name of cache to retrieve
public String getClusterName()
getClusterName
in interface CacheManager
public List<Address> getMembers()
getMembers
in interface CacheManager
public Address getAddress()
getAddress
in interface CacheManager
public boolean isCoordinator()
isCoordinator
in interface CacheManager
public void start()
start
in interface Lifecycle
public void stop()
stop
in interface Lifecycle
public void addListener(Object listener)
Listenable
Listener
and
further to that, contain methods annotated appropriately, otherwise the listener will not be registered.
See the Listener
annotation for more information.
addListener
in interface Listenable
listener
- must not be null.public void removeListener(Object listener)
Listenable
removeListener
in interface Listenable
listener
- listener to remove. Must not be null.public Set<Object> getListeners()
getListeners
in interface Listenable
public ComponentStatus getStatus()
getStatus
in interface CacheManager
public GlobalConfiguration getGlobalConfiguration()
CacheManager
getGlobalConfiguration
in interface CacheManager
public Configuration getDefaultConfiguration()
CacheManager
getDefaultConfiguration
in interface CacheManager
public Set<String> getCacheNames()
CacheManager
getCacheNames
in interface CacheManager
public String getCacheManagerStatus()
public String getDefinedCacheNames()
public String getDefinedCacheCount()
public String getCreatedCacheCount()
public String getRunningCacheCount()
public String getVersion()
public String getName()
public void startCache()
public void startCache(String cacheName)
public String toString()
toString
in class Object
|
Google Analytics | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |