org.infinispan.loaders.jdbm
Class JdbmCacheStore

java.lang.Object
  extended by org.infinispan.loaders.AbstractCacheLoader
      extended by org.infinispan.loaders.AbstractCacheStore
          extended by org.infinispan.loaders.jdbm.JdbmCacheStore
All Implemented Interfaces:
CacheLoader, CacheStore

@ThreadSafe
public class JdbmCacheStore
extends AbstractCacheStore

A persistent CacheLoader based on the JDBM project. See http://jdbm.sourceforge.net/ . Does not support transaction isolation.

Supports removal of expired entries.

It would probably be better if meta-data (expiry time) was stored independent of the value of the entry. That is, if (key,"m") == meta and (key,"v") == value.

Author:
Elias Ross, Galder ZamarreƱo

Field Summary
 
Fields inherited from class org.infinispan.loaders.AbstractCacheStore
multiThreadedPurge, purgerService
 
Fields inherited from class org.infinispan.loaders.AbstractCacheLoader
cache, marshaller
 
Constructor Summary
JdbmCacheStore()
           
 
Method Summary
protected  void applyModifications(List<? extends Modification> mods)
           
 void clear()
          Clears all entries in the store
 void fromStream(ObjectInput in)
          Reads from a stream the number of entries (long) then the entries themselves.
 Class<? extends CacheLoaderConfig> getConfigurationClass()
          This method is used by the configuration parser to get a hold of the CacheLoader implementation's corresponding CacheLoaderConfig type.
 void init(CacheLoaderConfig clc, 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.
protected  void purgeInternal()
          Purge expired entries.
 boolean remove(Object key)
          Removes an entry in the store.
 boolean remove0(Object key)
           
 void start()
           
 void stop()
          Closes all databases, ignoring exceptions, and nulls references to all database related information.
 void store(InternalCacheEntry entry)
          Stores an entry
 void toStream(ObjectOutput out)
          Writes to a stream the number of entries (long) then the entries themselves.
 String toString()
           
 
Methods inherited from class org.infinispan.loaders.AbstractCacheStore
commit, getCacheStoreConfig, getConcurrencyLevel, getMarshaller, prepare, purgeExpired, removeAll, rollback, safeClose, safeClose, supportsMultiThreadedPurge
 
Methods inherited from class org.infinispan.loaders.AbstractCacheLoader
containsKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.infinispan.loaders.CacheLoader
containsKey
 

Constructor Detail

JdbmCacheStore

public JdbmCacheStore()
Method Detail

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.

Returns:
the type of the CacheLoaderConfig bean used to configure this implementation of CacheLoader.

init

public void init(CacheLoaderConfig clc,
                 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 AbstractCacheStore
Parameters:
clc - 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

start

public void start()
           throws CacheLoaderException
Specified by:
start in interface CacheLoader
Overrides:
start in class AbstractCacheStore
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.

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.

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.

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.

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

stop

public void stop()
Closes all databases, ignoring exceptions, and nulls references to all database related information.

Specified by:
stop in interface CacheLoader
Overrides:
stop in class AbstractCacheStore

clear

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

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.

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

remove0

public boolean remove0(Object key)
                throws CacheLoaderException
Throws:
CacheLoaderException

store

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

Parameters:
entry - entry to store
Throws:
CacheLoaderException - in the event of problems writing to the store

toStream

public void toStream(ObjectOutput out)
              throws CacheLoaderException
Writes to a stream the number of entries (long) then the entries themselves.

Parameters:
out - stream to write to
Throws:
CacheLoaderException - in the event of problems reading from the store

fromStream

public void fromStream(ObjectInput in)
                throws CacheLoaderException
Reads from a stream the number of entries (long) then the entries themselves.

Parameters:
in - stream to read from
Throws:
CacheLoaderException - in the event of problems writing to the store

purgeInternal

protected void purgeInternal()
                      throws CacheLoaderException
Purge expired entries.

Specified by:
purgeInternal in class AbstractCacheStore
Throws:
CacheLoaderException

applyModifications

protected void applyModifications(List<? extends Modification> mods)
                           throws CacheLoaderException
Overrides:
applyModifications in class AbstractCacheStore
Throws:
CacheLoaderException

toString

public String toString()
Overrides:
toString in class Object

-->

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