org.terracotta.modules.ehcache.writebehind
Class CacheWriterWrapper

java.lang.Object
  extended by org.terracotta.modules.ehcache.writebehind.CacheWriterWrapper
All Implemented Interfaces:
ItemProcessor<SingleAsyncOperation>

public class CacheWriterWrapper
extends Object
implements ItemProcessor<SingleAsyncOperation>

An implementation of ItemProcessor that delegates the processing to a CacheWriter instance

Instances of this class will be used when items are processed one by one. Note that CacheWriter instances will not be shared across a Terracotta DSO cluster and are intended to be local on a node. They are tied to an individual write behind queue. You're thus free to use local resources in an CacheWriter, like database connections or file handles.

Version:
$Id: CacheWriterWrapper.java 23027 2010-05-21 14:24:50Z hhuynh $
Author:
Geert Bevin

Constructor Summary
CacheWriterWrapper(net.sf.ehcache.writer.CacheWriter cacheWriter, SerializationStrategy serializationStrategy)
          Creates a new item processor for a specific cache writer.
 
Method Summary
 void process(Collection<SingleAsyncOperation> items)
          This method is called from within ProcessingBucket when enqueued items are processed int batch.
 void process(SingleAsyncOperation operation)
          This method is called from within ProcessingBucket when enqueued items are processed one by one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheWriterWrapper

public CacheWriterWrapper(net.sf.ehcache.writer.CacheWriter cacheWriter,
                          SerializationStrategy serializationStrategy)
Creates a new item processor for a specific cache writer.

Parameters:
cacheWriter - the cache writer for which the wrapper has to be created
serializationStrategy - the strategy that should be used to serialize and deserialize, if needed
Method Detail

process

public void process(SingleAsyncOperation operation)
Description copied from interface: ItemProcessor
This method is called from within ProcessingBucket when enqueued items are processed one by one.

When this process method finishes, the corresponding item will be definitively removed from the bucket. Note that while the item removal is transactional and your implementation of the process method can be done in a transactional fashion, they are not transactional together. It is thus possible that your ItemProcessor succeeds and that the node goes down before the item is actually removed from the bucket. Your ItemProcessor thus might have to be implemented with some form of bookkeeping that is able to detect that a certain item has already been processed. This can for example be a check on a unique item identifier that is allocated before starting the actual processing of a new item.

Specified by:
process in interface ItemProcessor<SingleAsyncOperation>
Parameters:
operation - the item that has to be processed

process

public void process(Collection<SingleAsyncOperation> items)
Description copied from interface: ItemProcessor
This method is called from within ProcessingBucket when enqueued items are processed int batch.

All documentation from the ItemProcessor.process(Object) method also applies here.

Specified by:
process in interface ItemProcessor<SingleAsyncOperation>
Parameters:
items - the items that have to be processed


Copyright © 2010 Terracotta, Inc.. All Rights Reserved.