org.jboss.cache.loader.s3
Class S3CacheLoader

java.lang.Object
  extended by org.jboss.cache.loader.AbstractCacheLoader
      extended by org.jboss.cache.loader.s3.S3CacheLoader
All Implemented Interfaces:
Lifecycle, CacheLoader

@ThreadSafe
public class S3CacheLoader
extends AbstractCacheLoader

Uses the Amazon S3 service for storage. See http://aws.amazon.com/ for information. Does not support transaction isolation.

Data is stored in a single bucket location. The FQN comprises the key of the storage, the data the data itself.

Internal structure:

 A/
 B/_rootchild
 C/_rootchild/_child1
 C/_rootchild/_child2
 C/_rootchild/_child3
 B/_root2
 
The FQN component type is either prefixed with a _ for String, or a primitive type prefix.

All put and many remove operations require fetching and merging data before storing data, which increases latency. This fetching can be turned off. See S3LoaderConfig.getOptimize().

Parent nodes are added to the store as needed. For example, when doing a put("/a/b/c"), the nodes "/a/b" and "/a" are created if they do not exist. To prevent unnecessary checks of the store, a local cache is kept of these "parent nodes". With multiple sites removing parent nodes, this can potentially need to inconsistencies. To disable caching, set S3LoaderConfig.setParentCache(java.lang.String) to false.

Version:
$Id: S3CacheLoader.java 7168 2008-11-19 17:37:20Z jason.greene@jboss.com $
Author:
Elias Ross

Field Summary
 
Fields inherited from class org.jboss.cache.loader.AbstractCacheLoader
buddyFqnTransformer, cache, regionManager, transactions
 
Constructor Summary
S3CacheLoader()
           
 
Method Summary
 boolean exists(Fqn name)
          Returns whether the given node exists.
 Map get(Fqn name)
          Returns a map containing all key-value pairs for the given FQN, or null if the node is not present.
 Set<String> getChildrenNames(Fqn name)
          Returns an unmodifiable set of relative children names, or returns null if the parent node is not found or if no children are found.
 CacheLoaderConfig.IndividualCacheLoaderConfig getConfig()
          Gets the configuration.
 void put(Fqn name, Map<Object,Object> values)
          Stores a map of key-values for a given FQN, but does not delete existing key-value pairs (that is, it does not erase).
 Object put(Fqn name, Object key, Object value)
          Stores a single FQN-key-value record.
 void remove(Fqn name)
          Deletes the node for a given FQN and all its descendant nodes.
 Object remove(Fqn name, Object key)
          Removes a key from an FQN.
 void removeData(Fqn name)
          Clears the map for the given node, but does not remove the node.
 void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
          Sets the configuration string for this cache loader.
 void start()
          This cache loader is stateless, but as part of initialization access the service.
 void stop()
          Closes the connection; shuts down the HTTP connection pool.
 
Methods inherited from class org.jboss.cache.loader.AbstractCacheLoader
commit, create, destroy, doMarshall, doUnmarshall, getMarshaller, getNodeDataList, loadEntireState, loadState, loadStateHelper, move, prepare, put, put, regionAwareMarshall, regionAwareUnmarshall, rollback, setCache, setRegionManager, storeEntireState, storeState, storeStateHelper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

S3CacheLoader

public S3CacheLoader()
Method Detail

start

public void start()
           throws Exception
This cache loader is stateless, but as part of initialization access the service. Creates a new bucket, if necessary.

Specified by:
start in interface Lifecycle
Overrides:
start in class AbstractCacheLoader
Throws:
Exception

stop

public void stop()
Closes the connection; shuts down the HTTP connection pool.

Specified by:
stop in interface Lifecycle
Overrides:
stop in class AbstractCacheLoader

setConfig

public void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
Sets the configuration string for this cache loader.

Parameters:
base - May be an instance of the CacheLoaderConfig.IndividualCacheLoaderConfig base class, in which case the cache loader should use the PluggableConfigurationComponent.getProperties() method to find configuration information. Alternatively, may be a type-specific subclass of CacheLoaderConfig.IndividualCacheLoaderConfig, if there is one.

getConfig

public CacheLoaderConfig.IndividualCacheLoaderConfig getConfig()
Description copied from interface: CacheLoader
Gets the configuration.

Returns:
the configuration, represented by a CacheLoaderConfig.IndividualCacheLoaderConfig object.

getChildrenNames

public Set<String> getChildrenNames(Fqn name)
                             throws Exception
Returns an unmodifiable set of relative children names, or returns null if the parent node is not found or if no children are found.

Parameters:
name - The Fqn of the parent
Returns:
Set a set of children. Returns null if no children nodes are present, or the parent is not present
Throws:
Exception

get

public Map get(Fqn name)
        throws Exception
Returns a map containing all key-value pairs for the given FQN, or null if the node is not present.

Parameters:
name - the Fqn to search for.
Returns:
Map keys and values for the given node. Returns null if the node is not found. If the node is found but has no attributes, this method returns an empty Map.
Throws:
Exception

exists

public boolean exists(Fqn name)
               throws Exception
Returns whether the given node exists.

Returns:
true if node exists, false otherwise
Throws:
Exception

put

public Object put(Fqn name,
                  Object key,
                  Object value)
           throws Exception
Stores a single FQN-key-value record. This is slow, so avoid this method.

Throws:
Exception

remove

public Object remove(Fqn name,
                     Object key)
              throws Exception
Removes a key from an FQN. Not very fast.

Throws:
Exception

put

public void put(Fqn name,
                Map<Object,Object> values)
         throws Exception
Stores a map of key-values for a given FQN, but does not delete existing key-value pairs (that is, it does not erase).

Parameters:
name - The fully qualified name of the node
values - A Map of attributes. Can be null
Throws:
Exception

remove

public void remove(Fqn name)
            throws Exception
Deletes the node for a given FQN and all its descendant nodes.

Parameters:
name - the Fqn of the node
Throws:
Exception

removeData

public void removeData(Fqn name)
                throws Exception
Clears the map for the given node, but does not remove the node.

Parameters:
name - the Fqn of the node
Throws:
Exception


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