com.sun.sgs.impl.service.data
Class Context

java.lang.Object
  extended by com.sun.sgs.impl.util.TransactionContext
      extended by com.sun.sgs.impl.service.data.Context
All Implemented Interfaces:
TransactionListener

final class Context
extends TransactionContext
implements TransactionListener

Stores information for a specific transaction.


Field Summary
(package private)  ClassSerialization classSerial
          Controls serializing classes.
(package private)  boolean detectModifications
          Whether to detect modifications.
(package private)  ReferenceTable refs
          Stores information about managed references.
(package private)  DataStore store
          The data store.
(package private)  Transaction txn
          The transaction.
 
Fields inherited from class com.sun.sgs.impl.util.TransactionContext
isCommitted, isPrepared
 
Constructor Summary
Context(DataServiceImpl service, DataStore store, Transaction txn, int debugCheckInterval, boolean detectModifications, ClassesTable classesTable, boolean trackStaleObjects)
          Creates an instance of this class.
 
Method Summary
 void abort(boolean retryable)
          Aborts this context's involvement with the transaction associated with this context.
 void afterCompletion(boolean commit)
          Called after a transaction is committed or aborted.
 void beforeCompletion()
          Called after the main work of the transaction is complete, just before the transaction is prepared.
(package private)  void checkState()
          Checks that the service is running or shutting down.
 void commit()
          Commits this context's state.
(package private)
<T> ManagedReferenceImpl<T>
findReference(T object)
          Finds the existing reference associated with the specified object, returning null if it is not found.
(package private)  ManagedObject getBinding(String internalName, boolean forUpdate)
          Obtains the object associated with the specified internal name.
(package private)  ManagedReferenceImpl<?> getReference(long oid)
          Obtains the reference associated with the specified ID.
(package private)
<T> ManagedReferenceImpl<T>
getReference(T object)
          Obtains the reference associated with the specified object.
(package private)  BigInteger getTxnId()
          Returns the ID of the associated transaction as a BigInteger.
 String getTypeName()
          Returns the fully qualified type name of the listener.
(package private)  void maybeCheckReferenceTable()
          Checks the consistency of the reference table if the operation count equals the check interval.
(package private)  String nextBoundName(String internalName)
          Returns the next bound name.
(package private)  long nextObjectId(long oid)
          Returns the next object ID, or -1 if there are no more objects.
(package private)  boolean optimisticWriteLocks()
          Returns whether to delay write locking until commit time.
 boolean prepare()
          Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and returns true if this context's state is read-only and returns false otherwise.
 void prepareAndCommit()
          Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and if this context's state is not read-only, commits this context's state.
(package private)  void removeBinding(String internalName)
          Removes the object associated with the specified internal name.
(package private)  void removingObject(ManagedObjectRemoval object)
          Calls removingObject on the argument, and checks for recursion.
(package private)
<T> ManagedReferenceImpl<T>
safeFindReference(T object)
          Finds the existing reference associated with the specified object, returning null if it is not found or has been removed.
(package private)  void setBinding(String internalName, Object object)
          Sets the object associated with the specified internal name.
 
Methods inherited from class com.sun.sgs.impl.util.TransactionContext
getTransaction, isPrepared
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

final DataStore store
The data store.


txn

final Transaction txn
The transaction.


detectModifications

final boolean detectModifications
Whether to detect modifications.


classSerial

final ClassSerialization classSerial
Controls serializing classes.


refs

final ReferenceTable refs
Stores information about managed references. This field is logically part of the ManagedReferenceImpl class.

Constructor Detail

Context

Context(DataServiceImpl service,
        DataStore store,
        Transaction txn,
        int debugCheckInterval,
        boolean detectModifications,
        ClassesTable classesTable,
        boolean trackStaleObjects)
Creates an instance of this class.

Method Detail

getReference

<T> ManagedReferenceImpl<T> getReference(T object)
Obtains the reference associated with the specified object.


findReference

<T> ManagedReferenceImpl<T> findReference(T object)
Finds the existing reference associated with the specified object, returning null if it is not found. Throws ObjectNotFoundException if the object has been removed.


safeFindReference

<T> ManagedReferenceImpl<T> safeFindReference(T object)
Finds the existing reference associated with the specified object, returning null if it is not found or has been removed.


getReference

ManagedReferenceImpl<?> getReference(long oid)
Obtains the reference associated with the specified ID.


getBinding

ManagedObject getBinding(String internalName,
                         boolean forUpdate)
Obtains the object associated with the specified internal name.


setBinding

void setBinding(String internalName,
                Object object)
Sets the object associated with the specified internal name.


removeBinding

void removeBinding(String internalName)
Removes the object associated with the specified internal name.


nextBoundName

String nextBoundName(String internalName)
Returns the next bound name.


nextObjectId

long nextObjectId(long oid)
Returns the next object ID, or -1 if there are no more objects. Does not return IDs for removed objects. Specifying -1 requests the first ID.


prepare

public boolean prepare()
                throws Exception
Description copied from class: TransactionContext
Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and returns true if this context's state is read-only and returns false otherwise. In the case that this method is overridden and returns true, that implementation should also set the isCommitted flag to true.

The default implementation of this method sets the isPrepared flag to true and returns false.

Overrides:
prepare in class TransactionContext
Returns:
true if this context's state is read-only, false otherwise
Throws:
Exception - if there is a problem preparing this context's state

commit

public void commit()
Description copied from class: TransactionContext
Commits this context's state. The implementation of this method should set the isCommitted flag to true.

Specified by:
commit in class TransactionContext

prepareAndCommit

public void prepareAndCommit()
                      throws Exception
Description copied from class: TransactionContext
Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and if this context's state is not read-only, commits this context's state. This method should also set the isCommitted flag to true.

The default implementation of this method invokes prepare to prepare state for the transaction associated with this context, and if prepare returns false, then invokes commit to commit this context's state.

Overrides:
prepareAndCommit in class TransactionContext
Throws:
Exception - if there is a problem preparing this context's state

abort

public void abort(boolean retryable)
Description copied from class: TransactionContext
Aborts this context's involvement with the transaction associated with this context.

Specified by:
abort in class TransactionContext
Parameters:
retryable - if true, the transaction's abort cause is a retryable exception

beforeCompletion

public void beforeCompletion()
Called after the main work of the transaction is complete, just before the transaction is prepared. The transaction is still considered active when this method is called, although calls should not be made to independent Services. If the transaction has multiple transaction listeners registered, the order in which the listeners are called is unspecified.

If this method throws an exception, then the transaction will be aborted, and the exception will be treated as if it were thrown by the main body of the transaction.

This method will not be called if the transaction is aborted before it reaches the preparation stage, including if an earlier call to this method on another listener throws an exception or aborts the transaction.

This implementation flushes managed references and marks the transaction inactive so that we'll notice if other beforeCompletion methods attempt to call the data service.

Specified by:
beforeCompletion in interface TransactionListener

afterCompletion

public void afterCompletion(boolean commit)
Called after a transaction is committed or aborted. The parameter will be set to true if the transaction committed, else false if it aborted. If the transaction has multiple transaction listeners registered, the order in which the listeners are called is unspecified.

This implementation does nothing.

Specified by:
afterCompletion in interface TransactionListener
Parameters:
commit - true if the transaction committed, else false if it aborted

getTypeName

public String getTypeName()
Returns the fully qualified type name of the listener. Typically this is the implementing class or some other distinguishing name that will remain constant between transactions.

Specified by:
getTypeName in interface TransactionListener
Returns:
the name of the listener

maybeCheckReferenceTable

void maybeCheckReferenceTable()
Checks the consistency of the reference table if the operation count equals the check interval. Throws an IllegalStateException if it encounters a problem.


checkState

void checkState()
Checks that the service is running or shutting down.


removingObject

void removingObject(ManagedObjectRemoval object)
Calls removingObject on the argument, and checks for recursion.


getTxnId

BigInteger getTxnId()
Returns the ID of the associated transaction as a BigInteger.


optimisticWriteLocks

boolean optimisticWriteLocks()
Returns whether to delay write locking until commit time.


RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved