net.sf.spif
Class StoreChain

java.lang.Object
  |
  +--net.sf.spif.StoreChain
Direct Known Subclasses:
HashStore, IndexedFileStore, StoreAccumulator, StoreCache, StoreDispatcher, StoreLocker, StoreLogger, StorePersister, StoreProfiler, StoreSessionClient

public class StoreChain
extends java.lang.Object

A store chain implementation is an object which is able to participate in a store chain - a chain of responsibilities propagating requests for identified objects and changes to such objects.

The store chain in a vm is usually accessed by Store.

A store chain is instantiated at every vm to make sure requests and updates to objects are handled correctly. For instance, the client chain might consist of a cache and a remote forwarder. The server chain might consist of a remote receiver, an access controller, a locker, a cache and a persister. See Spif.

Store chains should implement equal to mean funtionally equal. That is, a cache is equal to another cache which functions in the same way, even if the two caches contains different data at a given time.

Version:
$Id: StoreChain.java,v 1.4 2003/03/07 22:51:41 bratseth Exp $
Author:
Jon S Bratseth

Field Summary
protected  StoreChain chained
          The store chain chained on this
 
Constructor Summary
StoreChain()
           
 
Method Summary
 void clear()
          Clears everything in the store.
 boolean equals(java.lang.Object object)
          Returns if this store is functionally equal to the given store chain.
 java.lang.Object get(Id id, boolean writable)
          Returns an object from the store.
 StoreChain getChained()
          Returns the chain chained on this.
 StoreChain getChained(java.lang.Class storeChainSubtype)
          Returns a chained instance of a type
protected  StoreChain getChained(Id id)
          Returns the chain chained on this for the appropriate type.
 int hashCode()
          Returns the hashcode of the class of this store chain.
 Id put(Id id, java.lang.Object object)
          Puts an object in the store.
 boolean remove(Id id)
          Removes an object.
 StoreChain setChained(StoreChain chained)
          Sets the chained chaineded on this
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chained

protected StoreChain chained
The store chain chained on this

Constructor Detail

StoreChain

public StoreChain()
Method Detail

getChained

public StoreChain getChained()
Returns the chain chained on this. Calls to this will usually be forwarded to this chain (as default, see getChained())

Returns:
the chain or null if nothing is chained on this

getChained

protected StoreChain getChained(Id id)

Returns the chain chained on this for the appropriate type. Override this method if you wish to use different chains whith different types of objects.

 //.....
 public StoreChain getChained(Id id) {
   if ( id!=null && id.getType().getName().indexOf("Legacy")>=0) {
       return legacyChain;    
   } 
   else {
       return chained;
   }
 }
 //....
 

This default implementation returns the chain given by setChained regardless of the input id.

Parameters:
id - the id to return the chain of, or null to return the default chain. Note that all implementations are required to return a sensible chain given null.
Returns:
the StoreChain chained on this for the given id type
See Also:
Id.getType(), StoreDispatcher

getChained

public StoreChain getChained(java.lang.Class storeChainSubtype)
Returns a chained instance of a type

Parameters:
storeChainSubtype - the type to return a chained instance of. It this is not a StoreChain subtype, null will always be returned
Returns:
the first chained instance of the given type, or null if no instance of the given type is chained in this vm

setChained

public StoreChain setChained(StoreChain chained)
Sets the chained chaineded on this

Parameters:
chained - the object to chained to this, or null to chained nothing
Returns:
the input chain, to facilitate setChained(first).setChained(second)...

get

public java.lang.Object get(Id id,
                            boolean writable)

Returns an object from the store.

This default implementation just forwards to the chained. for (optional) use by subclasses.

Parameters:
id - the id of the object to return
Returns:
the object, or null if the object could not be retrieved or if the input id was null
Throws:
java.lang.RuntimeException - throw some chain configuration dependent runtime exception, for instance a locker might throw a LockedException if a locked object is attempted acquired for writing

put

public Id put(Id id,
              java.lang.Object object)

Puts an object in the store. The objects may be new, or previously acquired by getting writeable. It is an error to attempt to put an existing object not previously acquired by getting writeable.

This default implementation just forwards to the chained. for (optional) use by subclasses.

Parameters:
id - the id of the object to put. May be null
object - the object to put. May be null
Returns:
the id of this object. This will usually be (and is in this default implementation) the input id, unless the given id is null and there is an id generating service on the store chain
Throws:
java.lang.RuntimeException - throw some chain-configuration-dependent runtime exception

remove

public boolean remove(Id id)

Removes an object. Does nothign if the object does not exist.

This default implementation just forwards to the chained. for (optional) use by subclasses.

Parameters:
id - the id of the object to remove
Returns:
true if the object did not exists
Throws:
java.lang.RuntimeException - may throw some chain-configuration-dependent runtime exception

clear

public void clear()
Clears everything in the store. Most usable for testing. Stores may not support this.


equals

public boolean equals(java.lang.Object object)

Returns if this store is functionally equal to the given store chain. Two caches for instance, are functionally equal if the function in the same way, even if the two caches contains different data at a given time.

This default implementation defines two store chains of the same class as functionally equal. This is sifficient for stateless store chains, but must be overridden by chains which has parameter controlled behaviour.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns the hashcode of the class of this store chain. See equals(java.lang.Object)

Overrides:
hashCode in class java.lang.Object


Spif 1.01 (2003-04-03). http://spif.sf.net