org.ehcache.config.builders
Class CacheConfigurationBuilder<K,V>

java.lang.Object
  extended by org.ehcache.config.builders.CacheConfigurationBuilder<K,V>
All Implemented Interfaces:
Builder<CacheConfiguration<K,V>>

public class CacheConfigurationBuilder<K,V>
extends java.lang.Object
implements Builder<CacheConfiguration<K,V>>

The CacheConfigurationBuilder enables building CacheConfigurations 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
 CacheConfigurationBuilder<K,V> add(Builder<? extends ServiceConfiguration<?>> configurationBuilder)
          Convenience method to add a ServiceConfiguration that is produced by a Builder.
 CacheConfigurationBuilder<K,V> add(ServiceConfiguration<?> configuration)
          Adds a ServiceConfiguration to the returned builder.
 CacheConfiguration<K,V> build()
          Builds the instance
 CacheConfigurationBuilder<K,V> clearAllServiceConfig()
          Clears all ServiceConfigurations from the returned builder.
<T extends ServiceConfiguration<?>>
T
getExistingServiceConfiguration(java.lang.Class<T> clazz)
          Returns the first ServiceConfiguration with type matching the class passed in.
<T extends ServiceConfiguration<?>>
java.util.List<T>
getExistingServiceConfigurations(java.lang.Class<T> clazz)
          Returns all ServiceConfigurations of type matching the class passed in.
 boolean hasConfiguredExpiry()
          Indicates whether this builder has configured expiry or not.
static
<K,V> CacheConfigurationBuilder<K,V>
newCacheConfigurationBuilder(java.lang.Class<K> keyType, java.lang.Class<V> valueType)
          Creates a new instance ready to produce a CacheConfiguration with key type <K> and with value type <V>.
 CacheConfigurationBuilder<K,V> remove(ServiceConfiguration<?> configuration)
          Removes a ServiceConfiguration from the returned builder.
 CacheConfigurationBuilder<K,V> withClassLoader(java.lang.ClassLoader classLoader)
          Adds a ClassLoader to the returned builder.
 CacheConfigurationBuilder<K,V> withDiskStoreThreadPool(java.lang.String threadPoolAlias, int concurrency)
          Adds a ServiceConfiguration for the OffHeapDiskStore.Provider indicating thread pool alias and write concurrency.
 CacheConfigurationBuilder<K,V> withEventListenersThreadPool(java.lang.String threadPoolAlias)
          Adds a ServiceConfiguration for the CacheEventDispatcherFactory specifying the thread pool alias to use.
 CacheConfigurationBuilder<K,V> withEvictionVeto(EvictionVeto<? super K,? super V> veto)
          Adds an EvictionVeto to the returned builder.
 CacheConfigurationBuilder<K,V> withExpiry(Expiry<? super K,? super V> expiry)
          Adds Expiry configuration to the returned builder.
 CacheConfigurationBuilder<K,V> withKeyCopier(java.lang.Class<? extends Copier<K>> keyCopierClass)
          Adds by-value semantic using the provided Copier class for the key on heap.
 CacheConfigurationBuilder<K,V> withKeyCopier(Copier<K> keyCopier)
          Adds by-value semantic using the provided Copier for the key on heap.
 CacheConfigurationBuilder<K,V> withKeySerializer(java.lang.Class<? extends Serializer<K>> keySerializerClass)
          Adds a Serializer class for cache keys to the configured builder.
 CacheConfigurationBuilder<K,V> withKeySerializer(Serializer<K> keySerializer)
          Adds a Serializer for cache keys to the configured builder.
 CacheConfigurationBuilder<K,V> withKeySerializingCopier()
          Adds by-value semantic using the cache key serializer for the key on heap.
 CacheConfigurationBuilder<K,V> withLoaderWriter(CacheLoaderWriter<K,V> loaderWriter)
          Adds a CacheLoaderWriter to the configured builder.
 CacheConfigurationBuilder<K,V> withLoaderWriter(java.lang.Class<CacheLoaderWriter<K,V>> loaderWriterClass, java.lang.Object... arguments)
          Adds a CacheLoaderWriter configured through a class and optional constructor arguments to the configured builder.
 CacheConfigurationBuilder<K,V> withOrderedEventParallelism(int eventParallelism)
          Adds StoreEventSourceConfiguration with the specified ordered event parallelism to the configured builder.
 CacheConfigurationBuilder<K,V> withResourcePools(ResourcePools resourcePools)
          Adds the ResourcePools to the returned builder.
 CacheConfigurationBuilder<K,V> withResourcePools(ResourcePoolsBuilder resourcePoolsBuilder)
          Convenience method to add a ResourcePools through a ResourcePoolsBuilder to the returned builder.
 CacheConfigurationBuilder<K,V> withSizeOfMaxObjectGraph(long size)
          Adds or updates the DefaultSizeOfEngineConfiguration with the specified object graph maximum size to the configured builder.
 CacheConfigurationBuilder<K,V> withSizeOfMaxObjectSize(long size, MemoryUnit unit)
          Adds or updates the DefaultSizeOfEngineConfiguration with the specified maximum mapping size to the configured builder.
 CacheConfigurationBuilder<K,V> withValueCopier(java.lang.Class<? extends Copier<V>> valueCopierClass)
          Adds by-value semantic using the provided Copier class for the value on heap.
 CacheConfigurationBuilder<K,V> withValueCopier(Copier<V> valueCopier)
          Adds by-value semantic using the provided Copier for the value on heap.
 CacheConfigurationBuilder<K,V> withValueSerializer(java.lang.Class<? extends Serializer<V>> valueSerializerClass)
          Adds a Serializer class for cache values to the configured builder.
 CacheConfigurationBuilder<K,V> withValueSerializer(Serializer<V> valueSerializer)
          Adds a Serializer for cache values to the configured builder.
 CacheConfigurationBuilder<K,V> withValueSerializingCopier()
          Adds by-value semantic using the cache value serializer for the value on heap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newCacheConfigurationBuilder

public static <K,V> CacheConfigurationBuilder<K,V> newCacheConfigurationBuilder(java.lang.Class<K> keyType,
                                                                                java.lang.Class<V> valueType)
Creates a new instance ready to produce a CacheConfiguration with key type <K> and with value type <V>.

Type Parameters:
K - the key type
V - the value type
Parameters:
keyType - the key type
valueType - the value type
Returns:
a CacheConfigurationBuilder

add

public CacheConfigurationBuilder<K,V> add(ServiceConfiguration<?> configuration)
Adds a ServiceConfiguration to the returned builder.

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

add

public CacheConfigurationBuilder<K,V> add(Builder<? extends ServiceConfiguration<?>> configurationBuilder)
Convenience method to add a ServiceConfiguration that is produced by a Builder.

Parameters:
configurationBuilder - the service configuration to add, Builder.build() will be called on it
Returns:
a new builder with the added service configuration
See Also:
add(ServiceConfiguration)

withEvictionVeto

public CacheConfigurationBuilder<K,V> withEvictionVeto(EvictionVeto<? super K,? super V> veto)
Adds an EvictionVeto to the returned builder.

Parameters:
veto - the eviction veto to be used
Returns:
a new builder with the added eviction veto

remove

public CacheConfigurationBuilder<K,V> remove(ServiceConfiguration<?> configuration)
Removes a ServiceConfiguration from the returned builder.

Parameters:
configuration - the service configuration to remove
Returns:
a new builder without the specified configuration

clearAllServiceConfig

public CacheConfigurationBuilder<K,V> clearAllServiceConfig()
Clears all ServiceConfigurations from the returned builder.

Returns:
a new builder with no service configurations left

getExistingServiceConfiguration

public <T extends ServiceConfiguration<?>> T getExistingServiceConfiguration(java.lang.Class<T> clazz)
Returns the first ServiceConfiguration with type matching the class passed in.

Type Parameters:
T - the type of the service configuration
Parameters:
clazz - the service configuration class
Returns:
a matching service configuration, or null if none can be found

getExistingServiceConfigurations

public <T extends ServiceConfiguration<?>> java.util.List<T> getExistingServiceConfigurations(java.lang.Class<T> clazz)
Returns all ServiceConfigurations of type matching the class passed in.

Type Parameters:
T - the type of the service configuration
Parameters:
clazz - the service configuration class
Returns:
a list with service configurations

withClassLoader

public CacheConfigurationBuilder<K,V> withClassLoader(java.lang.ClassLoader classLoader)
Adds a ClassLoader to the returned builder.

The ClassLoader will be used for resolving all non Ehcache types.

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

withResourcePools

public CacheConfigurationBuilder<K,V> withResourcePools(ResourcePools resourcePools)
Adds the ResourcePools to the returned builder.

ResourcePools is what determines the tiering of a cache.

Parameters:
resourcePools - the resource pools to use
Returns:
a new builder with the added resource pools

withResourcePools

public CacheConfigurationBuilder<K,V> withResourcePools(ResourcePoolsBuilder resourcePoolsBuilder)
Convenience method to add a ResourcePools through a ResourcePoolsBuilder to the returned builder.

Parameters:
resourcePoolsBuilder - the builder providing the resource pool
Returns:
a new builder with the added resource pools
See Also:
withResourcePools(ResourcePools)

withExpiry

public CacheConfigurationBuilder<K,V> withExpiry(Expiry<? super K,? super V> expiry)
Adds Expiry configuration to the returned builder.

Expiry is what controls data freshness in a cache.

Parameters:
expiry - the expiry to use
Returns:
a new builder with the added expiry

hasConfiguredExpiry

public boolean hasConfiguredExpiry()
Indicates whether this builder has configured expiry or not.

Returns:
true if expiry configured, false otherwise

withLoaderWriter

public CacheConfigurationBuilder<K,V> withLoaderWriter(CacheLoaderWriter<K,V> loaderWriter)
Adds a CacheLoaderWriter to the configured builder.

Configuration of a CacheLoaderWriter is what enables cache-through patterns.

Parameters:
loaderWriter - the loaderwriter to use
Returns:
a new builder with the added loaderwriter configuration

withLoaderWriter

public CacheConfigurationBuilder<K,V> withLoaderWriter(java.lang.Class<CacheLoaderWriter<K,V>> loaderWriterClass,
                                                       java.lang.Object... arguments)
Adds a CacheLoaderWriter configured through a class and optional constructor arguments to the configured builder.

Configuration of a CacheLoaderWriter is what enables cache-through patterns.

Parameters:
loaderWriterClass - the loaderwrite class
arguments - optional constructor arguments
Returns:
a new builder with the added loaderwriter configuration

withKeySerializingCopier

public CacheConfigurationBuilder<K,V> withKeySerializingCopier()
Adds by-value semantic using the cache key serializer for the key on heap.

Copiers are what enable control of by-reference / by-value semantics for on-heap tier.

Returns:
a new builder with the added key copier

withValueSerializingCopier

public CacheConfigurationBuilder<K,V> withValueSerializingCopier()
Adds by-value semantic using the cache value serializer for the value on heap.

Copiers are what enable control of by-reference / by-value semantics for on-heap tier.

Returns:
a new builder with the added value copier

withKeyCopier

public CacheConfigurationBuilder<K,V> withKeyCopier(Copier<K> keyCopier)
Adds by-value semantic using the provided Copier for the key on heap.

Copiers are what enable control of by-reference / by-value semantics for on-heap tier.

Parameters:
keyCopier - the key copier to use
Returns:
a new builder with the added key copier

withKeyCopier

public CacheConfigurationBuilder<K,V> withKeyCopier(java.lang.Class<? extends Copier<K>> keyCopierClass)
Adds by-value semantic using the provided Copier class for the key on heap.

Copiers are what enable control of by-reference / by-value semantics for on-heap tier.

Parameters:
keyCopierClass - the key copier class to use
Returns:
a new builder with the added key copier

withValueCopier

public CacheConfigurationBuilder<K,V> withValueCopier(Copier<V> valueCopier)
Adds by-value semantic using the provided Copier for the value on heap.

Copiers are what enable control of by-reference / by-value semantics for on-heap tier.

Parameters:
valueCopier - the value copier to use
Returns:
a new builder with the added value copier

withValueCopier

public CacheConfigurationBuilder<K,V> withValueCopier(java.lang.Class<? extends Copier<V>> valueCopierClass)
Adds by-value semantic using the provided Copier class for the value on heap.

Copiers are what enable control of by-reference / by-value semantics for on-heap tier.

Parameters:
valueCopierClass - the value copier class to use
Returns:
a new builder with the added value copier

withKeySerializer

public CacheConfigurationBuilder<K,V> withKeySerializer(Serializer<K> keySerializer)
Adds a Serializer for cache keys to the configured builder.

Serializers are what enables cache storage beyond the heap tier.

Parameters:
keySerializer - the key serializer to use
Returns:
a new builder with the added key serializer

withKeySerializer

public CacheConfigurationBuilder<K,V> withKeySerializer(java.lang.Class<? extends Serializer<K>> keySerializerClass)
Adds a Serializer class for cache keys to the configured builder.

Serializers are what enables cache storage beyond the heap tier.

Parameters:
keySerializerClass - the key serializer to use
Returns:
a new builder with the added key serializer

withValueSerializer

public CacheConfigurationBuilder<K,V> withValueSerializer(Serializer<V> valueSerializer)
Adds a Serializer for cache values to the configured builder.

Serializers are what enables cache storage beyond the heap tier.

Parameters:
valueSerializer - the key serializer to use
Returns:
a new builder with the added value serializer

withValueSerializer

public CacheConfigurationBuilder<K,V> withValueSerializer(java.lang.Class<? extends Serializer<V>> valueSerializerClass)
Adds a Serializer class for cache values to the configured builder.

Serializers are what enables cache storage beyond the heap tier.

Parameters:
valueSerializerClass - the key serializer to use
Returns:
a new builder with the added value serializer

withOrderedEventParallelism

public CacheConfigurationBuilder<K,V> withOrderedEventParallelism(int eventParallelism)
Adds StoreEventSourceConfiguration with the specified ordered event parallelism to the configured builder.

Parameters:
eventParallelism - the amount of parallelism for handling events when ordering is required
Returns:
a new builder with the added configuration

withEventListenersThreadPool

public CacheConfigurationBuilder<K,V> withEventListenersThreadPool(java.lang.String threadPoolAlias)
Adds a ServiceConfiguration for the CacheEventDispatcherFactory specifying the thread pool alias to use.

Parameters:
threadPoolAlias - the thread pool alias to use
Returns:
a new builder with the added configuration

withDiskStoreThreadPool

public CacheConfigurationBuilder<K,V> withDiskStoreThreadPool(java.lang.String threadPoolAlias,
                                                              int concurrency)
Adds a ServiceConfiguration for the OffHeapDiskStore.Provider indicating thread pool alias and write concurrency.

Parameters:
threadPoolAlias - the thread pool alias
concurrency - the write concurrency
Returns:
a new builder with the added configuration

withSizeOfMaxObjectGraph

public CacheConfigurationBuilder<K,V> withSizeOfMaxObjectGraph(long size)
Adds or updates the DefaultSizeOfEngineConfiguration with the specified object graph maximum size to the configured builder.

SizeOfEngine is what enables the heap tier to be sized in MemoryUnit.

Parameters:
size - the maximum graph size
Returns:
a new builder with the added / updated configuration

withSizeOfMaxObjectSize

public CacheConfigurationBuilder<K,V> withSizeOfMaxObjectSize(long size,
                                                              MemoryUnit unit)
Adds or updates the DefaultSizeOfEngineConfiguration with the specified maximum mapping size to the configured builder.

SizeOfEngine is what enables the heap tier to be sized in MemoryUnit.

Parameters:
size - the maximum mapping size
unit - the memory unit
Returns:
a new builder with the added / updated configuration

build

public CacheConfiguration<K,V> build()
Description copied from interface: Builder
Builds the instance

Specified by:
build in interface Builder<CacheConfiguration<K,V>>
Returns:
the newly built instance