org.ehcache.config.builders
Class UserManagedCacheBuilder<K,V,T extends UserManagedCache<K,V>>

java.lang.Object
  extended by org.ehcache.config.builders.UserManagedCacheBuilder<K,V,T>
Type Parameters:
K - the cache key type
V - the cache value type
T - the specific UserManagedCache type
All Implemented Interfaces:
Builder<T>

public class UserManagedCacheBuilder<K,V,T extends UserManagedCache<K,V>>
extends java.lang.Object
implements Builder<T>

The UserManagedCacheBuilder enables building UserManagedCaches using a fluent style.

UserManagedCaches are Caches that are not linked to a CacheManager.

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 an unitialized UserManagedCache.
 T build(boolean init)
          Builds the UserManagedCache, initializing it if requested.
 UserManagedCacheBuilder<K,V,T> identifier(java.lang.String identifier)
          Adds an identifier to the returned builder.
static
<K,V> UserManagedCacheBuilder<K,V,UserManagedCache<K,V>>
newUserManagedCacheBuilder(java.lang.Class<K> keyType, java.lang.Class<V> valueType)
          Creates a new UserManagedCacheBuilder.
 UserManagedCacheBuilder<K,V,T> using(Service service)
          Adds a Service to be made available to the returned builder.
 UserManagedCacheBuilder<K,V,T> using(ServiceCreationConfiguration<?> serviceConfiguration)
          Adds a ServiceCreationConfiguration, to trigger a service loading and its configuration, to the returned builder.
<N extends T>
UserManagedCacheBuilder<K,V,N>
with(UserManagedCacheConfiguration<K,V,N> cfg)
          Specifies the returned UserManagedCache subtype through a specific UserManagedCacheConfiguration which will optionally add configurations to the returned builder.
 UserManagedCacheBuilder<K,V,T> withClassLoader(java.lang.ClassLoader classLoader)
          Adds a ClassLoader, to load non Ehcache types, to the returned builder.
 UserManagedCacheBuilder<K,V,T> withEventDispatcher(CacheEventDispatcher<K,V> eventDispatcher)
          Adds an CacheEventDispatcher to the returned builder.
 UserManagedCacheBuilder<K,V,T> withEventExecutors(java.util.concurrent.ExecutorService orderedExecutor, java.util.concurrent.ExecutorService unOrderedExecutor)
          Adds the default CacheEventDispatcher using the provided ExecutorService to the returned builder.
 UserManagedCacheBuilder<K,V,T> withEventListeners(CacheEventListenerConfiguration... cacheEventListenerConfigurations)
          Adds one or more CacheEventListenerConfiguration to the returned builder.
 UserManagedCacheBuilder<K,V,T> withEventListeners(CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration)
          Convenience method to add a CacheEventListenerConfiguration based on the provided CacheEventListenerConfigurationBuilder to the returned builder.
 UserManagedCacheBuilder<K,V,T> withEvictionVeto(EvictionVeto<K,V> evictionVeto)
          Adds an EvictionVeto to the returned builder.
 UserManagedCacheBuilder<K,V,T> withExpiry(Expiry<K,V> expiry)
          Adds Expiry configuration to the returned builder.
 UserManagedCacheBuilder<K,V,T> withKeyCopier(Copier<K> keyCopier)
          Adds a configuration for key Copier to the returned builder.
 UserManagedCacheBuilder<K,V,T> withKeySerializer(Serializer<K> keySerializer)
          Adds a configuration for key Serializer to the returned builder.
 UserManagedCacheBuilder<K,V,T> withKeySerializingCopier()
          Adds a configuration for key copying using the key Serializer to the returned builder.
 UserManagedCacheBuilder<K,V,T> withLoaderWriter(CacheLoaderWriter<K,V> loaderWriter)
          Adds a CacheLoaderWriter to the returned builder.
 UserManagedCacheBuilder<K,V,T> withOrderedEventParallelism(int parallelism)
          Adds a configuration for the amount of ordered parallelism desired in event processing.
 UserManagedCacheBuilder<K,V,T> withResourcePools(ResourcePools resourcePools)
          Adds a ResourcePools configuration to the returned builder.
 UserManagedCacheBuilder<K,V,T> withResourcePools(ResourcePoolsBuilder resourcePoolsBuilder)
          Convenience method to add a ResourcePools configuration based on the provided ResourcePoolsBuilder to the returned builder.
 UserManagedCacheBuilder<K,V,T> withSizeOfMaxObjectGraph(long size)
          Adds or updates the DefaultSizeOfEngineProviderConfiguration with the specified object graph maximum size to the configured builder.
 UserManagedCacheBuilder<K,V,T> withSizeOfMaxObjectSize(long size, MemoryUnit unit)
          Adds or updates the DefaultSizeOfEngineProviderConfiguration with the specified maximum mapping size to the configured builder.
 UserManagedCacheBuilder<K,V,T> withValueCopier(Copier<V> valueCopier)
          Adds a configuration for value Copier to the returned builder.
 UserManagedCacheBuilder<K,V,T> withValueSerializer(Serializer<V> valueSerializer)
          Adds a configuration for value Serializer to the returned builder.
 UserManagedCacheBuilder<K,V,T> withValueSerializingCopier()
          Adds a configuration for value copying using the key Serializer 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 final T build(boolean init)
                                            throws java.lang.IllegalStateException
Builds the UserManagedCache, initializing it if requested.

Parameters:
init - whether to initialize or not the cache before returning
Returns:
a user managed cache
Throws:
java.lang.IllegalStateException - if the user managed cache cannot be built

build

public T build()
Builds an unitialized UserManagedCache.

Specified by:
build in interface Builder<T extends UserManagedCache<K,V>>
Returns:
an uninitialized user managed cache

with

public final <N extends T> UserManagedCacheBuilder<K,V,N> with(UserManagedCacheConfiguration<K,V,N> cfg)
Specifies the returned UserManagedCache subtype through a specific UserManagedCacheConfiguration which will optionally add configurations to the returned builder.

Type Parameters:
N - the subtype of UserManagedCache
Parameters:
cfg - the UserManagedCacheConfiguration to use
Returns:
a new builder ready to build a more specific subtype of user managed cache
See Also:
PersistentUserManagedCache, UserManagedPersistenceContext

identifier

public final UserManagedCacheBuilder<K,V,T> identifier(java.lang.String identifier)
Adds an identifier to the returned builder.

The identifier will be used in services and logging the way a cache alias would be inside a CacheManager

Parameters:
identifier - the identifier
Returns:
a new builder with the added identifier

withClassLoader

public final UserManagedCacheBuilder<K,V,T> withClassLoader(java.lang.ClassLoader classLoader)
Adds a ClassLoader, to load non Ehcache types, to the returned builder.

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

withExpiry

public final UserManagedCacheBuilder<K,V,T> withExpiry(Expiry<K,V> expiry)
Adds Expiry configuration to the returned builder.

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

withEventDispatcher

public final UserManagedCacheBuilder<K,V,T> withEventDispatcher(CacheEventDispatcher<K,V> eventDispatcher)
Adds an CacheEventDispatcher to the returned builder.

This is one way of providing a mandatory part of supporting event listeners in UserManagedCache

Parameters:
eventDispatcher - the event dispatcher to use
Returns:
a new builder with the configured event dispatcher
See Also:
withEventExecutors(ExecutorService, ExecutorService), withEventListeners(CacheEventListenerConfiguration...), withEventListeners(CacheEventListenerConfigurationBuilder)

withEventExecutors

public final UserManagedCacheBuilder<K,V,T> withEventExecutors(java.util.concurrent.ExecutorService orderedExecutor,
                                                               java.util.concurrent.ExecutorService unOrderedExecutor)
Adds the default CacheEventDispatcher using the provided ExecutorService to the returned builder.

This is one way of providing a mandatory part of supporting event listeners in UserManagedCache

Parameters:
orderedExecutor - the ordered event executor service
unOrderedExecutor - the unordered event executor service
Returns:
a new builder with the configured event dispatcher
See Also:
withEventDispatcher(CacheEventDispatcher), withEventListeners(CacheEventListenerConfiguration...), withEventListeners(CacheEventListenerConfigurationBuilder)

withEventListeners

public final UserManagedCacheBuilder<K,V,T> withEventListeners(CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration)
Convenience method to add a CacheEventListenerConfiguration based on the provided CacheEventListenerConfigurationBuilder to the returned builder.

Parameters:
cacheEventListenerConfiguration - the builder to get the configuration from
Returns:
a new builder with the added event listener configuration
See Also:
withEventDispatcher(CacheEventDispatcher), withEventExecutors(ExecutorService, ExecutorService), withEventListeners(CacheEventListenerConfiguration...)

withEventListeners

public final UserManagedCacheBuilder<K,V,T> withEventListeners(CacheEventListenerConfiguration... cacheEventListenerConfigurations)
Adds one or more CacheEventListenerConfiguration to the returned builder.

Parameters:
cacheEventListenerConfigurations - the cache event listener configurations
Returns:
a new builders with the added event listener configurations
See Also:
withEventDispatcher(CacheEventDispatcher), withEventExecutors(ExecutorService, ExecutorService), withEventListeners(CacheEventListenerConfigurationBuilder)

withResourcePools

public final UserManagedCacheBuilder<K,V,T> withResourcePools(ResourcePools resourcePools)
Adds a ResourcePools configuration to the returned builder.

Parameters:
resourcePools - the resource pools to use
Returns:
a new builder with the configured resource pools
See Also:
withResourcePools(ResourcePoolsBuilder)

withResourcePools

public final UserManagedCacheBuilder<K,V,T> withResourcePools(ResourcePoolsBuilder resourcePoolsBuilder)
Convenience method to add a ResourcePools configuration based on the provided ResourcePoolsBuilder to the returned builder.

Parameters:
resourcePoolsBuilder - the builder to get the resource pools from
Returns:
a new builder with the configured resource pools
See Also:
withResourcePools(ResourcePools)

withOrderedEventParallelism

public final UserManagedCacheBuilder<K,V,T> withOrderedEventParallelism(int parallelism)
Adds a configuration for the amount of ordered parallelism desired in event processing.

Parameters:
parallelism - the parallelism level
Returns:
a new builder with the added configuration

withEvictionVeto

public UserManagedCacheBuilder<K,V,T> withEvictionVeto(EvictionVeto<K,V> evictionVeto)
Adds an EvictionVeto to the returned builder.

Parameters:
evictionVeto - the eviction veto to use
Returns:
a new builder with the added eviction veto

withLoaderWriter

public UserManagedCacheBuilder<K,V,T> withLoaderWriter(CacheLoaderWriter<K,V> loaderWriter)
Adds a CacheLoaderWriter to the returned builder.

Parameters:
loaderWriter - the cache loader writer to use
Returns:
a new builder with the added cache loader writer

withKeySerializingCopier

public UserManagedCacheBuilder<K,V,T> withKeySerializingCopier()
Adds a configuration for key copying using the key Serializer to the returned builder.

Returns:
a new builder with the added configuration
See Also:
withKeyCopier(Copier), withKeySerializer(Serializer)

withValueSerializingCopier

public UserManagedCacheBuilder<K,V,T> withValueSerializingCopier()
Adds a configuration for value copying using the key Serializer to the returned builder.

Returns:
a new builder with the added configuration
See Also:
withValueCopier(Copier), withValueSerializer(Serializer)

withKeyCopier

public UserManagedCacheBuilder<K,V,T> withKeyCopier(Copier<K> keyCopier)
Adds a configuration for key Copier to the returned builder.

Parameters:
keyCopier - the key copier to use
Returns:
a new builder with the added key copier configuration
See Also:
withKeySerializingCopier()

withValueCopier

public UserManagedCacheBuilder<K,V,T> withValueCopier(Copier<V> valueCopier)
Adds a configuration for value Copier to the returned builder.

Parameters:
valueCopier - the value copier to use
Returns:
a new builder with the added value copier configuration
See Also:
withValueSerializingCopier()

withKeySerializer

public UserManagedCacheBuilder<K,V,T> withKeySerializer(Serializer<K> keySerializer)
Adds a configuration for key Serializer to the returned builder.

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

withValueSerializer

public UserManagedCacheBuilder<K,V,T> withValueSerializer(Serializer<V> valueSerializer)
Adds a configuration for value Serializer to the returned builder.

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

withSizeOfMaxObjectGraph

public UserManagedCacheBuilder<K,V,T> withSizeOfMaxObjectGraph(long size)
Adds or updates the DefaultSizeOfEngineProviderConfiguration 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 UserManagedCacheBuilder<K,V,T> withSizeOfMaxObjectSize(long size,
                                                              MemoryUnit unit)
Adds or updates the DefaultSizeOfEngineProviderConfiguration 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

newUserManagedCacheBuilder

public static <K,V> UserManagedCacheBuilder<K,V,UserManagedCache<K,V>> newUserManagedCacheBuilder(java.lang.Class<K> keyType,
                                                                                                  java.lang.Class<V> valueType)
Creates a new UserManagedCacheBuilder.

Type Parameters:
K - the key type
V - the value type
Parameters:
keyType - the cache key type
valueType - the cache value type
Returns:
the new builder

using

public UserManagedCacheBuilder<K,V,T> using(Service service)
Adds a Service to be made available to the returned builder.

Note that while Services will be started upon UserManagedCache construction, no other lifecycle operations will be performed on them. It is the responsibility of the developer to properly stop Services once they are no longer required.

Parameters:
service - the service to add
Returns:
a new builder with the added service
See Also:
using(ServiceCreationConfiguration)

using

public UserManagedCacheBuilder<K,V,T> using(ServiceCreationConfiguration<?> serviceConfiguration)
Adds a ServiceCreationConfiguration, to trigger a service loading and its configuration, to the returned builder.

Note that while Services will be started upon UserManagedCache construction, no other lifecycle operations will be performed on them. It is the responsibility of the developer to properly stop Services once they are no longer required. Which means that this method should not be used to get services that require a stop.

Parameters:
serviceConfiguration - the service creation configuration to add
Returns:
a new builder with the added service creation configuration
See Also:
using(Service)