Top Description Constructors Methods
net.sf.ehcache.writer

public abstract Class AbstractCacheWriter

extends Object
implements CacheWriter
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.writer.CacheWriter
Imports
net.sf.ehcache.CacheEntry, .CacheException, .Ehcache, .Element, net.sf.ehcache.writer.writebehind.operations.SingleOperationType, java.util.Collection

A convenience abstract base class that implements all CacheWriter methods.

The write, writeAll, delete and deleteAll methods throw UnsupportedOperationException unless they're overridden by the class that is extending AbstractCacheWriter. Classes that are extending this abstract base class should make sure that the appropriate cache writer operation methods are implemented with their application functionalities.

Author
Geert Bevin
Version
$Id: AbstractCacheWriter.java 10789 2018-04-26 02:08:13Z adahanne $

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CacheWriter
clone(Ehcache cache)

Implements net.sf.ehcache.writer.CacheWriter.clone.

Creates a clone of this writer.
public void
delete(CacheEntry
the cache entry that is used for the delete operation
entry
)

Implements net.sf.ehcache.writer.CacheWriter.delete.

Delete the cache entry from the store
public void
deleteAll(Collection<CacheEntry>
the entries that have been removed from the cache
entries
)

Implements net.sf.ehcache.writer.CacheWriter.deleteAll.

Remove data and keys from the underlying store for the given collection of keys, if present.
public void
dispose()

Implements net.sf.ehcache.writer.CacheWriter.dispose.

Providers may be doing all sorts of exotic things and need to be able to clean up on dispose.
public void
init()

Implements net.sf.ehcache.writer.CacheWriter.init.

Notifies writer to initialise themselves.
public void
throwAway(final Element
the Element that triggered the failure, or one of the elements part of the batch that failed
element
,
final SingleOperationType
the operation we tried to execute
operationType
,
final RuntimeException
the RuntimeException thrown by the Writer when the last retry attempt was being executed
e
)

Implements net.sf.ehcache.writer.CacheWriter.throwAway.

This method will be called, whenever an Element couldn't be handled by the writer and all the retryAttempts have been tried.
public void
write(Element
the element to be written
element
)

Implements net.sf.ehcache.writer.CacheWriter.write.

Write the specified value under the specified key to the underlying store.
public void
writeAll(Collection<Element>
the Elements to be written
elements
)

Implements net.sf.ehcache.writer.CacheWriter.writeAll.

Write the specified Elements to the underlying store.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AbstractCacheWriterback to summary
public AbstractCacheWriter()

Method Detail

cloneback to summary
public CacheWriter clone(Ehcache cache) throws CloneNotSupportedException

Implements net.sf.ehcache.writer.CacheWriter.clone.

Doc from net.sf.ehcache.writer.CacheWriter.clone.

Creates a clone of this writer. This method will only be called by ehcache before a cache is initialized.

Implementations should throw CloneNotSupportedException if they do not support clone but that will stop them from being used with defaultCache.

Returns:CacheWriter

a clone

Exceptions
CloneNotSupportedException:
if the extension could not be cloned.
deleteback to summary
public void delete(CacheEntry entry) throws CacheException

Implements net.sf.ehcache.writer.CacheWriter.delete.

Doc from net.sf.ehcache.writer.CacheWriter.delete.

Delete the cache entry from the store

Parameters
entry:CacheEntry

the cache entry that is used for the delete operation

deleteAllback to summary
public void deleteAll(Collection<CacheEntry> entries) throws CacheException

Implements net.sf.ehcache.writer.CacheWriter.deleteAll.

Doc from net.sf.ehcache.writer.CacheWriter.deleteAll.

Remove data and keys from the underlying store for the given collection of keys, if present. If this operation fails (by throwing an exception) after a partial success, the convention is that keys which have been erased successfully are to be removed from the specified keys, indicating that the erase operation for the keys left in the collection has failed or has not been attempted.

Parameters
entries:Collection<CacheEntry>

the entries that have been removed from the cache

disposeback to summary
public void dispose() throws CacheException

Implements net.sf.ehcache.writer.CacheWriter.dispose.

Doc from net.sf.ehcache.writer.CacheWriter.dispose.

Providers may be doing all sorts of exotic things and need to be able to clean up on dispose.

Cache operations are illegal when this method is called. The cache itself is partly disposed when this method is called.

initback to summary
public void init()

Implements net.sf.ehcache.writer.CacheWriter.init.

Doc from net.sf.ehcache.writer.CacheWriter.init.

Notifies writer to initialise themselves.

This method is called during the Cache's initialise method after it has changed it's status to alive. Cache operations are legal in this method. If you register a cache writer manually after a cache has been initialised already, this method will be called on the cache writer as soon as it has been registered.

Note that if you reuse cache writer instances or create a factory that returns the same cache writer instance as a singleton, your init method should be able to handle that situation. Unless you perform this multiple usage of a cache writer yourself, Ehcache will not do this though. So in the majority of the use cases, you don't need to do anything special.

throwAwayback to summary
public void throwAway(final Element element, final SingleOperationType operationType, final RuntimeException e)

Implements net.sf.ehcache.writer.CacheWriter.throwAway.

Doc from net.sf.ehcache.writer.CacheWriter.throwAway.

This method will be called, whenever an Element couldn't be handled by the writer and all the retryAttempts have been tried.

When batching is enabled all the elements in the failing batch will be passed to this methods

Try to not throw RuntimeExceptions from this method. Should an Exception occur, it will be logged, but the element will be lost anyways.

Parameters
element:Element

the Element that triggered the failure, or one of the elements part of the batch that failed

operationType:SingleOperationType

the operation we tried to execute

e:RuntimeException

the RuntimeException thrown by the Writer when the last retry attempt was being executed

writeback to summary
public void write(Element element) throws CacheException

Implements net.sf.ehcache.writer.CacheWriter.write.

Doc from net.sf.ehcache.writer.CacheWriter.write.

Write the specified value under the specified key to the underlying store. This method is intended to support both key/value creation and value update for a specific key.

Parameters
element:Element

the element to be written

writeAllback to summary
public void writeAll(Collection<Element> elements) throws CacheException

Implements net.sf.ehcache.writer.CacheWriter.writeAll.

Doc from net.sf.ehcache.writer.CacheWriter.writeAll.

Write the specified Elements to the underlying store. This method is intended to support both insert and update. If this operation fails (by throwing an exception) after a partial success, the convention is that entries which have been written successfully are to be removed from the specified mapEntries, indicating that the write operation for the entries left in the map has failed or has not been attempted.

Parameters
elements:Collection<Element>

the Elements to be written