org.jboss.cache
Class DefaultCacheFactory<K,V>

java.lang.Object
  extended by org.jboss.cache.factories.ComponentFactory
      extended by org.jboss.cache.DefaultCacheFactory<K,V>
All Implemented Interfaces:
CacheFactory<K,V>

public class DefaultCacheFactory<K,V>
extends ComponentFactory
implements CacheFactory<K,V>

Default implementation of the CacheFactory interface.

This is a special instance of a ComponentFactory which contains bootstrap information for the ComponentRegistry.

E.g., bootstrap(CacheImpl, CacheSPI, org.jboss.cache.config.Configuration) is used to create a cache, a ComponentRegistry, and then wire dependencies as needed.

In JBoss Cache 2.0.x, this was a singleton and you had to use getInstance() to obtain an instance. From JBoss Cache 2.1.x onwards, this is no longer a singleton and you can use the default no-arg constructor to obtain a reference. getInstance() has been deprecated and modified to return a new instance of this class.

Author:
Manik Surtani (manik@jboss.org)
See Also:
ComponentFactory

Field Summary
 
Fields inherited from class org.jboss.cache.factories.ComponentFactory
componentRegistry, configuration, log
 
Constructor Summary
DefaultCacheFactory()
           
 
Method Summary
protected  void bootstrap(CacheImpl cache, CacheSPI spi, Configuration configuration)
          Bootstraps this factory with a Configuration and a ComponentRegistry
protected
<T> T
construct(String componentName, Class<T> componentType)
          Constructs a component.
protected  CacheSPI<K,V> createAndWire(Configuration configuration)
           
 Cache<K,V> createCache()
          Creates and starts a Cache instance using default configuration settings.
 Cache<K,V> createCache(boolean start)
          Creates and optionally starts a Cache instance using default configuration settings.
 Cache<K,V> createCache(Configuration configuration)
          This implementation clones the configuration passed in before using it.
 Cache<K,V> createCache(Configuration configuration, boolean start)
          This implementation clones the configuration passed in before using it.
 Cache<K,V> createCache(InputStream is)
          Creates a Cache instance based on an InputStream passed in, which should be a stream to a valid XML configuration file.
 Cache<K,V> createCache(InputStream is, boolean start)
          Creates a Cache instance based on an InputStream passed in, which should be a stream to a valid XML configuration file.
 Cache<K,V> createCache(String configFileName)
          Creates and starts a Cache instance.
 Cache<K,V> createCache(String configFileName, boolean start)
          Creates Cache instance, and optionally starts it.
static
<K,V> CacheFactory<K,V>
getInstance()
          Deprecated. 
 
Methods inherited from class org.jboss.cache.factories.ComponentFactory
assertTypeConstructable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCacheFactory

public DefaultCacheFactory()
Method Detail

getInstance

@Deprecated
public static <K,V> CacheFactory<K,V> getInstance()
Deprecated. 

Note - this method used to return a singleton instance, and since 2.1.0 returns a new instance. The method is deprecated and you should use the no-arg constructor to create a new instance of this factory.

Returns:
a NEW instance of this class.

createCache

public Cache<K,V> createCache()
                       throws ConfigurationException
Description copied from interface: CacheFactory
Creates and starts a Cache instance using default configuration settings. See Configuration for default values.

Specified by:
createCache in interface CacheFactory<K,V>
Returns:
a cache
Throws:
ConfigurationException - if there are problems with the default configuration

createCache

public Cache<K,V> createCache(boolean start)
                       throws ConfigurationException
Description copied from interface: CacheFactory
Creates and optionally starts a Cache instance using default configuration settings. See Configuration for default values.

Specified by:
createCache in interface CacheFactory<K,V>
Parameters:
start - if true, starts the cache
Returns:
a cache
Throws:
ConfigurationException - if there are problems with the default configuration

createCache

public Cache<K,V> createCache(String configFileName)
                       throws ConfigurationException
Description copied from interface: CacheFactory
Creates and starts a Cache instance. The following are all valid calls:
    factory.createCache("myCacheService.xml"); // file is in class path
    factory.createCache("etc/myCacheService.xml"); // file is in etc/ relative to the directory you started the JVM
    factory.createCache("/home/jbosscache/myCacheService.xml"); // file is in the /home/jbosscache directory
 

Specified by:
createCache in interface CacheFactory<K,V>
Parameters:
configFileName - the named XML file should exist in the classpath or should be a fully qualified or relative (to your JVM working directory) path to a file on the local file system. Note that the classpath is checked first for the existence of this file.
Returns:
a running Cache instance
Throws:
ConfigurationException - if there are problems with the configuration

createCache

public Cache<K,V> createCache(String configFileName,
                              boolean start)
                       throws ConfigurationException
Description copied from interface: CacheFactory
Creates Cache instance, and optionally starts it.

Specified by:
createCache in interface CacheFactory<K,V>
Parameters:
configFileName - the named XML file should exist in the classpath or should be a fully qualified or relative (to your JVM working directory) path to a file on the local file system. Note that the classpath is checked first for the existence of this file.
start - if true, the cache is started before returning.
Returns:
an optionally running Cache instance
Throws:
ConfigurationException - if there are problems with the configuration
See Also:
for examples on valid config file names.

createCache

public Cache<K,V> createCache(Configuration configuration)
                       throws ConfigurationException
This implementation clones the configuration passed in before using it.

Specified by:
createCache in interface CacheFactory<K,V>
Parameters:
configuration - to use
Returns:
a cache
Throws:
ConfigurationException - if there are problems with the cfg

createCache

public Cache<K,V> createCache(Configuration configuration,
                              boolean start)
                       throws ConfigurationException
This implementation clones the configuration passed in before using it.

Specified by:
createCache in interface CacheFactory<K,V>
Parameters:
configuration - to use
start - whether to start the cache
Returns:
a cache
Throws:
ConfigurationException - if there are problems with the cfg

createAndWire

protected CacheSPI<K,V> createAndWire(Configuration configuration)
                               throws Exception
Throws:
Exception

bootstrap

protected void bootstrap(CacheImpl cache,
                         CacheSPI spi,
                         Configuration configuration)
Bootstraps this factory with a Configuration and a ComponentRegistry

Parameters:
cache -
configuration -

createCache

public Cache<K,V> createCache(InputStream is)
                       throws ConfigurationException
Description copied from interface: CacheFactory
Creates a Cache instance based on an InputStream passed in, which should be a stream to a valid XML configuration file.

Specified by:
createCache in interface CacheFactory<K,V>
Parameters:
is - the InputStream
Returns:
a running Cache instance
Throws:
ConfigurationException - if there are problems with the configuration

createCache

public Cache<K,V> createCache(InputStream is,
                              boolean start)
                       throws ConfigurationException
Description copied from interface: CacheFactory
Creates a Cache instance based on an InputStream passed in, which should be a stream to a valid XML configuration file.

Specified by:
createCache in interface CacheFactory<K,V>
Parameters:
is - the InputStream
start - if true, the cache is started before returning.
Returns:
a running Cache instance
Throws:
ConfigurationException - if there are problems with the configuration

construct

protected <T> T construct(String componentName,
                          Class<T> componentType)
Description copied from class: ComponentFactory
Constructs a component.

Specified by:
construct in class ComponentFactory
Parameters:
componentName - optional, if the ComponentName annotation is used with the parameter, it's value is passed in here for the implementing factory to use.
componentType - type of component
Returns:
a component


Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.