com.sun.jini.outrigger
Class EntryHolder

java.lang.Object
  extended by com.sun.jini.outrigger.EntryHolder
All Implemented Interfaces:
TransactionConstants

 class EntryHolder
extends Object
implements TransactionConstants

EntryHolders hold all the entries of a exact given class. OutriggerServerImpl has one EntryHolder for each entry class it knows about. A simple implementation is used that simply stores the entries in a list.

Author:
Sun Microsystems, Inc.

Nested Class Summary
(package private)  class EntryHolder.ContinuingQuery
          Object that can be used to perform a query that can return multiple matches and be restarted in another thread.
private  class EntryHolder.SimpleRepEnum
          The class that implements RepEnum for this class.
 
Field Summary
private  FastList<EntryHandle> contents
          The list that holds the handles
private  Hashtable idMap
          The map of cookies to handles, shared with the EntryHolderSet and every other EntryHolder.
private static Logger iteratorLogger
          Logger for logging information about iterators
private static Logger matchingLogger
          Logger for logging information about entry matching
private  OutriggerServerImpl space
          The server we are working for
 
Fields inherited from interface net.jini.core.transaction.server.TransactionConstants
ABORTED, ACTIVE, COMMITTED, NOTCHANGED, PREPARED, VOTING
 
Constructor Summary
EntryHolder(OutriggerServerImpl space, Hashtable idMap)
          Create a new EntryHolder with the shared idMap, and which will hold classes of the given className.
 
Method Summary
(package private)  void add(EntryHandle handle, TransactableMgr txn)
          Add new new entry to the holder.
(package private)  boolean attemptCapture(EntryHandle handle, TransactableMgr txn, boolean takeIt, Set conflictSet, Set lockedEntrySet, WeakHashMap provisionallyRemovedEntrySet, long now)
          Atomically check to see if the passed entry can be read/taken by the specified operation using the specified transaction and if it can read/take it and return true, otherwise return false.
private  boolean confirmAvailability(EntryRep rep, EntryHandle handle, TransactableMgr txn, boolean takeIt, long time, Set conflictSet, Set lockedEntrySet, WeakHashMap provisionallyRemovedEntrySet)
          With the EntryRep rep passed in, verify that the entry hasn't been taken by someone else, hasn't expired, etc.
private  boolean confirmAvailabilityWithTxn(EntryRep rep, EntryHandle handle, TransactableMgr txnMgr, boolean takeIt, long time, Set conflictSet, Set lockedEntrySet, WeakHashMap provisionallyRemovedEntrySet)
           
(package private)  RepEnum contents(TransactableMgr mgr)
          Return an enumerator over the contents of this space that are visible from the given mgr.
(package private)  EntryHolder.ContinuingQuery continuingQuery(EntryRep[] tmpls, TransactableMgr txn, boolean takeThem, long now)
          Return an object that can be used to perform a query that can return multiple matches and be restarted in another thread.
(package private)  void dump(String name)
          Debug method: Dump out the state of this holder, printing out the name of the dump first.
private  EntryHandle getContentsHead()
          Get the head of the contents list
private  boolean grab(EntryHandle handle, TransactableMgr txn, int op, boolean takeIt, boolean recovery)
          Given an entry that we want to return as the result of a query and we have confirmed we can return it, make the results of the query visible to the rest of the service.
private  EntryHandle handleFor(EntryRep rep)
          Return the handle for the given EntryRep object.
(package private)  EntryHandle hasMatch(EntryRep tmpl, TransactableMgr txn, boolean takeIt, Set conflictSet, Set lockedEntrySet, WeakHashMap provisionallyRemovedEntrySet)
          Return an EntryHandle object that matches the given template, or null if none does.
private  boolean isExpired(long now, EntryHandle handle)
          Return true if the entry held by the given handle has expired by the time in now.
(package private)  void reap()
          Reap the expired elements (and the underlying FastList)
(package private)  void recoverTake(EntryHandle handle, Txn txn)
          Recover a logged take.
(package private)  boolean remove(EntryHandle h, boolean recovery)
          Remove the given handle from this holder and the idMap.
(package private)  String[] supertypes()
          Return an array of the class names of the super classes of the entries in this holder, or null if the holder is empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contents

private final FastList<EntryHandle> contents
The list that holds the handles


idMap

private final Hashtable idMap
The map of cookies to handles, shared with the EntryHolderSet and every other EntryHolder.


space

private final OutriggerServerImpl space
The server we are working for


matchingLogger

private static final Logger matchingLogger
Logger for logging information about entry matching


iteratorLogger

private static final Logger iteratorLogger
Logger for logging information about iterators

Constructor Detail

EntryHolder

EntryHolder(OutriggerServerImpl space,
            Hashtable idMap)
Create a new EntryHolder with the shared idMap, and which will hold classes of the given className. The idMap is shared with EntryHolderSet so that there is one table that can map ID to EntryRep

Method Detail

hasMatch

EntryHandle hasMatch(EntryRep tmpl,
                     TransactableMgr txn,
                     boolean takeIt,
                     Set conflictSet,
                     Set lockedEntrySet,
                     WeakHashMap provisionallyRemovedEntrySet)
               throws CannotJoinException
Return an EntryHandle object that matches the given template, or null if none does. Optionally removes (perhaps provisionally) the found entry.

Parameters:
tmpl - The template to match against
txn - If non-null the transaction (represented as a TransactableMgr to perform the operation under. May be null if the operation is not to be done under a transaction.
takeIt - true if hasMatch should remove the matching entry.
conflictSet - If non-null the TransactableMgr objects of any transactions that prevent a non-null value 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.
Throws:
CannotJoinException - if a match is found and the operation is to be performed under a transaction, but the transaction is no longer active.
See Also:
attemptCapture(com.sun.jini.outrigger.EntryHandle, com.sun.jini.outrigger.TransactableMgr, boolean, java.util.Set, java.util.Set, java.util.WeakHashMap, long)

dump

void dump(String name)
Debug method: Dump out the state of this holder, printing out the name of the dump first.


attemptCapture

boolean attemptCapture(EntryHandle handle,
                       TransactableMgr txn,
                       boolean takeIt,
                       Set conflictSet,
                       Set lockedEntrySet,
                       WeakHashMap provisionallyRemovedEntrySet,
                       long now)
Atomically check to see if the passed entry can be read/taken by the specified operation using the specified transaction and if it can read/take it and return true, otherwise return false. If the entry is removed. Note, if the entry is removed, removal is logged.

Parameters:
handle - The EntryHandle of the entry the caller wants to read/take.
txn - If non-null the transaction to perform this operation under. Note, if non-null and txn is not active false will be returned.
takeIt - true if the caller is trying take the passed entry, false otherwise.
conflictSet - If non-null and the entry can not be read/taken because of transaction conflicts the conflicting transaction(s) will be added to this set. This method assumes that any concurrent access is being arbitrated by the set or by the caller.
lockedEntrySet - If the entry can not be read/taken because of a transaction conflict, the ID of the entry will be added to this set. 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.
now - an estimate of the current time in milliseconds since the beginning of the epoch.
Returns:
true if the entry could be read/taken and false otherwise.
Throws:
NullPointerException - if entry is null.

confirmAvailabilityWithTxn

private boolean confirmAvailabilityWithTxn(EntryRep rep,
                                           EntryHandle handle,
                                           TransactableMgr txnMgr,
                                           boolean takeIt,
                                           long time,
                                           Set conflictSet,
                                           Set lockedEntrySet,
                                           WeakHashMap provisionallyRemovedEntrySet)
                                    throws CannotJoinException
Throws:
CannotJoinException

confirmAvailability

private boolean confirmAvailability(EntryRep rep,
                                    EntryHandle handle,
                                    TransactableMgr txn,
                                    boolean takeIt,
                                    long time,
                                    Set conflictSet,
                                    Set lockedEntrySet,
                                    WeakHashMap provisionallyRemovedEntrySet)
With the EntryRep rep passed in, verify that the entry hasn't been taken by someone else, hasn't expired, etc. Also, verify that the entry is really (legally) visible to this transaction at this time. If this is a take, it it is removed or provisionally removed. If this operation is under a transaction, the entry is locked appropriately.


grab

private boolean grab(EntryHandle handle,
                     TransactableMgr txn,
                     int op,
                     boolean takeIt,
                     boolean recovery)
Given an entry that we want to return as the result of a query and we have confirmed we can return it, make the results of the query visible to the rest of the service. We must either [a] remove it from the holder (if the operation is a take under the same transaction the entry was written under), [b] mark it as provisionally removed pending commiting the operation to disk (if the operation is a take without a transaction), [c] lock it under the transaction passed into this method (if the operation is a read or take under a transaction), or [d] do nothing (read not under a transaction) as appropriate.

Also used during log recovery to recover takes.

Parameters:
handle - The handle attached to the particular EntryRep
txn - The Txn object
op - TAKE or READ (as a TransactableMgr constant)
takeIt - Is this a TAKE (or is it [false] a READ)
recovery - true if being called as part of store recovery.
Returns:
true if the entry could be grabbed.
Throws:
NullPointerException - if handle is null.

recoverTake

void recoverTake(EntryHandle handle,
                 Txn txn)
Recover a logged take.

Parameters:
handle - The EntryHandle of the entry who's take is being logged.
txn - If non-null the transaction the take was performed under.
Throws:
NullPointerException - if handle is null.

isExpired

private boolean isExpired(long now,
                          EntryHandle handle)
Return true if the entry held by the given handle has expired by the time in now.


getContentsHead

private EntryHandle getContentsHead()
Get the head of the contents list

Returns:
The head of the contents list, if it exists. null if the list is empty.

add

void add(EntryHandle handle,
         TransactableMgr txn)
Add new new entry to the holder. Assumes the lock on the handle is held if there is a possibility of concurrent access.

Parameters:
handle - The EntryHandle for the entry being added.
txn - If the add is being done under a transaction the TransactableMgr for that transaction.
Throws:
NullPointerException - if handle is null.

supertypes

String[] supertypes()
Return an array of the class names of the super classes of the entries in this holder, or null if the holder is empty.


contents

RepEnum contents(TransactableMgr mgr)
Return an enumerator over the contents of this space that are visible from the given mgr.


continuingQuery

EntryHolder.ContinuingQuery continuingQuery(EntryRep[] tmpls,
                                            TransactableMgr txn,
                                            boolean takeThem,
                                            long now)
Return an object that can be used to perform a query that can return multiple matches and be restarted in another thread.

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
Returns:
a new ContinuingQuery object.

remove

boolean remove(EntryHandle h,
               boolean recovery)
Remove the given handle from this holder and the idMap. If the handle isn't in this holder, this does nothing.

Parameters:
h - the EntryHandle to remove.
recovery - true if being called as part of log recovery.
Returns:
true if this call removed h and false otherwise.

handleFor

private EntryHandle handleFor(EntryRep rep)
Return the handle for the given EntryRep object. This is done via lookup in the idMap. The idMap is doing double duty here. The LeaseDesc associated with an EntryRep is also the rep's EntryHandle.


reap

void reap()
Reap the expired elements (and the underlying FastList)



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