org.ehcache.impl.internal.loaderwriter.writebehind
Class NonBatchingLocalHeapWriteBehindQueue<K,V>

java.lang.Object
  extended by org.ehcache.impl.internal.loaderwriter.writebehind.NonBatchingLocalHeapWriteBehindQueue<K,V>
All Implemented Interfaces:
WriteBehind<K,V>, CacheLoaderWriter<K,V>

public class NonBatchingLocalHeapWriteBehindQueue<K,V>
extends java.lang.Object


Constructor Summary
NonBatchingLocalHeapWriteBehindQueue(ExecutionService executionService, java.lang.String defaultThreadPool, WriteBehindConfiguration config, CacheLoaderWriter<K,V> cacheLoaderWriter)
           
 
Method Summary
protected  void addOperation(SingleOperation<K,V> operation)
           
 void delete(K key)
          Deletes a single entry from the underlying system of record.
 void deleteAll(java.lang.Iterable<? extends K> keys)
          Deletes a set of entry from the underlying system of record.
protected  SingleOperation<K,V> getOperation(K key)
           
 long getQueueSize()
          Gets the best estimate for items in the queue still awaiting processing.
 V load(K key)
          Loads the value to be associated with the given key in the Cache using this CacheLoaderWriter instance.
 java.util.Map<K,V> loadAll(java.lang.Iterable<? extends K> keys)
          Loads the values to be associated with the keys in the Cache using this CacheLoaderWriter instance.
protected static
<T> void
putUninterruptibly(java.util.concurrent.BlockingQueue<T> queue, T r)
           
 void start()
          Start the write behind queue
 void stop()
          Stop the coordinator and all the internal data structures.
 void write(K key, V value)
          Writes a single entry to the underlying system of record, maybe a brand new value or an update to an existing value
 void writeAll(java.lang.Iterable<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
          Writes multiple entries to the underlying system of record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonBatchingLocalHeapWriteBehindQueue

public NonBatchingLocalHeapWriteBehindQueue(ExecutionService executionService,
                                            java.lang.String defaultThreadPool,
                                            WriteBehindConfiguration config,
                                            CacheLoaderWriter<K,V> cacheLoaderWriter)
Method Detail

getOperation

protected SingleOperation<K,V> getOperation(K key)

addOperation

protected void addOperation(SingleOperation<K,V> operation)

start

public void start()
Description copied from interface: WriteBehind
Start the write behind queue


stop

public void stop()
Description copied from interface: WriteBehind
Stop the coordinator and all the internal data structures.

This stops as quickly as possible without losing any previously added items. However, no guarantees are made towards the processing of these items. It's highly likely that items are still inside the internal data structures and not processed.


getQueueSize

public long getQueueSize()
Description copied from interface: WriteBehind
Gets the best estimate for items in the queue still awaiting processing.

Returns:
the amount of elements still awaiting processing.

load

public V load(K key)
       throws java.lang.Exception
Description copied from interface: CacheLoaderWriter
Loads the value to be associated with the given key in the Cache using this CacheLoaderWriter instance.

Specified by:
load in interface CacheLoaderWriter<K,V>
Parameters:
key - the key that will map to the value returned
Returns:
the value to be mapped
Throws:
java.lang.Exception - if the value cannot be loaded

loadAll

public java.util.Map<K,V> loadAll(java.lang.Iterable<? extends K> keys)
                           throws java.lang.Exception
Description copied from interface: CacheLoaderWriter
Loads the values to be associated with the keys in the Cache using this CacheLoaderWriter instance. The returned Map should contain null mapped keys for values that couldn't be found.
The mapping that will be installed in the cache is the key as found in the input parameter keys mapped to the result of loadAllResult.get(key). Any other mapping will be ignored.

Specified by:
loadAll in interface CacheLoaderWriter<K,V>
Parameters:
keys - the keys that will be mapped to the values returned in the map
Returns:
the Map of values for each key passed in, where no mapping means no value to map.
Throws:
BulkCacheLoadingException - This writer must throw this exception to indicate partial success. The exception declares which keys were actually loaded (if any)
java.lang.Exception - a generic failure. All values will be considered not loaded in this case

write

public void write(K key,
                  V value)
           throws CacheWritingException
Description copied from interface: CacheLoaderWriter
Writes a single entry to the underlying system of record, maybe a brand new value or an update to an existing value

Specified by:
write in interface CacheLoaderWriter<K,V>
Parameters:
key - the key of the mapping being installed or updated
value - the actual value being updated
Throws:
CacheWritingException
See Also:
Cache.put(Object, Object)

writeAll

public void writeAll(java.lang.Iterable<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
              throws BulkCacheWritingException,
                     java.lang.Exception
Description copied from interface: CacheLoaderWriter
Writes multiple entries to the underlying system of record. These can either be new entries or updates to existing ones. It is legal for this method to result in "partial success" where some subset of the entries are written. In this case a BulkCacheWritingException must be thrown (see below)

Specified by:
writeAll in interface CacheLoaderWriter<K,V>
Parameters:
entries - the key to value mappings
Throws:
BulkCacheWritingException - This writer must throw this exception to indicate partial success. The exception declares which keys were actually written (if any)
java.lang.Exception - a generic failure. All entries will be considered not written in this case
See Also:
Cache.putAll(java.util.Map)

delete

public void delete(K key)
            throws CacheWritingException
Description copied from interface: CacheLoaderWriter
Deletes a single entry from the underlying system of record.

Specified by:
delete in interface CacheLoaderWriter<K,V>
Parameters:
key - the key to delete
Throws:
CacheWritingException
See Also:
Cache.remove(Object)

deleteAll

public void deleteAll(java.lang.Iterable<? extends K> keys)
               throws BulkCacheWritingException,
                      java.lang.Exception
Description copied from interface: CacheLoaderWriter
Deletes a set of entry from the underlying system of record. It is legal for this method to result in "partial success" where some subset of the keys are deleted. In this case a BulkCacheWritingException must be thrown (see below)

Specified by:
deleteAll in interface CacheLoaderWriter<K,V>
Parameters:
keys - the keys to delete
Throws:
BulkCacheWritingException - This writer must throw this exception to indicate partial success. The exception declares which keys were actually deleted (if any)
java.lang.Exception - a generic failure. All entries will be considered not deleted in this case
See Also:
Cache.removeAll(java.util.Set)

putUninterruptibly

protected static <T> void putUninterruptibly(java.util.concurrent.BlockingQueue<T> queue,
                                             T r)