ehcache

net.sf.ehcache.config
Class CacheWriterConfiguration

java.lang.Object
  extended by net.sf.ehcache.config.CacheWriterConfiguration
All Implemented Interfaces:
Cloneable

public class CacheWriterConfiguration
extends Object
implements Cloneable

Class to hold the CacheWriterManager configuration

Version:
$Id: CacheWriterConfiguration.java 7406 2013-04-23 22:04:53Z cdennis $
Author:
Geert Bevin

Nested Class Summary
static class CacheWriterConfiguration.CacheWriterFactoryConfiguration
          Configuration for the CacheWriterFactoryConfiguration.
static class CacheWriterConfiguration.WriteMode
          Represents how elements are written to the CacheWriter
 
Field Summary
static int DEFAULT_MAX_WRITE_DELAY
          Default maximum write delay
static int DEFAULT_MIN_WRITE_DELAY
          Default minimum write delay
static boolean DEFAULT_NOTIFY_LISTENERS_ON_EXCEPTION
          Default notifyListenersOnException behavior
static int DEFAULT_RATE_LIMIT_PER_SECOND
          Default rate limit per second
static int DEFAULT_RETRY_ATTEMPT_DELAY_SECONDS
          Default retry attempt delay
static int DEFAULT_RETRY_ATTEMPTS
          Default retry attempts
static int DEFAULT_WRITE_BATCH_SIZE
          Default write batch size
static boolean DEFAULT_WRITE_BATCHING
          Default writeBatching behavior
static int DEFAULT_WRITE_BEHIND_CONCURRENCY
          Default concurrency level for write behind
static int DEFAULT_WRITE_BEHIND_MAX_QUEUE_SIZE
          Default max queue size for write behind
static boolean DEFAULT_WRITE_COALESCING
          Default write coalescing behavior
static CacheWriterConfiguration.WriteMode DEFAULT_WRITE_MODE
          Default writeMode
 
Constructor Summary
CacheWriterConfiguration()
           
 
Method Summary
 void addCacheWriterFactory(CacheWriterConfiguration.CacheWriterFactoryConfiguration cacheWriterFactoryConfiguration)
          Allows BeanHandler to add the CacheWriterFactory to the configuration.
 CacheWriterConfiguration cacheWriterFactory(CacheWriterConfiguration.CacheWriterFactoryConfiguration cacheWriterFactory)
           
 CacheWriterConfiguration clone()
          Clones this object, following the usual contract.
 boolean equals(Object obj)
          Overrided equals()
 CacheWriterConfiguration.CacheWriterFactoryConfiguration getCacheWriterFactoryConfiguration()
          Accessor
 int getMaxWriteDelay()
          Get the maximum number of seconds to wait before writing behind
 int getMinWriteDelay()
          Get the minimum number of seconds to wait before writing behind
 boolean getNotifyListenersOnException()
          Check whether listeners should be notified when an exception occurs on a writer operation
 int getRateLimitPerSecond()
          Get the maximum number of write operations to allow per second.
 int getRetryAttemptDelaySeconds()
          Retrieves the number of seconds to wait before retrying an failed operation.
 int getRetryAttempts()
          Retrieves the number of times the write of element is retried.
 boolean getWriteBatching()
          Check whether write operations should be batched
 int getWriteBatchSize()
          Retrieves the size of the batch operation.
 int getWriteBehindConcurrency()
          Accessor
 int getWriteBehindMaxQueueSize()
          Accessor
 boolean getWriteCoalescing()
           
 CacheWriterConfiguration.WriteMode getWriteMode()
          Get the write mode in terms of the mode enum
 int hashCode()
          Overrided hashCode()
 CacheWriterConfiguration maxWriteDelay(int maxWriteDelay)
           
 CacheWriterConfiguration minWriteDelay(int minWriteDelay)
           
 CacheWriterConfiguration notifyListenersOnException(boolean notifyListenersOnException)
           
 CacheWriterConfiguration rateLimitPerSecond(int rateLimitPerSecond)
           
 CacheWriterConfiguration retryAttemptDelaySeconds(int retryAttemptDelaySeconds)
           
 CacheWriterConfiguration retryAttempts(int retryAttempts)
           
 void setMaxWriteDelay(int maxWriteDelay)
          Set the maximum number of seconds to wait before writing behind.
 void setMinWriteDelay(int minWriteDelay)
          Set the minimum number of seconds to wait before writing behind.
 void setNotifyListenersOnException(boolean notifyListenersOnException)
          Sets whether to notify listeners when an exception occurs on a writer operation.
 void setRateLimitPerSecond(int rateLimitPerSecond)
          Sets the maximum number of write operations to allow per second when writeBatching is enabled.
 void setRetryAttemptDelaySeconds(int retryAttemptDelaySeconds)
          Sets the number of seconds to wait before retrying an failed operation.
 void setRetryAttempts(int retryAttempts)
          Sets the number of times the operation is retried in the CacheWriter, this happens after the original operation.
 void setWriteBatching(boolean writeBatching)
          Sets whether to batch write operations.
 void setWriteBatchSize(int writeBatchSize)
          Sets the number of operations to include in each batch when writeBatching is enabled.
 void setWriteBehindConcurrency(int concurrency)
          Configures the amount of thread/bucket pairs WriteBehind should use
 void setWriteBehindMaxQueueSize(int writeBehindMaxQueueSize)
          Configures the maximum amount of operations to be on the waiting queue, before it blocks
 void setWriteCoalescing(boolean writeCoalescing)
          Sets whether to use write coalescing.
 void setWriteMode(String writeMode)
          Converts the writeMode string argument to uppercase and looks up enum constant in WriteMode.
 void validate(Collection<ConfigError> errors)
          Check for errors/inconsistencies in this configuration.
 CacheWriterConfiguration writeBatching(boolean writeBatching)
           
 CacheWriterConfiguration writeBatchSize(int writeBatchSize)
           
 CacheWriterConfiguration writeBehindConcurrency(int concurrency)
           
 CacheWriterConfiguration writeBehindMaxQueueSize(int writeBehindMaxQueueSize)
           
 CacheWriterConfiguration writeCoalescing(boolean writeCoalescing)
           
 CacheWriterConfiguration writeMode(CacheWriterConfiguration.WriteMode writeMode)
           
 CacheWriterConfiguration writeMode(String writeMode)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

CacheWriterConfiguration

public CacheWriterConfiguration()
Method Detail

clone

public CacheWriterConfiguration clone()
Clones this object, following the usual contract.

Overrides:
clone in class Object
Returns:
a copy, which independent other than configurations than cannot change.

setWriteMode

public void setWriteMode(String writeMode)
Converts the writeMode string argument to uppercase and looks up enum constant in WriteMode.


writeMode

public CacheWriterConfiguration writeMode(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 - true if listeners should be notified when an exception occurs on a writer operation; false otherwise

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 the CacheWriter performs 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 when writeBatching is enabled.

This is only applicable to write behind mode.

Defaults to 0.

Parameters:
rateLimitPerSecond - the number of write operations to allow; use a number &lt;=0 to 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 to true and 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 - true to enable write coalescing; or false to 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 to true, CacheWriter.writeAll(java.util.Collection) and CacheWriter#deleteAll will be called rather than CacheWriter.write(net.sf.ehcache.Element) and CacheWriter.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 - true if write operations should be batched; false otherwise

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 when writeBatching is 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 than 1 will 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 the CacheWriter, 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:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrided equals()

Overrides:
equals in class Object

validate

public void validate(Collection<ConfigError> errors)
Check for errors/inconsistencies in this configuration. Add any erros found as ConfigError in the errors collection.

Parameters:
errors - collection to add errors to.

ehcache

Copyright 2001-2016, Terracotta, Inc.