fabric.worker
Class RemoteStore

java.lang.Object
  extended by fabric.net.RemoteNode
      extended by fabric.worker.RemoteStore
All Implemented Interfaces:
Store, java.io.Serializable
Direct Known Subclasses:
InProcessStore

public class RemoteStore
extends RemoteNode
implements Store

Encapsulates a Store. This class maintains two connections to the store (one with SSL, for worker requests; and one without, for dissemination requests) and manages all communication. Stores can only be obtained through the Worker.getStore() interface. For each remote store, there should be at most one RemoteStore object representing that store.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class fabric.net.RemoteNode
name
 
Constructor Summary
protected RemoteStore(java.lang.String name)
          Creates a store representing the store at the given host name.
protected RemoteStore(java.lang.String name, java.security.PublicKey key)
          Creates a store representing the store at the given host name.
 
Method Summary
 void abortTransaction(boolean useAuthentication, TransactionID tid)
          Notifies the store that the transaction is being Aborted.
 void cache(Object._Impl impl)
          Adds the given object to the cache.
 boolean checkForStaleObjects(LongKeyMap<java.lang.Integer> reads)
          Determines whether the given set of objects are stale.
 void cleanup()
          Cleans up the SerializedObject collector thread.
 void clearCache()
          Clears the worker's cache for this store.
 void commitTransaction(boolean useAuthentication, long transactionID)
          Notifies the Store that the transaction should be committed.
 long createOnum()
          Obtains a new, unused object number from the Store.
 boolean evict(long onum)
          Evicts the object with the given onum from cache.
 NodePrincipal getPrincipal()
          Returns the NodePrincipal associated with this store.
 java.security.PublicKey getPublicKey()
           
 Map getRoot()
          Returns the root map of the Store
protected  java.util.List<SerializedObject> getStaleObjects(LongKeyMap<java.lang.Integer> reads)
          Helper for checkForStaleObjects.
 int hashCode()
           
 boolean isLocalStore()
          Determines whether this is the local store.
protected  SocketAddress lookup()
           
 boolean notifyEvict(long onum)
          Notifies that an object has been evicted from cache.
 boolean prepareTransaction(boolean useAuthentication, long tid, long commitTime, java.util.Collection<Object._Impl> toCreate, LongKeyMap<java.lang.Integer> reads, java.util.Collection<Object._Impl> writes)
          Sends a PREPARE message to the store.
 Glob readEncryptedObjectFromStore(long onum)
          Called by dissemination to fetch an encrypted object from the store.
 Object._Impl readObject(long onum)
          Returns the requested _Impl object.
 Object._Impl readObjectFromCache(long onum)
          Returns the requested _Impl object if it exists in the object cache.
 ObjectGroup readObjectFromStore(long onum)
          Goes to the store to get object.
 Object._Impl readObjectNoDissem(long onum)
          Returns the requested _Impl object, fetching it directly from the Store if it is not resident.
 java.lang.Object readResolve()
          Looks up the actual Store object when this store is deserialized.
protected  void reserve(int num)
          Ensure that a given number of objects can be created without contacting the store.
 java.lang.String toString()
           
 boolean updateCache(SerializedObject update)
          Updates the worker's cache of objects that originate from this store.
 
Methods inherited from class fabric.net.RemoteNode
name, openStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fabric.worker.Store
name
 

Constructor Detail

RemoteStore

protected RemoteStore(java.lang.String name)
Creates a store representing the store at the given host name.


RemoteStore

protected RemoteStore(java.lang.String name,
                      java.security.PublicKey key)
Creates a store representing the store at the given host name.

Method Detail

cleanup

public void cleanup()
Cleans up the SerializedObject collector thread.

Overrides:
cleanup in class RemoteNode

createOnum

public long createOnum()
                throws UnreachableNodeException
Description copied from interface: Store
Obtains a new, unused object number from the Store.

Specified by:
createOnum in interface Store
Throws:
UnreachableNodeException

prepareTransaction

public boolean prepareTransaction(boolean useAuthentication,
                                  long tid,
                                  long commitTime,
                                  java.util.Collection<Object._Impl> toCreate,
                                  LongKeyMap<java.lang.Integer> reads,
                                  java.util.Collection<Object._Impl> writes)
                           throws TransactionPrepareFailedException,
                                  UnreachableNodeException
Sends a PREPARE message to the store.

Specified by:
prepareTransaction in interface Store
Returns:
whether a subtransaction was created on the store as a result of the prepare.
Throws:
TransactionPrepareFailedException
UnreachableNodeException

readObject

public final Object._Impl readObject(long onum)
                              throws FetchException
Returns the requested _Impl object. If the object is not resident, it is fetched from the Store via dissemination.

Specified by:
readObject in interface Store
Parameters:
onum - The identifier of the requested object
Returns:
The requested object
Throws:
FabricException
FetchException

readObjectNoDissem

public final Object._Impl readObjectNoDissem(long onum)
                                      throws FetchException
Description copied from interface: Store
Returns the requested _Impl object, fetching it directly from the Store if it is not resident.

Specified by:
readObjectNoDissem in interface Store
Parameters:
onum - The identifier of the requested object
Returns:
The requested object
Throws:
FetchException

readObjectFromCache

public Object._Impl readObjectFromCache(long onum)
Description copied from interface: Store
Returns the requested _Impl object if it exists in the object cache.

Specified by:
readObjectFromCache in interface Store
Parameters:
onum - The identifier of the requested object.
Returns:
The requested object if it exists in the object cache; otherwise, null.

readObjectFromStore

public ObjectGroup readObjectFromStore(long onum)
                                throws FetchException
Goes to the store to get object.

Parameters:
onum - The object number to fetch
Returns:
An ObjectGroup whose head object is the requested object.
Throws:
FetchException - if there was an error while fetching the object from the store.

readEncryptedObjectFromStore

public final Glob readEncryptedObjectFromStore(long onum)
                                        throws FetchException
Called by dissemination to fetch an encrypted object from the store.

Parameters:
onum - The object number to fetch.
Throws:
FetchException

readResolve

public java.lang.Object readResolve()
Looks up the actual Store object when this store is deserialized. While this method is not explicitly called in the code, it is used by the Java serialization framework when deserializing a Store object.

Returns:
The canonical Store object corresponding to this Store's onum
Throws:
java.io.ObjectStreamException

reserve

protected void reserve(int num)
                throws UnreachableNodeException
Ensure that a given number of objects can be created without contacting the store.

Parameters:
num - The number of objects to allocate
Throws:
UnreachableNodeException

abortTransaction

public void abortTransaction(boolean useAuthentication,
                             TransactionID tid)
Description copied from interface: Store
Notifies the store that the transaction is being Aborted.

Specified by:
abortTransaction in interface Store
tid - the ID of the aborting transaction. This is assumed to specify a top-level transaction.

commitTransaction

public void commitTransaction(boolean useAuthentication,
                              long transactionID)
                       throws UnreachableNodeException,
                              TransactionCommitFailedException
Description copied from interface: Store
Notifies the Store that the transaction should be committed.

Specified by:
commitTransaction in interface Store
transactionID - the ID of the transaction to commit
Throws:
UnreachableNodeException
TransactionCommitFailedException

checkForStaleObjects

public boolean checkForStaleObjects(LongKeyMap<java.lang.Integer> reads)
Description copied from interface: Store
Determines whether the given set of objects are stale.

Specified by:
checkForStaleObjects in interface Store
Returns:
true iff stale objects were found.

getStaleObjects

protected java.util.List<SerializedObject> getStaleObjects(LongKeyMap<java.lang.Integer> reads)
Helper for checkForStaleObjects.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getRoot

public Map getRoot()
Description copied from interface: Store
Returns the root map of the Store

Specified by:
getRoot in interface Store

getPrincipal

public NodePrincipal getPrincipal()
Description copied from interface: Store
Returns the NodePrincipal associated with this store.

Specified by:
getPrincipal in interface Store

isLocalStore

public final boolean isLocalStore()
Description copied from interface: Store
Determines whether this is the local store.

Specified by:
isLocalStore in interface Store

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

notifyEvict

public boolean notifyEvict(long onum)
Notifies that an object has been evicted from cache.

Specified by:
notifyEvict in interface Store
Parameters:
onum - Onum of the object that was evicted.
Returns:
true iff the onum was found in cache.

evict

public boolean evict(long onum)
Description copied from interface: Store
Evicts the object with the given onum from cache.

Specified by:
evict in interface Store
Returns:
true iff the onum was found in cache.

updateCache

public boolean updateCache(SerializedObject update)
Updates the worker's cache of objects that originate from this store. If an object with the given onum exists in cache, it is evicted and the given update is placed in the cache of serialized objects. Otherwise, the cache of serialized objects will only be updated if a pre-existing serialized object exits for the given onum.

Returns:
true iff an _Impl with the given onum was evicted from cache.

cache

public void cache(Object._Impl impl)
Description copied from interface: Store
Adds the given object to the cache.

Specified by:
cache in interface Store

getPublicKey

public java.security.PublicKey getPublicKey()
Returns:
The store's public key for verifying Glob signatures.

clearCache

public void clearCache()
Clears the worker's cache for this store. To be used for (performance) testing only.

See Also:
Worker.clearCache()

lookup

protected SocketAddress lookup()
                        throws java.io.IOException
Specified by:
lookup in class RemoteNode
Returns:
Throws:
java.io.IOException