com.sun.jini.outrigger
Class TemplateHandle

java.lang.Object
  extended by com.sun.jini.outrigger.FastList.Node
      extended by com.sun.jini.outrigger.BaseHandle
          extended by com.sun.jini.outrigger.TemplateHandle

 class TemplateHandle
extends BaseHandle

TemplateHandle associates one or more TransitionWatchers with a template. Unless otherwise noted all methods are thread safe.


Field Summary
private  Vector descs
          A cache of the EntryHandleTmplDesc indexed by the number of fields.
private  WatchersForTemplateClass owner
          The WatchersForTemplateClass this object belongs to.
private  Set watchers
          The watchers.
 
Constructor Summary
TemplateHandle(EntryRep tmpl, WatchersForTemplateClass owner)
          Create a handle for the template tmpl.
 
Method Summary
(package private)  void addTransitionWatcher(TransitionWatcher watcher)
          Add a watcher to this handle.
(package private)  void collectInterested(Set set, EntryTransition transition, long ordinal)
          Iterate over the watchers associated with this handle calling isInterested on each and if it returns true adding the watcher to the passed set.
(package private)  EntryHandleTmplDesc descFor(int numFields)
          Return the description for the given field count.
(package private)  OutriggerServerImpl getServer()
          Return the OutriggerServerImpl this handle is part of.
(package private)  boolean isEmpty()
          Return true if there are no watchers associated with this object and false otherwise.
(package private)  boolean matches(EntryRep entry)
          Return true if this template matches the given entry.
(package private)  void reap(long now)
          Visit each TransitionWatcher and check to see if it has expired, removing it if it has.
(package private)  void removeTransitionWatcher(TransitionWatcher watcher)
          Remote a watcher from this handle.
 
Methods inherited from class com.sun.jini.outrigger.BaseHandle
classFor, rep
 
Methods inherited from class com.sun.jini.outrigger.FastList.Node
markOnList, removed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

descs

private final Vector descs
A cache of the EntryHandleTmplDesc indexed by the number of fields.


watchers

private final Set watchers
The watchers. We use a HashSet because we will probably do a fair number of removals for each traversal and the number of watchers managed by one TemplateHandle will probably never get very large. If this does become an issue making TransitionWatcher extend FastList.Node and using a FastList here would probably be a good choice (though that would require changing FastList to support overlapping traversals of different lists from the same thread.)


owner

private final WatchersForTemplateClass owner
The WatchersForTemplateClass this object belongs to.

Constructor Detail

TemplateHandle

TemplateHandle(EntryRep tmpl,
               WatchersForTemplateClass owner)
Create a handle for the template tmpl.

Method Detail

descFor

EntryHandleTmplDesc descFor(int numFields)
Return the description for the given field count.


matches

boolean matches(EntryRep entry)
Return true if this template matches the given entry.


addTransitionWatcher

void addTransitionWatcher(TransitionWatcher watcher)
Add a watcher to this handle. Assumes that the handle has not been removed from its FastList and that the caller owns the lock on this.

Parameters:
watcher - the watcher to be added.
Throws:
NullPointerException - if watcher is null.

removeTransitionWatcher

void removeTransitionWatcher(TransitionWatcher watcher)
Remote a watcher from this handle. Does nothing if the specified watcher is not associated with this TemplateHandle.

Parameters:
watcher - the watcher to be removed.
Throws:
NullPointerException - if watcher is null.

collectInterested

void collectInterested(Set set,
                       EntryTransition transition,
                       long ordinal)
Iterate over the watchers associated with this handle calling isInterested on each and if it returns true adding the watcher to the passed set.

Parameters:
set - The set to accumulate interested watchers into.
transition - The transition being processed.
ordinal - The ordinal associated with transition.
Throws:
NullPointerException - if either argument is null.

getServer

OutriggerServerImpl getServer()
Return the OutriggerServerImpl this handle is part of.

Returns:
The OutriggerServerImpl this handle is part of.

reap

void reap(long now)
Visit each TransitionWatcher and check to see if it has expired, removing it if it has.

Parameters:
now - an estimate of the current time expressed as milliseconds since the beginning of the epoch.

isEmpty

boolean isEmpty()
Return true if there are no watchers associated with this object and false otherwise. Assumes the call holds the lock on this.

Returns:
true if there are no watchers in this handle.


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