com.sun.jini.outrigger
Class AvailabilityRegistrationWatcher

java.lang.Object
  extended by com.sun.jini.outrigger.TransitionWatcher
      extended by com.sun.jini.outrigger.AvailabilityRegistrationWatcher
All Implemented Interfaces:
LeasedResource, EventRegistrationRecord, Comparable
Direct Known Subclasses:
StorableAvailabilityWatcher, TransactableAvailabilityWatcher

abstract class AvailabilityRegistrationWatcher
extends TransitionWatcher
implements EventRegistrationRecord

Subclass of TransitionWatcher for availability event registrations. Also represents the event registration itself.


Nested Class Summary
private  class AvailabilityRegistrationWatcher.VisibilityEventSender
          Common implementation of EventSender for visibility events
 
Field Summary
(package private)  Uuid cookie
          The UUID that identifies this registration Only for use by subclasses.
private  long currentSeqNum
          The current sequence number.
(package private)  long eventID
          The event ID associated with this registration Protected, but only for use by subclasses.
(package private)  long expiration
          The current expiration time of the registration Protected, but only for use by subclasses.
(package private)  MarshalledObject handback
          The handback associated with this registration.
private  Set owners
          The TemplateHandles associated with this watcher.
private  OutriggerServerImpl server
          The OutriggerServerImpl we are part of.
(package private)  boolean visibilityOnly
          true if client is interested in only visibility events, false otherwise.
 
Fields inherited from class com.sun.jini.outrigger.TransitionWatcher
startOrdinal
 
Constructor Summary
AvailabilityRegistrationWatcher(long timestamp, long startOrdinal, long currentSeqNum)
          Used during log recovery to create a mostly empty AvailabilityRegistrationWatcher.
AvailabilityRegistrationWatcher(long timestamp, long startOrdinal, Uuid cookie, boolean visibilityOnly, MarshalledObject handback, long eventID)
          Create a new AvailabilityRegistrationWatcher.
 
Method Summary
(package private)  boolean addTemplateHandle(TemplateHandle h)
          Associate a TemplateHandle with this object.
 boolean cancel()
          Make sure this object will be removed from the system independent of the expiration time.
(package private)  void cleanup(OutriggerServerImpl server, boolean expired)
          Overridden by subclasses if there is any cleanup work they need to do as part of cancel or removeIfExpired.
private  boolean doRemove(long now, boolean doIt)
          The heavy lifting of removing ourselves.
 Uuid getCookie()
          Get the unique identifier associated with this object.
 long getExpiration()
          Get the expiration time of this object.
(package private) abstract  RemoteEventListener getListener(ProxyPreparer preparer)
          Return the remote listener associated with this EventRegistrationWatcher.
(package private)  void process(EntryTransition transition, long now)
          Process the given transition by queuing up a task with the notifier for event delivery.
(package private)  void removeIfExpired(long now)
          Remove this watcher from the system if it has expired.
 void setExpiration(long newExpiration)
          Set the expiration time of this object.
 
Methods inherited from class com.sun.jini.outrigger.TransitionWatcher
compareTo, isInterested
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expiration

long expiration
The current expiration time of the registration Protected, but only for use by subclasses.


cookie

Uuid cookie
The UUID that identifies this registration Only for use by subclasses. Should not be changed.


handback

MarshalledObject handback
The handback associated with this registration. Only for use by subclasses. Should not be changed.


visibilityOnly

boolean visibilityOnly
true if client is interested in only visibility events, false otherwise. Only for use by subclasses. Should not be changed.


eventID

long eventID
The event ID associated with this registration Protected, but only for use by subclasses. Should not be changed.


currentSeqNum

private long currentSeqNum
The current sequence number.


owners

private Set owners
The TemplateHandles associated with this watcher.


server

private OutriggerServerImpl server
The OutriggerServerImpl we are part of.

Constructor Detail

AvailabilityRegistrationWatcher

AvailabilityRegistrationWatcher(long timestamp,
                                long startOrdinal,
                                long currentSeqNum)
Used during log recovery to create a mostly empty AvailabilityRegistrationWatcher.

Note, we set the time stamp and tie-breaker here instead of getting them from the log. This means they will be inconstant with their value from the last VM we were in, but since they never leak out and events are read-only anyway this should not be a problem (this also allows us to keep the tie-breaker and time stamp in final fields).

Parameters:
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.
currentSeqNum - Sequence number to start with.

AvailabilityRegistrationWatcher

AvailabilityRegistrationWatcher(long timestamp,
                                long startOrdinal,
                                Uuid cookie,
                                boolean visibilityOnly,
                                MarshalledObject handback,
                                long eventID)
Create a new AvailabilityRegistrationWatcher.

Parameters:
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.
cookie - The unique identifier associated with this watcher. Must not be null.
visibilityOnly - pass true if client only wants visibility events
handback - The handback object that should be sent along with event notifications to the the listener.
eventID - The event ID for event type represented by this object.
Throws:
NullPointerException - if the cookie argument is null.
Method Detail

process

void process(EntryTransition transition,
             long now)
Process the given transition by queuing up a task with the notifier for event delivery. Assumes the passed entry matches the template in the TemplateHandle associated with this watcher and that isInterested returned true. 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 occurred).
Throws:
NullPointerException - if transition is null.

getListener

abstract RemoteEventListener getListener(ProxyPreparer preparer)
                                  throws ClassNotFoundException,
                                         IOException
Return the remote listener associated with this EventRegistrationWatcher. Optionally prepare the listener if it has been recovered from the store and not yet re-prepared.

Returns:
the remote listener associated with this EventRegistrationWatcher
Throws:
IOException - if the listener can not be unmarshalled. May throw RemoteException if the call to the preparer does
ClassNotFoundException - if the listener needs to be unmarshalled and a necessary class can not be found
SecurityException - if the prepareProxy call does.

addTemplateHandle

boolean addTemplateHandle(TemplateHandle h)
Associate a TemplateHandle with this object. May call more than once.

Specified by:
addTemplateHandle in class TransitionWatcher
Parameters:
h - The TemplateHandle associate with this watcher
Returns:
true if the handle was successfully added, and false if the watcher has already been removed
Throws:
NullPointerException - if h is null

setExpiration

public void setExpiration(long newExpiration)
Set the expiration time of this object. This method may be called before setTemplateHandle is called. Assumes locking is handled by the caller.

Specified by:
setExpiration in interface LeasedResource
Parameters:
newExpiration - The expiration time.

getExpiration

public long getExpiration()
Description copied from class: TransitionWatcher
Get the expiration time of this object. This method may be called before addTemplateHandle is called. Assumes locking is handled by the caller.

Specified by:
getExpiration in interface LeasedResource
Specified by:
getExpiration in class TransitionWatcher
Returns:
The time (in milliseconds since the beginning of the epoch) when this watcher is no longer relevant.

getCookie

public Uuid getCookie()
Get the unique identifier associated with this object. This method may be called before setTemplateHandle is called.

Specified by:
getCookie in interface LeasedResource
Returns:
The unique identifier associated with this watcher.

cleanup

void cleanup(OutriggerServerImpl server,
             boolean expired)
Overridden by subclasses if there is any cleanup work they need to do as part of cancel or removeIfExpired. Called after releasing the lock on this. Will be called at most once.

Parameters:
server - A reference to the top level server object.
expired - true if being called from removeIfExpired and false otherwise.

doRemove

private boolean doRemove(long now,
                         boolean doIt)
The heavy lifting of removing ourselves.

Parameters:
now - The current time (or a bit earlier).
doIt - If true ignore now and just remove this object.
Returns:
true if this call removed this object, false if it had already been done. Should be ignored if doIt is false.

removeIfExpired

void removeIfExpired(long now)
Description copied from class: TransitionWatcher
Remove this watcher from the system if it has expired. Responsible for calling the remove method of the associated TemplateHandle. This method can be called more than once, though second and subsequent calls may have no effect.

Specified by:
removeIfExpired in class TransitionWatcher
Parameters:
now - An estimate of the current time that must be less than or equal to the current time.

cancel

public boolean cancel()
Description copied from interface: EventRegistrationRecord
Make sure this object will be removed from the system independent of the expiration time.

Specified by:
cancel in interface EventRegistrationRecord
Returns:
true if this call was the first removal attempt.


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