org.ehcache.config.builders
Class CacheManagerBuilder<T extends CacheManager>

java.lang.Object
  extended by org.ehcache.config.builders.CacheManagerBuilder<T>
All Implemented Interfaces:
Builder<T>

public class CacheManagerBuilder<T extends CacheManager>
extends java.lang.Object
implements Builder<T>

The CacheManagerBuilder enables building cache managers using a fluent style.

As with all Ehcache builders, all instances are immutable and calling any method on the builder will return a new instance without modifying the one on which the method was called. This enables the sharing of builder instances without any risk of seeing them modified by code elsewhere.


Method Summary
 T build()
          Builds a CacheManager or a subtype of it uninitialized.
 T build(boolean init)
          Builds a CacheManager or a subtype of it and initializes it if requested.
static CacheManager newCacheManager(Configuration configuration)
          Creates a new CacheManager based on the provided configuration
static CacheManagerBuilder<CacheManager> newCacheManagerBuilder()
          Creates a new CacheManagerBuilder
static CacheManagerConfiguration<PersistentCacheManager> persistence(java.lang.String location)
          Convenience method to get a CacheManagerConfiguration for a PersistentCacheManager.
 CacheManagerBuilder<T> replacing(ServiceCreationConfiguration<?> overwriteServiceConfiguration)
          Replaces an existing ServiceCreationConfiguration of the same type on the returned builder.
 CacheManagerBuilder<T> using(Service service)
          Adds a Service instance to the returned builder.
 CacheManagerBuilder<T> using(ServiceCreationConfiguration<?> serviceConfiguration)
          Adds a ServiceCreationConfiguration to the returned builder.
<N extends T>
CacheManagerBuilder<N>
with(CacheManagerConfiguration<N> cfg)
          Specifies the returned CacheManager subtype through a specific CacheManagerConfiguration which will optionally add configurations to the returned builder.
<K,V> CacheManagerBuilder<T>
withCache(java.lang.String alias, CacheConfiguration<K,V> configuration)
          Adds a CacheConfiguration linked to the specified alias to the returned builder.
<K,V> CacheManagerBuilder<T>
withCache(java.lang.String alias, CacheConfigurationBuilder<K,V> configurationBuilder)
          Convenience method to add a CacheConfiguration linked to the specified alias to the returned builder by building it from the provided CacheConfigurationBuilder.
 CacheManagerBuilder<T> withClassLoader(java.lang.ClassLoader classLoader)
          Adds a ClassLoader, to use for non Ehcache types, to the returned builder
<C> CacheManagerBuilder<T>
withCopier(java.lang.Class<C> clazz, java.lang.Class<? extends Copier<C>> copier)
          Adds a default Copier for the specified type to the returned builder.
 CacheManagerBuilder<T> withDefaultDiskStoreThreadPool(java.lang.String threadPoolAlias)
          Adds a OffHeapDiskStoreProviderConfiguration, that specifies the thread pool to use, to the returned builder.
 CacheManagerBuilder<T> withDefaultEventListenersThreadPool(java.lang.String threadPoolAlias)
          Adds a CacheEventDispatcherFactoryConfiguration, that specifies the thread pool to use, to the returned builder.
 CacheManagerBuilder<T> withDefaultSizeOfMaxObjectGraph(long size)
          Adds a default SizeOfEngine configuration, that limits the max object graph to size, to the returned builder.
 CacheManagerBuilder<T> withDefaultSizeOfMaxObjectSize(long size, MemoryUnit unit)
          Adds a default SizeOfEngine configuration, that limits the max object size, to the returned builder.
 CacheManagerBuilder<T> withDefaultWriteBehindThreadPool(java.lang.String threadPoolAlias)
          Adds a WriteBehindProviderConfiguration, that specifies the thread pool to use, to the returned builder.
<C> CacheManagerBuilder<T>
withSerializer(java.lang.Class<C> clazz, java.lang.Class<? extends Serializer<C>> serializer)
          Adds a default Serializer for the specified type to the returned builder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

build

public T build(boolean init)
Builds a CacheManager or a subtype of it and initializes it if requested.

Parameters:
init - whether the returned CacheManager is to be initialized or not
Returns:
a CacheManager or a subtype of it

build

public T build()
Builds a CacheManager or a subtype of it uninitialized.

Specified by:
build in interface Builder<T extends CacheManager>
Returns:
a CacheManager or a subtype of it uninitialized

newCacheManager

public static CacheManager newCacheManager(Configuration configuration)
Creates a new CacheManager based on the provided configuration

Parameters:
configuration - the configuration to use
Returns:
a CacheManager

withCache

public <K,V> CacheManagerBuilder<T> withCache(java.lang.String alias,
                                              CacheConfiguration<K,V> configuration)
Adds a CacheConfiguration linked to the specified alias to the returned builder.

Type Parameters:
K - the cache key type
V - the cache value type
Parameters:
alias - the cache alias
configuration - the CacheConfiguration
Returns:
a new builder with the added cache configuration
See Also:
CacheConfigurationBuilder

withCache

public <K,V> CacheManagerBuilder<T> withCache(java.lang.String alias,
                                              CacheConfigurationBuilder<K,V> configurationBuilder)
Convenience method to add a CacheConfiguration linked to the specified alias to the returned builder by building it from the provided CacheConfigurationBuilder.

Type Parameters:
K - the cache key type
V - the cache value type
Parameters:
alias - the cache alias
configurationBuilder - the CacheConfigurationBuilder to get CacheConfiguration from
Returns:
a new builder with the added cache configuration
See Also:
CacheConfigurationBuilder

with

public <N extends T> CacheManagerBuilder<N> with(CacheManagerConfiguration<N> cfg)
Specifies the returned CacheManager subtype through a specific CacheManagerConfiguration which will optionally add configurations to the returned builder.

Type Parameters:
N - the subtype of CacheManager
Parameters:
cfg - the CacheManagerConfiguration to use
Returns:
a new builder ready to build a more specific subtype of cache manager
See Also:
persistence(String), PersistentCacheManager, CacheManagerPersistenceConfiguration

using

public CacheManagerBuilder<T> using(Service service)
Adds a Service instance to the returned builder.

The service instance will be used by the constructed CacheManager.

Parameters:
service - the Service to add
Returns:
a new builder with the added service

withCopier

public <C> CacheManagerBuilder<T> withCopier(java.lang.Class<C> clazz,
                                             java.lang.Class<? extends Copier<C>> copier)
Adds a default Copier for the specified type to the returned builder.

Type Parameters:
C - the type which can be copied
Parameters:
clazz - the Class for which the copier is
copier - the Copier instance
Returns:
a new builder with the added default copier

withSerializer

public <C> CacheManagerBuilder<T> withSerializer(java.lang.Class<C> clazz,
                                                 java.lang.Class<? extends Serializer<C>> serializer)
Adds a default Serializer for the specified type to the returned builder.

Type Parameters:
C - the type which can be serialized
Parameters:
clazz - the Class for which the serializer is
serializer - the Serializer instance
Returns:
a new builder with the added default serializer

withDefaultSizeOfMaxObjectGraph

public CacheManagerBuilder<T> withDefaultSizeOfMaxObjectGraph(long size)
Adds a default SizeOfEngine configuration, that limits the max object graph to size, to the returned builder.

Parameters:
size - the max object graph size
Returns:
a new builder with the added configuration

withDefaultSizeOfMaxObjectSize

public CacheManagerBuilder<T> withDefaultSizeOfMaxObjectSize(long size,
                                                             MemoryUnit unit)
Adds a default SizeOfEngine configuration, that limits the max object size, to the returned builder.

Parameters:
size - the max object size
unit - the max object size unit
Returns:
a new builder with the added configuration

withDefaultWriteBehindThreadPool

public CacheManagerBuilder<T> withDefaultWriteBehindThreadPool(java.lang.String threadPoolAlias)
Adds a WriteBehindProviderConfiguration, that specifies the thread pool to use, to the returned builder.

Parameters:
threadPoolAlias - the thread pool alias
Returns:
a new builder with the added configuration
See Also:
PooledExecutionServiceConfigurationBuilder

withDefaultDiskStoreThreadPool

public CacheManagerBuilder<T> withDefaultDiskStoreThreadPool(java.lang.String threadPoolAlias)
Adds a OffHeapDiskStoreProviderConfiguration, that specifies the thread pool to use, to the returned builder.

Parameters:
threadPoolAlias - the thread pool alias
Returns:
a new builder with the added configuration
See Also:
PooledExecutionServiceConfigurationBuilder

withDefaultEventListenersThreadPool

public CacheManagerBuilder<T> withDefaultEventListenersThreadPool(java.lang.String threadPoolAlias)
Adds a CacheEventDispatcherFactoryConfiguration, that specifies the thread pool to use, to the returned builder.

Parameters:
threadPoolAlias - the thread pool alias
Returns:
a new builder with the added configuration
See Also:
PooledExecutionServiceConfigurationBuilder

using

public CacheManagerBuilder<T> using(ServiceCreationConfiguration<?> serviceConfiguration)
Adds a ServiceCreationConfiguration to the returned builder.

These configurations are used to load services and configure them at creation time.

Parameters:
serviceConfiguration - the ServiceCreationConfiguration to use
Returns:
a new builder with the added configuration

replacing

public CacheManagerBuilder<T> replacing(ServiceCreationConfiguration<?> overwriteServiceConfiguration)
Replaces an existing ServiceCreationConfiguration of the same type on the returned builder.

Duplicate service creation configuration will cause a cache manager to fail to initialize.

Parameters:
overwriteServiceConfiguration - the new ServiceCreationConfiguration to use
Returns:
a new builder with the replaced configuration

withClassLoader

public CacheManagerBuilder<T> withClassLoader(java.lang.ClassLoader classLoader)
Adds a ClassLoader, to use for non Ehcache types, to the returned builder

Parameters:
classLoader - the class loader to use
Returns:
a new builder with the added class loader

newCacheManagerBuilder

public static CacheManagerBuilder<CacheManager> newCacheManagerBuilder()
Creates a new CacheManagerBuilder

Returns:
the cache manager builder

persistence

public static CacheManagerConfiguration<PersistentCacheManager> persistence(java.lang.String location)
Convenience method to get a CacheManagerConfiguration for a PersistentCacheManager.

Parameters:
location - the file location for persistent data
Returns:
a CacheManagerConfiguration
See Also:
with(CacheManagerConfiguration), PersistentCacheManager