Package net.sf.ehcache.config
Class CacheWriterConfiguration
- java.lang.Object
-
- net.sf.ehcache.config.CacheWriterConfiguration
-
- All Implemented Interfaces:
java.lang.Cloneable
public class CacheWriterConfiguration extends java.lang.Object implements java.lang.CloneableClass to hold the CacheWriterManager configuration- Version:
- $Id$
- Author:
- Geert Bevin
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCacheWriterConfiguration.CacheWriterFactoryConfigurationConfiguration for the CacheWriterFactoryConfiguration.static classCacheWriterConfiguration.WriteModeRepresents how elements are written to theCacheWriter
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_WRITE_DELAYDefault maximum write delaystatic intDEFAULT_MIN_WRITE_DELAYDefault minimum write delaystatic booleanDEFAULT_NOTIFY_LISTENERS_ON_EXCEPTIONDefault notifyListenersOnException behaviorstatic intDEFAULT_RATE_LIMIT_PER_SECONDDefault rate limit per secondstatic intDEFAULT_RETRY_ATTEMPT_DELAY_SECONDSDefault retry attempt delaystatic intDEFAULT_RETRY_ATTEMPTSDefault retry attemptsstatic intDEFAULT_WRITE_BATCH_SIZEDefault write batch sizestatic booleanDEFAULT_WRITE_BATCHINGDefault writeBatching behaviorstatic intDEFAULT_WRITE_BEHIND_CONCURRENCYDefault concurrency level for write behindstatic intDEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZEDefault max queue size for write behindstatic booleanDEFAULT_WRITE_COALESCINGDefault write coalescing behaviorstatic CacheWriterConfiguration.WriteModeDEFAULT_WRITE_MODEDefault writeMode
-
Constructor Summary
Constructors Constructor Description CacheWriterConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCacheWriterFactory(CacheWriterConfiguration.CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration)Allows BeanHandler to add the CacheWriterFactory to the configuration.CacheWriterConfigurationcacheWriterFactory(CacheWriterConfiguration.CacheWriterFactoryConfiguration cacheWriterFactory)CacheWriterConfigurationclone()Clones this object, following the usual contract.booleanequals(java.lang.Object obj)Overrided equals()CacheWriterConfiguration.CacheWriterFactoryConfigurationgetCacheWriterFactoryConfiguration()AccessorintgetMaxWriteDelay()Get the maximum number of seconds to wait before writing behindintgetMinWriteDelay()Get the minimum number of seconds to wait before writing behindbooleangetNotifyListenersOnException()Check whether listeners should be notified when an exception occurs on a writer operationintgetRateLimitPerSecond()Get the maximum number of write operations to allow per second.intgetRetryAttemptDelaySeconds()Retrieves the number of seconds to wait before retrying an failed operation.intgetRetryAttempts()Retrieves the number of times the write of element is retried.booleangetWriteBatching()Check whether write operations should be batchedintgetWriteBatchSize()Retrieves the size of the batch operation.intgetWriteBehindConcurrency()AccessorintgetWriteBehindMaxQueueSize()AccessorbooleangetWriteCoalescing()CacheWriterConfiguration.WriteModegetWriteMode()Get the write mode in terms of the mode enuminthashCode()Overrided hashCode()CacheWriterConfigurationmaxWriteDelay(int maxWriteDelay)CacheWriterConfigurationminWriteDelay(int minWriteDelay)CacheWriterConfigurationnotifyListenersOnException(boolean notifyListenersOnException)CacheWriterConfigurationrateLimitPerSecond(int rateLimitPerSecond)CacheWriterConfigurationretryAttemptDelaySeconds(int retryAttemptDelaySeconds)CacheWriterConfigurationretryAttempts(int retryAttempts)voidsetMaxWriteDelay(int maxWriteDelay)Set the maximum number of seconds to wait before writing behind.voidsetMinWriteDelay(int minWriteDelay)Set the minimum number of seconds to wait before writing behind.voidsetNotifyListenersOnException(boolean notifyListenersOnException)Sets whether to notify listeners when an exception occurs on a writer operation.voidsetRateLimitPerSecond(int rateLimitPerSecond)Sets the maximum number of write operations to allow per second whenwriteBatchingis enabled.voidsetRetryAttemptDelaySeconds(int retryAttemptDelaySeconds)Sets the number of seconds to wait before retrying an failed operation.voidsetRetryAttempts(int retryAttempts)Sets the number of times the operation is retried in theCacheWriter, this happens after the original operation.voidsetWriteBatching(boolean writeBatching)Sets whether to batch write operations.voidsetWriteBatchSize(int writeBatchSize)Sets the number of operations to include in each batch whenwriteBatchingis enabled.voidsetWriteBehindConcurrency(int concurrency)Configures the amount of thread/bucket pairs WriteBehind should usevoidsetWriteBehindMaxQueueSize(int writeBehindMaxQueueSize)Configures the maximum amount of operations to be on the waiting queue, before it blocksvoidsetWriteCoalescing(boolean writeCoalescing)Sets whether to use write coalescing.voidsetWriteMode(java.lang.String writeMode)Converts thewriteModestring argument to uppercase and looks up enum constant in WriteMode.voidvalidate(java.util.Collection<ConfigError> errors)Check for errors/inconsistencies in this configuration.CacheWriterConfigurationwriteBatching(boolean writeBatching)CacheWriterConfigurationwriteBatchSize(int writeBatchSize)CacheWriterConfigurationwriteBehindConcurrency(int concurrency)CacheWriterConfigurationwriteBehindMaxQueueSize(int writeBehindMaxQueueSize)CacheWriterConfigurationwriteCoalescing(boolean writeCoalescing)CacheWriterConfigurationwriteMode(java.lang.String writeMode)CacheWriterConfigurationwriteMode(CacheWriterConfiguration.WriteMode writeMode)
-
-
-
Field Detail
-
DEFAULT_WRITE_MODE
public static final CacheWriterConfiguration.WriteMode DEFAULT_WRITE_MODE
Default writeMode
-
DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION
public static final boolean DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION
Default notifyListenersOnException behavior- See Also:
- Constant Field Values
-
DEFAULT_MIN_WRITE_DELAY
public static final int DEFAULT_MIN_WRITE_DELAY
Default minimum write delay- See Also:
- Constant Field Values
-
DEFAULT_MAX_WRITE_DELAY
public static final int DEFAULT_MAX_WRITE_DELAY
Default maximum write delay- See Also:
- Constant Field Values
-
DEFAULT_RATE_LIMIT_PER_SECOND
public static final int DEFAULT_RATE_LIMIT_PER_SECOND
Default rate limit per second- See Also:
- Constant Field Values
-
DEFAULT_WRITE_COALESCING
public static final boolean DEFAULT_WRITE_COALESCING
Default write coalescing behavior- See Also:
- Constant Field Values
-
DEFAULT_WRITE_BATCHING
public static final boolean DEFAULT_WRITE_BATCHING
Default writeBatching behavior- See Also:
- Constant Field Values
-
DEFAULT_WRITE_BATCH_SIZE
public static final int DEFAULT_WRITE_BATCH_SIZE
Default write batch size- See Also:
- Constant Field Values
-
DEFAULT_RETRY_ATTEMPTS
public static final int DEFAULT_RETRY_ATTEMPTS
Default retry attempts- See Also:
- Constant Field Values
-
DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS
public static final int DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS
Default retry attempt delay- See Also:
- Constant Field Values
-
DEFAULT_WRITE_BEHIND_CONCURRENCY
public static final int DEFAULT_WRITE_BEHIND_CONCURRENCY
Default concurrency level for write behind- See Also:
- Constant Field Values
-
DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE
public static final int DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE
Default max queue size for write behind- See Also:
- Constant Field Values
-
-
Method Detail
-
clone
public CacheWriterConfiguration clone()
Clones this object, following the usual contract.- Overrides:
clonein classjava.lang.Object- Returns:
- a copy, which independent other than configurations than cannot change.
-
setWriteMode
public void setWriteMode(java.lang.String writeMode)
Converts thewriteModestring argument to uppercase and looks up enum constant in WriteMode.
-
writeMode
public CacheWriterConfiguration writeMode(java.lang.String writeMode)
- Returns:
- this configuration instance
- See Also:
setWriteMode(String)
-
writeMode
public CacheWriterConfiguration writeMode(CacheWriterConfiguration.WriteMode writeMode)
- Returns:
- this configuration instance
- See Also:
setWriteMode(String)
-
getWriteMode
public CacheWriterConfiguration.WriteMode getWriteMode()
Get the write mode in terms of the mode enum
-
setNotifyListenersOnException
public void setNotifyListenersOnException(boolean notifyListenersOnException)
Sets whether to notify listeners when an exception occurs on a writer operation.This is only applicable to write through mode.
Defaults to false.
- Parameters:
notifyListenersOnException-trueif listeners should be notified when an exception occurs on a writer operation;falseotherwise
-
notifyListenersOnException
public CacheWriterConfiguration notifyListenersOnException(boolean notifyListenersOnException)
- Returns:
- this configuration instance
- See Also:
setNotifyListenersOnException(boolean)
-
getNotifyListenersOnException
public boolean getNotifyListenersOnException()
Check whether listeners should be notified when an exception occurs on a writer operation
-
setMinWriteDelay
public void setMinWriteDelay(int minWriteDelay)
Set the minimum number of seconds to wait before writing behind. If set to a value greater than 0, it permits operations to build up in the queue. This is different from the maximum write delay in that by waiting a minimum amount of time, work is always being built up. If the minimum write delay is set to zero and theCacheWriterperforms its work very quickly, the overhead of processing the write behind queue items becomes very noticeable in a cluster since all the operations might be done for individual items instead of for a collection of them.This is only applicable to write behind mode.
Defaults to 1).
- Parameters:
minWriteDelay- the minimum number of seconds to wait before writing behind
-
minWriteDelay
public CacheWriterConfiguration minWriteDelay(int minWriteDelay)
- Returns:
- this configuration instance
- See Also:
setMinWriteDelay(int)
-
getMinWriteDelay
public int getMinWriteDelay()
Get the minimum number of seconds to wait before writing behind
-
setMaxWriteDelay
public void setMaxWriteDelay(int maxWriteDelay)
Set the maximum number of seconds to wait before writing behind. If set to a value greater than 0, it permits operations to build up in the queue to enable effective coalescing and batching optimisations.This is only applicable to write behind mode.
Defaults to 1).
- Parameters:
maxWriteDelay- the maximum number of seconds to wait before writing behind
-
maxWriteDelay
public CacheWriterConfiguration maxWriteDelay(int maxWriteDelay)
- Returns:
- this configuration instance
- See Also:
setMaxWriteDelay(int)
-
getMaxWriteDelay
public int getMaxWriteDelay()
Get the maximum number of seconds to wait before writing behind
-
setRateLimitPerSecond
public void setRateLimitPerSecond(int rateLimitPerSecond)
Sets the maximum number of write operations to allow per second whenwriteBatchingis enabled.This is only applicable to write behind mode.
Defaults to 0.
- Parameters:
rateLimitPerSecond- the number of write operations to allow; use a number<=0to disable rate limiting.
-
rateLimitPerSecond
public CacheWriterConfiguration rateLimitPerSecond(int rateLimitPerSecond)
- Returns:
- this configuration instance
- See Also:
setRateLimitPerSecond(int rateLimitPerSecond)
-
getRateLimitPerSecond
public int getRateLimitPerSecond()
Get the maximum number of write operations to allow per second.
-
setWriteCoalescing
public void setWriteCoalescing(boolean writeCoalescing)
Sets whether to use write coalescing. If set totrueand multiple operations on the same key are present in the write-behind queue, only the latest write is done, as the others are redundant. This can dramatically reduce load on the underlying resource.This is only applicable to write behind mode.
Defaults to false.
- Parameters:
writeCoalescing-trueto enable write coalescing; orfalseto disable it
-
writeCoalescing
public CacheWriterConfiguration writeCoalescing(boolean writeCoalescing)
- Returns:
- this configuration instance
- See Also:
setWriteCoalescing(boolean)
-
getWriteCoalescing
public boolean getWriteCoalescing()
- Returns:
- this configuration instance
- See Also:
setWriteCoalescing(boolean)
-
setWriteBatching
public void setWriteBatching(boolean writeBatching)
Sets whether to batch write operations. If set totrue,CacheWriter.writeAll(java.util.Collection<net.sf.ehcache.Element>)andCacheWriter#deleteAllwill be called rather thanCacheWriter.write(net.sf.ehcache.Element)andCacheWriter.delete(net.sf.ehcache.CacheEntry)being called for each key. Resources such as databases can perform more efficiently if updates are batched, thus reducing load.This is only applicable to write behind mode.
Defaults to false.
- Parameters:
writeBatching-trueif write operations should be batched;falseotherwise
-
writeBatching
public CacheWriterConfiguration writeBatching(boolean writeBatching)
- Returns:
- this configuration instance
- See Also:
setWriteBatching(boolean)
-
getWriteBatching
public boolean getWriteBatching()
Check whether write operations should be batched
-
setWriteBatchSize
public void setWriteBatchSize(int writeBatchSize)
Sets the number of operations to include in each batch whenwriteBatchingis enabled. If there are less entries in the write-behind queue than the batch size, the queue length size is used.This is only applicable to write behind mode.
Defaults to 1.
- Parameters:
writeBatchSize- the number of operations to include in each batch; numbers smaller than1will cause the default batch size to be used
-
writeBatchSize
public CacheWriterConfiguration writeBatchSize(int writeBatchSize)
- Returns:
- this configuration instance
- See Also:
setWriteBatchSize(int)
-
getWriteBatchSize
public int getWriteBatchSize()
Retrieves the size of the batch operation.
-
setRetryAttempts
public void setRetryAttempts(int retryAttempts)
Sets the number of times the operation is retried in theCacheWriter, this happens after the original operation.This is only applicable to write behind mode.
Defaults to 0.
- Parameters:
retryAttempts- the number of retries for a particular element
-
retryAttempts
public CacheWriterConfiguration retryAttempts(int retryAttempts)
- Returns:
- this configuration instance
- See Also:
setRetryAttempts(int)
-
getRetryAttempts
public int getRetryAttempts()
Retrieves the number of times the write of element is retried.
-
setRetryAttemptDelaySeconds
public void setRetryAttemptDelaySeconds(int retryAttemptDelaySeconds)
Sets the number of seconds to wait before retrying an failed operation.This is only applicable to write behind mode.
Defaults to 1.
- Parameters:
retryAttemptDelaySeconds- the number of seconds to wait before retrying an operation
-
retryAttemptDelaySeconds
public CacheWriterConfiguration retryAttemptDelaySeconds(int retryAttemptDelaySeconds)
- Returns:
- this configuration instance
- See Also:
setRetryAttemptDelaySeconds(int)
-
getRetryAttemptDelaySeconds
public int getRetryAttemptDelaySeconds()
Retrieves the number of seconds to wait before retrying an failed operation.
-
addCacheWriterFactory
public final void addCacheWriterFactory(CacheWriterConfiguration.CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration)
Allows BeanHandler to add the CacheWriterFactory to the configuration.
-
cacheWriterFactory
public CacheWriterConfiguration cacheWriterFactory(CacheWriterConfiguration.CacheWriterFactoryConfiguration cacheWriterFactory)
- Returns:
- this configuration instance
- See Also:
addCacheWriterFactory(CacheWriterFactoryConfiguration)
-
getCacheWriterFactoryConfiguration
public CacheWriterConfiguration.CacheWriterFactoryConfiguration getCacheWriterFactoryConfiguration()
Accessor- Returns:
- the configuration
-
setWriteBehindConcurrency
public void setWriteBehindConcurrency(int concurrency)
Configures the amount of thread/bucket pairs WriteBehind should use- Parameters:
concurrency- Amount of thread/bucket pairs, has to be at least 1
-
writeBehindConcurrency
public CacheWriterConfiguration writeBehindConcurrency(int concurrency)
- Parameters:
concurrency- Amount of thread/bucket pairs, has to be at least 1- Returns:
- this configuration instance
- See Also:
setWriteBehindConcurrency(int)
-
getWriteBehindConcurrency
public int getWriteBehindConcurrency()
Accessor- Returns:
- the amount of bucket/thread pairs configured for this cache's write behind
-
setWriteBehindMaxQueueSize
public void setWriteBehindMaxQueueSize(int writeBehindMaxQueueSize)
Configures the maximum amount of operations to be on the waiting queue, before it blocks- Parameters:
writeBehindMaxQueueSize- maximum amount of operations allowed on the waiting queue
-
getWriteBehindMaxQueueSize
public int getWriteBehindMaxQueueSize()
Accessor- Returns:
- the maximum amount of operations allowed on the write behind queue
-
writeBehindMaxQueueSize
public CacheWriterConfiguration writeBehindMaxQueueSize(int writeBehindMaxQueueSize)
- Parameters:
writeBehindMaxQueueSize- maximum amount of operations allowed on the waiting queue- Returns:
- this configuration instance
- See Also:
setWriteBehindMaxQueueSize(int)
-
hashCode
public int hashCode()
Overrided hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Overrided equals()- Overrides:
equalsin classjava.lang.Object
-
validate
public void validate(java.util.Collection<ConfigError> errors)
Check for errors/inconsistencies in this configuration. Add any erros found asConfigErrorin the errors collection.- Parameters:
errors- collection to add errors to.
-
-