Infinispan Distribution 5.2.6.Final-redhat-2

org.infinispan.loaders.decorators
Class AsyncStore

java.lang.Object
  extended by org.infinispan.loaders.decorators.AbstractDelegatingStore
      extended by org.infinispan.loaders.decorators.AsyncStore
All Implemented Interfaces:
CacheLoader, CacheStore

public class AsyncStore
extends AbstractDelegatingStore

The AsyncStore is a delegating CacheStore that buffers changes and writes them asynchronously to the underlying CacheStore.

Read operations are done synchronously, taking into account the current state of buffered changes.

There is no provision for exception handling for problems encountered with the underlying store during a write operation, and the exception is just logged.

When configuring the loader, use the following element:

<async enabled="true" />

to define whether cache loader operations are to be asynchronous. If not specified, a cache loader operation is assumed synchronous and this decorator is not applied.

Write operations affecting same key are now coalesced so that only the final state is actually stored.

Since:
4.0
Author:
Manik Surtani, Galder ZamarreƱo, Sanne Grinovero, Karsten Blees

Constructor Summary
AsyncStore(CacheStore delegate, AsyncStoreConfig asyncStoreConfig)
           
 
Method Summary
protected  void applyModificationsSync(List<Modification> mods)
           
 void clear()
          Clears all entries in the store
 void commit(GlobalTransaction tx)
          Commits a transaction that has been previously prepared.
 boolean containsKey(Object key)
           
 void init(CacheLoaderConfig config, Cache<?,?> cache, StreamingMarshaller m)
          Used to initialize a cache loader.
 Set<InternalCacheEntry> load(int numEntries)
          Loads up to a specific number of entries.
 InternalCacheEntry load(Object key)
          Loads an entry mapped to by a given key.
 Set<InternalCacheEntry> loadAll()
          Loads all entries in the loader.
 Set<Object> loadAllKeys(Set<Object> keysToExclude)
          Loads a set of all keys, excluding a filter set.
 void prepare(List<? extends Modification> mods, GlobalTransaction tx, boolean isOnePhase)
          Issues a prepare call with a set of modifications to be applied to the cache store
 boolean remove(Object key)
          Removes an entry in the store.
 void removeAll(Set<Object> keys)
          Bulk remove operation
 void rollback(GlobalTransaction tx)
          Rolls back a transaction that has been previously prepared

This method may be invoked on a transaction for which there is no prior CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean).

 void start()
           
 void stop()
           
 void store(InternalCacheEntry entry)
          Stores an entry
 
Methods inherited from class org.infinispan.loaders.decorators.AbstractDelegatingStore
fromStream, getCacheStoreConfig, getConfigurationClass, getDelegate, purgeExpired, setDelegate, toStream, undelegateCacheLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncStore

public AsyncStore(CacheStore delegate,
                  AsyncStoreConfig asyncStoreConfig)
Method Detail

init

public void init(CacheLoaderConfig config,
                 Cache<?,?> cache,
                 StreamingMarshaller m)
          throws CacheLoaderException
Description copied from interface: CacheLoader
Used to initialize a cache loader. Typically invoked by the CacheLoaderManager when setting up cache loaders.

Specified by:
init in interface CacheLoader
Overrides:
init in class AbstractDelegatingStore
Parameters:
config - the cache loader configuration bean
cache - cache associated with this cache loader. Implementations may use this to determine cache name when selecting where refer to state in storage, for example, a different database table name.
m - marshaller to use when loading state from a stream, if supported by the implementation.
Throws:
CacheLoaderException

load

public InternalCacheEntry load(Object key)
                        throws CacheLoaderException
Description copied from interface: CacheLoader
Loads an entry mapped to by a given key. Should return null if the entry does not exist. Expired entries are not returned.

Specified by:
load in interface CacheLoader
Overrides:
load in class AbstractDelegatingStore
Parameters:
key - key
Returns:
an entry
Throws:
CacheLoaderException - in the event of problems reading from source

containsKey

public boolean containsKey(Object key)
                    throws CacheLoaderException
Specified by:
containsKey in interface CacheLoader
Overrides:
containsKey in class AbstractDelegatingStore
Parameters:
key - key to test
Returns:
true if the key exists, false otherwise
Throws:
CacheLoaderException - in the event of problems reading from source

loadAllKeys

public Set<Object> loadAllKeys(Set<Object> keysToExclude)
                        throws CacheLoaderException
Description copied from interface: CacheLoader
Loads a set of all keys, excluding a filter set.

Specified by:
loadAllKeys in interface CacheLoader
Overrides:
loadAllKeys in class AbstractDelegatingStore
Parameters:
keysToExclude - a set of keys to exclude. An empty set or null will indicate that all keys should be returned.
Returns:
A set containing keys of entries stored. An empty set is returned if the loader is empty.
Throws:
CacheLoaderException

loadAll

public Set<InternalCacheEntry> loadAll()
                                throws CacheLoaderException
Description copied from interface: CacheLoader
Loads all entries in the loader. Expired entries are not returned.

Specified by:
loadAll in interface CacheLoader
Overrides:
loadAll in class AbstractDelegatingStore
Returns:
a set of entries, or an empty set if the loader is emptied.
Throws:
CacheLoaderException - in the event of problems reading from source

load

public Set<InternalCacheEntry> load(int numEntries)
                             throws CacheLoaderException
Description copied from interface: CacheLoader
Loads up to a specific number of entries. There is no guarantee as to order of entries loaded. The set returned would contain up to a maximum of numEntries entries, and no more.

Specified by:
load in interface CacheLoader
Overrides:
load in class AbstractDelegatingStore
Parameters:
numEntries - maximum number of entries to load
Returns:
a set of entries, which would contain between 0 and numEntries entries.
Throws:
CacheLoaderException

store

public void store(InternalCacheEntry entry)
Description copied from interface: CacheStore
Stores an entry

Specified by:
store in interface CacheStore
Overrides:
store in class AbstractDelegatingStore
Parameters:
entry - entry to store

clear

public void clear()
Description copied from interface: CacheStore
Clears all entries in the store

Specified by:
clear in interface CacheStore
Overrides:
clear in class AbstractDelegatingStore

remove

public boolean remove(Object key)
Description copied from interface: CacheStore
Removes an entry in the store.

Specified by:
remove in interface CacheStore
Overrides:
remove in class AbstractDelegatingStore
Parameters:
key - key to remove
Returns:
true if the entry was removed; false if the entry wasn't found.

removeAll

public void removeAll(Set<Object> keys)
               throws CacheLoaderException
Description copied from interface: CacheStore
Bulk remove operation

Specified by:
removeAll in interface CacheStore
Overrides:
removeAll in class AbstractDelegatingStore
Parameters:
keys - to remove
Throws:
CacheLoaderException - in the event of problems writing to the store

prepare

public void prepare(List<? extends Modification> mods,
                    GlobalTransaction tx,
                    boolean isOnePhase)
             throws CacheLoaderException
Description copied from interface: CacheStore
Issues a prepare call with a set of modifications to be applied to the cache store

Specified by:
prepare in interface CacheStore
Overrides:
prepare in class AbstractDelegatingStore
Parameters:
mods - modifications to be applied
tx - transaction identifier
isOnePhase - if true, there will not be a commit or rollback phase and changes should be flushed immediately
Throws:
CacheLoaderException - in the event of problems writing to the store

rollback

public void rollback(GlobalTransaction tx)
Description copied from interface: CacheStore
Rolls back a transaction that has been previously prepared

This method may be invoked on a transaction for which there is no prior CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean). The implementation would need to deal with this case accordingly. Typically, this would be a no-op, after ensuring any resources attached to the transaction are cleared up.

Also note that this method may be invoked on a thread which is different from the CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean) invocation. As such, ThreadLocals should not be relied upon to maintain transaction context.

Specified by:
rollback in interface CacheStore
Overrides:
rollback in class AbstractDelegatingStore
Parameters:
tx - tx to roll back

commit

public void commit(GlobalTransaction tx)
            throws CacheLoaderException
Description copied from interface: CacheStore
Commits a transaction that has been previously prepared.

This method may be invoked on a transaction for which there is no prior CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean). The implementation would need to deal with this case accordingly. Typically, this would be a no-op, after ensuring any resources attached to the transaction are cleared up.

Also note that this method may be invoked on a thread which is different from the CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean) invocation. As such, ThreadLocals should not be relied upon to maintain transaction context.

Specified by:
commit in interface CacheStore
Overrides:
commit in class AbstractDelegatingStore
Parameters:
tx - tx to commit
Throws:
CacheLoaderException - in the event of problems writing to the store

start

public void start()
           throws CacheLoaderException
Specified by:
start in interface CacheLoader
Overrides:
start in class AbstractDelegatingStore
Throws:
CacheLoaderException

stop

public void stop()
          throws CacheLoaderException
Specified by:
stop in interface CacheLoader
Overrides:
stop in class AbstractDelegatingStore
Throws:
CacheLoaderException

applyModificationsSync

protected void applyModificationsSync(List<Modification> mods)
                               throws CacheLoaderException
Throws:
CacheLoaderException

Infinispan Distribution 5.2.6.Final-redhat-2

Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.