package org.infinispan.manager; import org.infinispan.Cache; import org.infinispan.config.Configuration; import org.infinispan.config.GlobalConfiguration; import org.infinispan.factories.annotations.NonVolatile; import org.infinispan.factories.scopes.Scope; import org.infinispan.factories.scopes.Scopes; import org.infinispan.lifecycle.ComponentStatus; import org.infinispan.lifecycle.Lifecycle; import org.infinispan.notifications.Listenable; import org.infinispan.remoting.transport.Address; import java.util.List; /** * A CacheManager is the primary mechanism for retrieving a {@link org.infinispan.Cache} instance, and is often * used as a starting point to using the {@link org.infinispan.Cache}. *

* CacheManagers are heavyweight objects, and we foresee no more than one CacheManager being used per * JVM (unless specific configuration requirements require more than one; but either way, this would be a minimal and * finite number of instances). *

* Constructing a CacheManager is done via one of its constructors, which optionally take in a {@link * org.infinispan.config.Configuration} or a path or URL to a configuration XML file. *

* Lifecycle - CacheManagers have a lifecycle (it implements {@link org.infinispan.lifecycle.Lifecycle}) and * the default constructors also call {@link #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 dependency injection framework. *

* 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 {@link #stop()} on the CacheManager. This will ensure all caches * within its scope are properly stopped as well. *

* Sample usage: CacheManager manager = new DefaultCacheManager("my-config-file.xml"); Cache entityCache = * manager.getCache("myEntityCache"); entityCache.put("aPerson", new Person()); *

* Configuration myNewConfiguration = new Configuration(); myNewConfiguration.setCacheMode(Configuration.CacheMode.LOCAL); * manager.defineCache("myLocalCache", myNewConfiguration); Cache localCache = manager.getCache("myLocalCache"); * * * @author Manik Surtani (manik@jboss.org) * @author Galder ZamarreƱo * @since 4.0 */ @Scope(Scopes.GLOBAL) @NonVolatile public interface CacheManager extends Lifecycle, Listenable { // /** // * Defines a named cache. Named caches can be defined by using this method, in which case the configuration passed // * in is used to override the default configuration used when this cache manager instance was created. // *

// * The other way to define named caches is declaratively, in the XML file passed in to the cache manager. // *

// * A combination of approaches may also be used, provided the names do not conflict. // * // * @param cacheName name of cache to define // * @param configurationOverride configuration overrides to use // * @throws DuplicateCacheNameException if the name is already in use. // */ // void defineCache(String cacheName, Configuration configurationOverride) throws DuplicateCacheNameException; /** * 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, * then applies the configuration overrides passed and returns this configuration instance. *

* If cache name has been previously defined, this method creates a clone of this cache's existing configuration, * applies the overrides and return the configuration instance. *

* The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache * manager. This method enables you to override certain properties that have previously been defined via XML. *

* Passing a brand new Configuration instance as configuration override without having called any of its setters * will effectively return the named cache's configuration since no overrides where passed to it. * * @param cacheName name of cache whose configuration is being defined * @param configurationOverride configuration overrides to use * @return a cloned configuration instance */ 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 configuration of the cache whose * name matches the given template cache name, then applies the configuration overrides passed and returns this * configuration instance. *

* If cache name has been previously defined, this method creates a clone of this cache's existing configuration, * applies the overrides and return this configuration instance. *

* The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache manager. * This method enables you to override certain properties that have previously been defined via XML. *

* Passing a brand new Configuration instance as configuration override without having called any of its setters * will effectively return the named cache's configuration since no overrides where passed to it. *

* If templateName is null or there's no named cache with that name, this methods works exactly like * {@link CacheManager#defineConfiguration(String, Configuration)} in the sense that the base configuration used is the * default configuration. * * @param cacheName name of cache whose configuration is being defined * @param templateName name of cache to which to which apply overrides if cache name has not been previously * defined * @param configurationOverride configuration overrides to use * @return a cloned configuration instance */ Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride); /** * Retrieves the default cache associated with this cache manager. *

* As such, this method is always guaranteed to return the default cache. * * @return the default cache. */ Cache getCache(); /** * Retrieves a named cache from the system. If the cache has been previously created with the same name, the running * cache instance is returned. Otherwise, this method attempts to create the cache first. *

* When creating a new cache, this method will use the configuration passed in to the CacheManager on construction, * as a template, and then optionally apply any overrides previously defined for the named cache using the {@link * #defineCache(String, org.infinispan.config.Configuration)} method, or declared in the configuration file. * * @param cacheName name of cache to retrieve * @return a cache instance identified by cacheName */ Cache getCache(String cacheName); /** * @return the name of the cluster. Null if running in local mode. */ String getClusterName(); List

getMembers(); Address getAddress(); boolean isCoordinator(); ComponentStatus getStatus(); /** * Returns the global configuration object associated to this CacheManager. */ public GlobalConfiguration getGlobalConfiguration(); }