org.infinispan.loaders.decorators
Class AbstractDelegatingStore

java.lang.Object
  extended by org.infinispan.loaders.decorators.AbstractDelegatingStore
All Implemented Interfaces:
CacheLoader, CacheStore
Direct Known Subclasses:
AsyncStore, ReadOnlyStore, SingletonStore

public class AbstractDelegatingStore
extends Object
implements CacheStore

Simple delegate that delegates all calls. This is intended as a building block for other decorators who wish to add behavior to certain calls only.

Since:
4.0
Author:
Manik Surtani

Constructor Summary
AbstractDelegatingStore(CacheStore delegate)
           
 
Method Summary
 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 fromStream(ObjectInput inputStream)
          Writes contents of the stream to the store.
 CacheStoreConfig getCacheStoreConfig()
          Returns the configuration object associated to this cache store config.
 Class<? extends CacheLoaderConfig> getConfigurationClass()
          This method is used by the configuration parser to get a hold of the CacheLoader implementation's corresponding CacheLoaderConfig type.
 CacheStore getDelegate()
           
 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> list, GlobalTransaction tx, boolean isOnePhase)
          Issues a prepare call with a set of modifications to be applied to the cache store
 void purgeExpired()
          Purges expired entries from the 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 setDelegate(CacheStore delegate)
           
 void start()
           
 void stop()
           
 void store(InternalCacheEntry ed)
          Stores an entry
 void toStream(ObjectOutput outputStream)
          Loads the entire state into a stream, using whichever format is most efficient for the cache loader implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDelegatingStore

public AbstractDelegatingStore(CacheStore delegate)
Method Detail

setDelegate

public void setDelegate(CacheStore delegate)

getDelegate

public CacheStore getDelegate()

removeAll

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

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

store

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

Specified by:
store in interface CacheStore
Parameters:
ed - entry to store
Throws:
CacheLoaderException - in the event of problems writing to the store

fromStream

public void fromStream(ObjectInput inputStream)
                throws CacheLoaderException
Description copied from interface: CacheStore
Writes contents of the stream to the store. Implementations should expect that the stream contains data in an implementation-specific format, typically generated using CacheStore.toStream(java.io.ObjectOutput). While not a requirement, it is recommended that implementations make use of the StreamingMarshaller when dealing with the stream to make use of efficient marshalling.

It is imperative that implementations do not close the stream after finishing with it.

It is also recommended that implementations use their own start and end markers on the stream since other processes may write additional data to the stream after the cache store has written to it. As such, either markers or some other mechanism to prevent the store from reading too much information should be employed when writing to the stream in CacheStore.fromStream(java.io.ObjectInput) to prevent data corruption.

It can be assumed that the stream passed in already performs buffering such that the cache store implementation doesn't have to.

Specified by:
fromStream in interface CacheStore
Parameters:
inputStream - stream to read from
Throws:
CacheLoaderException - in the event of problems writing to the store

toStream

public void toStream(ObjectOutput outputStream)
              throws CacheLoaderException
Description copied from interface: CacheStore
Loads the entire state into a stream, using whichever format is most efficient for the cache loader implementation. Typically read and parsed by CacheStore.fromStream(java.io.ObjectInput).

While not a requirement, it is recommended that implementations make use of the StreamingMarshaller when dealing with the stream to make use of efficient marshalling.

It is imperative that implementations do not flush or close the stream after finishing with it.

It is also recommended that implementations use their own start and end markers on the stream since other processes may write additional data to the stream after the cache store has written to it. As such, either markers or some other mechanism to prevent the store from reading too much information in CacheStore.fromStream(java.io.ObjectInput) should be employed, to prevent data corruption.

It can be assumed that the stream passed in already performs buffering such that the cache store implementation doesn't have to.

Specified by:
toStream in interface CacheStore
Parameters:
outputStream - stream to write to
Throws:
CacheLoaderException - in the event of problems reading from the store

clear

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

Specified by:
clear in interface CacheStore
Throws:
CacheLoaderException - in the event of problems writing to the store

remove

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

Specified by:
remove in interface CacheStore
Parameters:
key - key to remove
Returns:
true if the entry was removed; false if the entry wasn't found.
Throws:
CacheLoaderException - in the event of problems writing to the store

purgeExpired

public void purgeExpired()
                  throws CacheLoaderException
Description copied from interface: CacheStore
Purges expired entries from the store.

Specified by:
purgeExpired in interface CacheStore
Throws:
CacheLoaderException - in the event of problems writing to the store

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 acordingly. 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
Parameters:
tx - tx to commit
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 acordingly. 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
Parameters:
tx - tx to roll back

prepare

public void prepare(List<? extends Modification> list,
                    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
Parameters:
list - 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

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
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
Parameters:
key - key
Returns:
an entry
Throws:
CacheLoaderException - in the event of problems reading from source

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
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
Parameters:
numEntries - maximum number of entries to load
Returns:
a set of entries, which would contain between 0 and numEntries entries.
Throws:
CacheLoaderException

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

containsKey

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

getConfigurationClass

public Class<? extends CacheLoaderConfig> getConfigurationClass()
Description copied from interface: CacheLoader
This method is used by the configuration parser to get a hold of the CacheLoader implementation's corresponding CacheLoaderConfig type. This is usually done by instantiating the CacheLoader and then calling this method. This may result in 2 instances being created, however, since the instance created to get a hold of the configuration type is then discarded and another instance is created for actual use as a CacheLoader when the cache starts.

Since Infinispan 4.1, you can also annotate your CacheLoader implementation with CacheLoaderMetadata and provide this information via the annotation, which will prevent unnecessary instances being created.

Specified by:
getConfigurationClass in interface CacheLoader
Returns:
the type of the CacheLoaderConfig bean used to configure this implementation of CacheLoader.

start

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

stop

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

getCacheStoreConfig

public CacheStoreConfig getCacheStoreConfig()
Description copied from interface: CacheStore
Returns the configuration object associated to this cache store config.

Specified by:
getCacheStoreConfig in interface CacheStore

Google Analytics

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