javax.cache
Class MutableConfiguration<K,V>

java.lang.Object
  extended by javax.cache.MutableConfiguration<K,V>
Type Parameters:
K - the type of keys maintained the cache
V - the type of cached values
All Implemented Interfaces:
Configuration<K,V>

public class MutableConfiguration<K,V>
extends Object
implements Configuration<K,V>

A simple mutable implementation of a Configuration.

Since:
1.0
Author:
Brian Oliver

Nested Class Summary
 
Nested classes/interfaces inherited from interface javax.cache.Configuration
Configuration.Duration
 
Field Summary
protected  ArrayList<CacheEntryListenerRegistration<? super K,? super V>> cacheEntryListenerRegistrations
          The CacheEntryListenerRegistrations for the Configuration.
protected  CacheLoader<K,? extends V> cacheLoader
          The CacheLoader for the built Configuration.
protected  CacheWriter<? super K,? super V> cacheWriter
          The CacheWriter for the built Configuration.
protected  ExpiryPolicy<? super K,? super V> expiryPolicy
          The ExpiryPolicy for the Configuration.
protected  boolean isReadThrough
          A flag indicating if "read-through" mode is required.
protected  boolean isStatisticsEnabled
          A flag indicating if statistics gathering is enabled.
protected  boolean isStoreByValue
          A flag indicating if the cache will be store-by-value or store-by-reference.
protected  boolean isTransactionsEnabled
          A flag indicating if the cache will use transactions.
protected  boolean isWriteThrough
          A flag indicating if "write-through" mode is required.
protected  IsolationLevel txnIsolationLevel
          The transaction IsolationLevel.
protected  Mode txnMode
          The transaction Mode.
 
Constructor Summary
MutableConfiguration()
          Constructs an MutableConfiguration with the standard default values.
MutableConfiguration(Configuration<K,V> configuration)
          A copy-constructor for a MutableConfiguration.
MutableConfiguration(Iterable<CacheEntryListenerRegistration<? super K,? super V>> cacheEntryListenerRegistrations, CacheLoader<K,? extends V> cacheLoader, CacheWriter<? super K,? super V> cacheWriter, ExpiryPolicy<? super K,? super V> expiryPolicy, boolean isReadThrough, boolean isWriteThrough, boolean isStatisticsEnabled, boolean isStoreByValue, boolean isTransactionsEnabled, IsolationLevel txnIsolationLevel, Mode txnMode)
          Constructs a MutableConfiguration based on a set of parameters.
 
Method Summary
 boolean equals(Object object)
          
 Iterable<CacheEntryListenerRegistration<? super K,? super V>> getCacheEntryListenerRegistrations()
          Obtains the CacheEntryListenerRegistrations for CacheEntryListeners to be configured on a Cache.
 CacheLoader<K,? extends V> getCacheLoader()
          Gets the registered CacheLoader, if any.
 CacheWriter<? super K,? super V> getCacheWriter()
          Gets the registered CacheWriter, if any.
 ExpiryPolicy<? super K,? super V> getExpiryPolicy()
          Gets the ExpiryPolicy to be used for caches.
 IsolationLevel getTransactionIsolationLevel()
          Gets the transaction isolation level.
 Mode getTransactionMode()
          Gets the transaction mode.
 int hashCode()
          
 boolean isReadThrough()
          Determines if a Cache should operate in "read-through" mode.
 boolean isStatisticsEnabled()
          Checks whether statistics collection is enabled in this cache.
 boolean isStoreByValue()
          Whether storeByValue (true) or storeByReference (false).
 boolean isTransactionsEnabled()
          Checks whether transactions are enabled for this cache.
 boolean isWriteThrough()
          Determines if a Cache should operate in "write-through" mode.
 MutableConfiguration<K,V> registerCacheEntryListener(CacheEntryListener<? super K,? super V> cacheEntryListener, boolean requireOldValue, CacheEntryEventFilter<? super K,? super V> cacheEntryEventFilter, boolean synchronous)
          Add a CacheEntryListener.
 MutableConfiguration<K,V> setCacheLoader(CacheLoader<K,? extends V> loader)
          Set the CacheLoader.
 MutableConfiguration<K,V> setCacheWriter(CacheWriter<? super K,? super V> writer)
          Set the CacheWriter.
 MutableConfiguration<K,V> setExpiryPolicy(ExpiryPolicy<? super K,? super V> policy)
          Set the ExpiryPolicy.
 MutableConfiguration<K,V> setReadThrough(boolean isReadThrough)
          Set if read-through caching should be used.
 void setStatisticsEnabled(boolean enabled)
          Sets whether statistics gathering is enabled on a cache.
 MutableConfiguration<K,V> setStoreByValue(boolean isStoreByValue)
          Set if a configured cache should use "store-by-value" or "store-by-reference" semantics.
 MutableConfiguration<K,V> setTransactionMode(Mode mode)
          Set the Transaction Mode.
 MutableConfiguration<K,V> setTransactions(IsolationLevel level, Mode mode)
          Set the Transaction IsolationLevel and Mode.
 MutableConfiguration<K,V> setTransactionsEnabled(boolean isTransactionsEnabled)
          Set if transactions should be enabled.
 MutableConfiguration<K,V> setWriteThrough(boolean isWriteThrough)
          Set if write-through caching should be used.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheEntryListenerRegistrations

protected ArrayList<CacheEntryListenerRegistration<? super K,? super V>> cacheEntryListenerRegistrations
The CacheEntryListenerRegistrations for the Configuration.


cacheLoader

protected CacheLoader<K,? extends V> cacheLoader
The CacheLoader for the built Configuration.


cacheWriter

protected CacheWriter<? super K,? super V> cacheWriter
The CacheWriter for the built Configuration.


expiryPolicy

protected ExpiryPolicy<? super K,? super V> expiryPolicy
The ExpiryPolicy for the Configuration.


isReadThrough

protected boolean isReadThrough
A flag indicating if "read-through" mode is required.


isWriteThrough

protected boolean isWriteThrough
A flag indicating if "write-through" mode is required.


isStatisticsEnabled

protected boolean isStatisticsEnabled
A flag indicating if statistics gathering is enabled.


isStoreByValue

protected boolean isStoreByValue
A flag indicating if the cache will be store-by-value or store-by-reference.


isTransactionsEnabled

protected boolean isTransactionsEnabled
A flag indicating if the cache will use transactions.


txnIsolationLevel

protected IsolationLevel txnIsolationLevel
The transaction IsolationLevel.


txnMode

protected Mode txnMode
The transaction Mode.

Constructor Detail

MutableConfiguration

public MutableConfiguration()
Constructs an MutableConfiguration with the standard default values.


MutableConfiguration

public MutableConfiguration(Iterable<CacheEntryListenerRegistration<? super K,? super V>> cacheEntryListenerRegistrations,
                            CacheLoader<K,? extends V> cacheLoader,
                            CacheWriter<? super K,? super V> cacheWriter,
                            ExpiryPolicy<? super K,? super V> expiryPolicy,
                            boolean isReadThrough,
                            boolean isWriteThrough,
                            boolean isStatisticsEnabled,
                            boolean isStoreByValue,
                            boolean isTransactionsEnabled,
                            IsolationLevel txnIsolationLevel,
                            Mode txnMode)
Constructs a MutableConfiguration based on a set of parameters.

Parameters:
cacheEntryListenerRegistrations - the CacheEntryListenerRegistrations
cacheLoader - the CacheLoader
cacheWriter - the CacheWriter
expiryPolicy - the ExpiryPolicy
isReadThrough - is read-through caching supported
isWriteThrough - is write-through caching supported
isStatisticsEnabled - are statistics enabled
isStoreByValue - true if the "store-by-value" more or false for "store-by-reference"
isTransactionsEnabled - true if transactions are enabled
txnIsolationLevel - the IsolationLevel
txnMode - the Mode

MutableConfiguration

public MutableConfiguration(Configuration<K,V> configuration)
A copy-constructor for a MutableConfiguration.

Parameters:
configuration - the Configuration from which to copy
Method Detail

getCacheEntryListenerRegistrations

public Iterable<CacheEntryListenerRegistration<? super K,? super V>> getCacheEntryListenerRegistrations()
Obtains the CacheEntryListenerRegistrations for CacheEntryListeners to be configured on a Cache.

Specified by:
getCacheEntryListenerRegistrations in interface Configuration<K,V>
Returns:
an Iterable over the CacheEntryListenerRegistrations

registerCacheEntryListener

public MutableConfiguration<K,V> registerCacheEntryListener(CacheEntryListener<? super K,? super V> cacheEntryListener,
                                                            boolean requireOldValue,
                                                            CacheEntryEventFilter<? super K,? super V> cacheEntryEventFilter,
                                                            boolean synchronous)
Add a CacheEntryListener. If the specified CacheEntryListenerRegistration is already known, the request to add it is ignored.

Parameters:
cacheEntryListener - the CacheEntryListener
requireOldValue - whether the old value is supplied to CacheEntryEvent.
cacheEntryEventFilter - the CacheEntryEventFilter
synchronous - whether the caller is blocked until the listener invocation completes.

getCacheLoader

public CacheLoader<K,? extends V> getCacheLoader()
Gets the registered CacheLoader, if any.

A CacheLoader should be configured for "Read Through" caches to load values when a cache miss occurs using either the Cache.get(Object) and/or Cache#getAll(java.util.Set methods.

The default value is null.

Specified by:
getCacheLoader in interface Configuration<K,V>
Returns:
the CacheLoader or null if none has been set.

setCacheLoader

public MutableConfiguration<K,V> setCacheLoader(CacheLoader<K,? extends V> loader)
Set the CacheLoader.

Parameters:
loader - the CacheLoader
Returns:
the MutableConfiguration to permit fluent-style method calls

getCacheWriter

public CacheWriter<? super K,? super V> getCacheWriter()
Gets the registered CacheWriter, if any.

The default value is null.

Specified by:
getCacheWriter in interface Configuration<K,V>
Returns:
the CacheWriter or null if none has been set.

setCacheWriter

public MutableConfiguration<K,V> setCacheWriter(CacheWriter<? super K,? super V> writer)
Set the CacheWriter.

Parameters:
writer - the CacheWriter
Returns:
the MutableConfiguration to permit fluent-style method calls

getExpiryPolicy

public ExpiryPolicy<? super K,? super V> getExpiryPolicy()
Gets the ExpiryPolicy to be used for caches.

The default value is ExpiryPolicy#DEFAULT.

Specified by:
getExpiryPolicy in interface Configuration<K,V>
Returns:
the ExpiryPolicy (must not be null)

setExpiryPolicy

public MutableConfiguration<K,V> setExpiryPolicy(ExpiryPolicy<? super K,? super V> policy)
Set the ExpiryPolicy. If null is specified the ExpiryPolicy Default is assumed.

Parameters:
policy - the ExpiryPolicy
Returns:
the MutableConfiguration to permit fluent-style method calls

getTransactionIsolationLevel

public IsolationLevel getTransactionIsolationLevel()
Gets the transaction isolation level.

The default value is IsolationLevel.NONE.

Specified by:
getTransactionIsolationLevel in interface Configuration<K,V>
Returns:
the isolation level.

setTransactions

public MutableConfiguration<K,V> setTransactions(IsolationLevel level,
                                                 Mode mode)
Set the Transaction IsolationLevel and Mode.

Parameters:
level - the IsolationLevel
mode - the Mode
Returns:
the MutableConfiguration to permit fluent-style method calls

getTransactionMode

public Mode getTransactionMode()
Gets the transaction mode.

The default value is Mode.NONE.

Specified by:
getTransactionMode in interface Configuration<K,V>
Returns:
the the mode of the cache.

setTransactionMode

public MutableConfiguration<K,V> setTransactionMode(Mode mode)
Set the Transaction Mode.

Parameters:
mode - the Mode
Returns:
the MutableConfiguration to permit fluent-style method calls

isReadThrough

public boolean isReadThrough()
Determines if a Cache should operate in "read-through" mode.

When in "read-through" mode, cache misses that occur due to cache entries not existing as a result of performing a "get" call via one of Cache.get(Object), Cache.getAll(java.util.Set), Cache.getAndRemove(Object) and/or Cache.getAndReplace(Object, Object) will appropriately cause the configured CacheLoader to be invoked.

The default value is false.

Specified by:
isReadThrough in interface Configuration<K,V>
Returns:
true when a Cache is in "read-through" mode.
See Also:
Configuration.getCacheLoader()

setReadThrough

public MutableConfiguration<K,V> setReadThrough(boolean isReadThrough)
Set if read-through caching should be used.

Parameters:
isReadThrough - true if read-through is required
Returns:
the MutableConfiguration to permit fluent-style method calls

isWriteThrough

public boolean isWriteThrough()
Determines if a Cache should operate in "write-through" mode.

When in "write-through" mode, cache updates that occur as a result of performing "put" operations called via one of Cache.put(Object, Object), Cache.getAndRemove(Object), Cache.removeAll(), Cache.getAndPut(Object, Object) Cache.getAndRemove(Object), Cache.getAndReplace(Object, Object), Cache.invokeEntryProcessor(Object, javax.cache.Cache.EntryProcessor) will appropriately cause the configured CacheWriter to be invoked.

The default value is false.

Specified by:
isWriteThrough in interface Configuration<K,V>
Returns:
true when a Cache is in "write-through" mode.
See Also:
Configuration.getCacheWriter()

setWriteThrough

public MutableConfiguration<K,V> setWriteThrough(boolean isWriteThrough)
Set if write-through caching should be used.

Parameters:
isWriteThrough - true if write-through is required
Returns:
the MutableConfiguration to permit fluent-style method calls

isStoreByValue

public boolean isStoreByValue()
Whether storeByValue (true) or storeByReference (false). When true, both keys and values are stored by value.

When false, both keys and values are stored by reference. Caches stored by reference are capable of mutation by any threads holding the reference. The effects are:

Storage by reference only applies to the local heap. If an entry is moved off heap it will need to be transformed into a representation. Any mutations that occur after transformation may not be reflected in the cache.

When a cache is storeByValue, any mutation to the key or value does not affect the key of value stored in the cache.

The default value is true.

Specified by:
isStoreByValue in interface Configuration<K,V>
Returns:
true if the cache is store by value

setStoreByValue

public MutableConfiguration<K,V> setStoreByValue(boolean isStoreByValue)
Set if a configured cache should use "store-by-value" or "store-by-reference" semantics.

Parameters:
isStoreByValue - true if "store-by-value" is required, false for "store-by-reference"
Returns:
the MutableConfiguration to permit fluent-style method calls

isStatisticsEnabled

public boolean isStatisticsEnabled()
Checks whether statistics collection is enabled in this cache.

The default value is false.

Specified by:
isStatisticsEnabled in interface Configuration<K,V>
Returns:
true if statistics collection is enabled

setStatisticsEnabled

public void setStatisticsEnabled(boolean enabled)
Sets whether statistics gathering is enabled on a cache.

Statistics may be enabled or disabled at runtime via CacheManager.enableStatistics(String, boolean).

Parameters:
enabled - true to enable statistics, false to disable.

isTransactionsEnabled

public boolean isTransactionsEnabled()
Checks whether transactions are enabled for this cache.

Note that in a transactional cache, entries being mutated within a transaction cannot be expired by the cache.

The default value is false.

Specified by:
isTransactionsEnabled in interface Configuration<K,V>
Returns:
true if transaction are enabled

setTransactionsEnabled

public MutableConfiguration<K,V> setTransactionsEnabled(boolean isTransactionsEnabled)
Set if transactions should be enabled.

Parameters:
isTransactionsEnabled - true if transactions should be enabled
Returns:
the MutableConfiguration to permit fluent-style method calls

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object object)

Overrides:
equals in class Object


Copyright © 2013. All Rights Reserved.