com.sun.jini.outrigger
Class ConsumingWatcher

java.lang.Object
  extended by com.sun.jini.outrigger.TransitionWatcher
      extended by com.sun.jini.outrigger.QueryWatcher
          extended by com.sun.jini.outrigger.SingletonQueryWatcher
              extended by com.sun.jini.outrigger.ConsumingWatcher
All Implemented Interfaces:
Transactable, Comparable, TransactionConstants

 class ConsumingWatcher
extends SingletonQueryWatcher
implements Transactable

Subclass of QueryWatcher for takes and transactional reads. Resolves with the first matching transition where the entry is visible to the associated transaction and the entry is still available.


Field Summary
private  WeakHashMap provisionallyRemovedEntrySet
          Set of entries (represented by EntryHolders) that we would have liked to return, but have been provisionally removed.
private  boolean takeIt
          true if this query is a take and false otherwise.
private  Txn txn
          If non-null the transaction this query is being performed under.
 
Fields inherited from class com.sun.jini.outrigger.TransitionWatcher
startOrdinal
 
Fields inherited from interface net.jini.core.transaction.server.TransactionConstants
ABORTED, ACTIVE, COMMITTED, NOTCHANGED, PREPARED, VOTING
 
Constructor Summary
ConsumingWatcher(long expiration, long timestamp, long startOrdinal, WeakHashMap provisionallyRemovedEntrySet, Txn txn, boolean takeIt)
          Create a new ConsumingWatcher.
 
Method Summary
 void abort(TransactableMgr mgr, OutriggerServerImpl space)
          If a transaction ends in the middle of a query we want to throw an exception to the client making the query (not the Txn calling us here.)
(package private)  boolean catchUp(EntryTransition transition, long now)
          Process a transition which was posted before the watcher was placed in TransitionWatchers object.
 void commit(TransactableMgr mgr, OutriggerServerImpl space)
          This should never happen since we always return NOTCHANGED from prepare.
(package private)  boolean isInterested(EntryTransition transition, long ordinal)
          Return true if this watcher cares about a given visibility transition.
 int prepare(TransactableMgr mgr, OutriggerServerImpl space)
          If a transaction ends in the middle of a query we want to throw an exception to the client making the query not the Txn calling us here.)
(package private)  void process(EntryTransition transition, long now)
          Process the given transition.
 
Methods inherited from class com.sun.jini.outrigger.SingletonQueryWatcher
addTemplateHandle, getServer, isResolved, resolve, resolvedWithEntry, resolvedWithThrowable, waitOnResolution
 
Methods inherited from class com.sun.jini.outrigger.QueryWatcher
getExpiration, removeIfExpired
 
Methods inherited from class com.sun.jini.outrigger.TransitionWatcher
compareTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

txn

private final Txn txn
If non-null the transaction this query is being performed under. If null this query is not associated with a transaction.


takeIt

private final boolean takeIt
true if this query is a take and false otherwise.


provisionallyRemovedEntrySet

private final WeakHashMap provisionallyRemovedEntrySet
Set of entries (represented by EntryHolders) that we would have liked to return, but have been provisionally removed.

Constructor Detail

ConsumingWatcher

ConsumingWatcher(long expiration,
                 long timestamp,
                 long startOrdinal,
                 WeakHashMap provisionallyRemovedEntrySet,
                 Txn txn,
                 boolean takeIt)
Create a new ConsumingWatcher.

Parameters:
expiration - the initial expiration time for this TransitionWatcher in milliseconds since the beginning of the epoch.
timestamp - the value that is used to sort TransitionWatchers.
startOrdinal - the highest ordinal associated with operations that are considered to have occurred before the operation associated with this watcher.
provisionallyRemovedEntrySet - If the watcher encounters an entry that can not be read/taken because it has been provisionally removed then its handle will be placed in this WeakHashMap as a key (with null as the value). May be null in which case provisionally removed entries will not be recorded. Ensures that object is only accessed by one thread at a time
txn - If the query is being performed under a transaction the Txn object associated with that transaction.
takeIt - true if this query is a take and false otherwise.
Method Detail

isInterested

boolean isInterested(EntryTransition transition,
                     long ordinal)
Description copied from class: TransitionWatcher
Return true if this watcher cares about a given visibility transition. Assumes the transitioning entry matches the template in the TemplateHandle associated with this watcher. This method should return a value even if the expiration time has been reached or remove has been called. This call should not obtain any locks.

Specified by:
isInterested in class TransitionWatcher
Parameters:
transition - A EntryTransition that describes the transition and what entry is transitioning. This method will assume that transition.getHandle returns a non-null value.
ordinal - The ordinal associated with transition.
Returns:
true if this watcher is interested in the indicated transition and false otherwise.

process

void process(EntryTransition transition,
             long now)
Description copied from class: TransitionWatcher
Process the given transition. Assumes the passed entry matches the template in the TemplateHandle associated with this watcher and that isInterested returned true. This call may make changes to the passed EntryHandle that will prevent it from being used by other watchers. If remove has been called or the expiration time of this watcher has passed, this call should have no effect. This call may cause the watcher to be removed.

Specified by:
process in class TransitionWatcher
Parameters:
transition - A EntryTransition that describes the transition and what entry is transitioning. This method will assume that transition.getHandle returns a non-null value.
now - An estimate of the current time (not the time when the event occured).

catchUp

boolean catchUp(EntryTransition transition,
                long now)
Description copied from class: QueryWatcher
Process a transition which was posted before the watcher was placed in TransitionWatchers object. Assumes that the entry in the transition matches matches the template in the TemplateHandle associated with this watcher. Does not assume isInterested has been called.

Specified by:
catchUp in class QueryWatcher
Parameters:
transition - A EntryTransition that describes the transition and what entry is transitioning. This method will assume that transition.getHandle returns a non-null value.
now - An estimate of the current time (not the time when the event occured).
Returns:
true if the query has been resolved, and false otherwise. Note, even if this call returns true, waitOnResolution must still be called.

prepare

public int prepare(TransactableMgr mgr,
                   OutriggerServerImpl space)
If a transaction ends in the middle of a query we want to throw an exception to the client making the query not the Txn calling us here.)

Specified by:
prepare in interface Transactable

commit

public void commit(TransactableMgr mgr,
                   OutriggerServerImpl space)
This should never happen since we always return NOTCHANGED from prepare.

Specified by:
commit in interface Transactable

abort

public void abort(TransactableMgr mgr,
                  OutriggerServerImpl space)
If a transaction ends in the middle of a query we want to throw an exception to the client making the query (not the Txn calling us here.)

Specified by:
abort in interface Transactable


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.