com.sun.jini.outrigger
Class EntryHolder.ContinuingQuery

java.lang.Object
  extended by com.sun.jini.outrigger.EntryHolder.ContinuingQuery
Enclosing class:
EntryHolder

 class EntryHolder.ContinuingQuery
extends Object

Object that can be used to perform a query that can return multiple matches and be restarted in another thread. Assumes that is being invoked from only one thread at a time, but does handle synchronization between concurrent queries on the parent EntryHolder.


Field Summary
private  Iterator<EntryHandle> contentsIterator
          Current position in parent EntryHolder's contents
private  EntryHandleTmplDesc[] descs
          EntryHandleTmplDesc for the templates
(package private)  long now
          Time used to weed out expired entries, ok if old
private  boolean takeThem
          true if entries yielded by the query should removed.
private  EntryRep[] tmpls
          Templates being used for the query
private  TransactableMgr txn
          Transaction (if any) being used for the query
 
Constructor Summary
private EntryHolder.ContinuingQuery(EntryRep[] tmpls, TransactableMgr txn, boolean takeThem, long now)
          Create a new ContinuingQuery object.
 
Method Summary
private  boolean handleMatch(EntryHandle handle)
          Returns true if handle has not been removed and matches one or more of the templates
(package private)  EntryHandle next(Set conflictSet, Set lockedEntrySet, WeakHashMap provisionallyRemovedEntrySet)
          Return the next matching entry.
(package private)  void restart(long now)
          EntryHolder queries have thread local state that get clobbered if another query (on a different or same EntryHolder, including hasMatch calls) is started in the same thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tmpls

private final EntryRep[] tmpls
Templates being used for the query


txn

private final TransactableMgr txn
Transaction (if any) being used for the query


takeThem

private final boolean takeThem
true if entries yielded by the query should removed.


descs

private EntryHandleTmplDesc[] descs
EntryHandleTmplDesc for the templates


now

long now
Time used to weed out expired entries, ok if old


contentsIterator

private Iterator<EntryHandle> contentsIterator
Current position in parent EntryHolder's contents

Constructor Detail

EntryHolder.ContinuingQuery

private EntryHolder.ContinuingQuery(EntryRep[] tmpls,
                                    TransactableMgr txn,
                                    boolean takeThem,
                                    long now)
Create a new ContinuingQuery object.

Parameters:
tmpls - An array of templates. Query will yield any entry that matches one or more of the templates.
txn - Transaction that should be used with the query. May be null. If non-null any entries yielded by the query will be locked under the transaction.
takeThem - If true any entries yielded by the query should be removed.
now - Estimate of current time used to weed out expired entries, ok if old
Method Detail

restart

void restart(long now)
EntryHolder queries have thread local state that get clobbered if another query (on a different or same EntryHolder, including hasMatch calls) is started in the same thread. The state also needs to be restored if it the query is continued in another thread. The restart method must be called to restore the thread local state.

Parameters:
now - Estimate of current time used to weed out expired entries, ok if old

next

EntryHandle next(Set conflictSet,
                 Set lockedEntrySet,
                 WeakHashMap provisionallyRemovedEntrySet)
           throws CannotJoinException
Return the next matching entry. Returns null if there are no matches remaining. Call restart first if query is being used in a different thread from the last next call and/or the current thread has done any form of EntryHolder query on any holder since the last next call.

Parameters:
conflictSet - If non-null the TransactableMgr objects of any transactions that prevent a entry from being retured will be added to conflictSet. May be null in which case conflicting transaction will not be recorded. This method assumes that any concurrent access is being arbitrated by the set or by the caller.
lockedEntrySet - If non-null the ID of any entries that can't be retured because of conflicting transaction will be added to lockedEntrySet. May be null in which case unavailable entries will not be recorded. This method assumes that any concurrent access is being arbitrated by the set or by the caller.
provisionallyRemovedEntrySet - If the entry can not be read/taken because it has been provisionally removed then its handle will be placed in the passed WeakHashMap as a key (with null as the value). May be null in which case provisionally removed entries will not be recorded. This method assumes that any concurrent access is being arbitrated by the set or by the caller.
Returns:
a matching entry or null.
Throws:
CannotJoinException - if a match is found and the operation is to be performed under a transaction, but the transaction is no longer active.

handleMatch

private boolean handleMatch(EntryHandle handle)
Returns true if handle has not been removed and matches one or more of the templates



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