com.sun.jini.norm
Class LeaseSet

java.lang.Object
  extended by com.sun.jini.norm.LeaseSet
All Implemented Interfaces:
LeasedResource, Serializable

 class LeaseSet
extends Object
implements Serializable, LeasedResource

Norm's internal representation of LeaseRenewalSets. Unless otherwise noted the methods of this class assume synchronization being handled by the caller.

Author:
Sun Microsystems, Inc.

Nested Class Summary
(package private) static class LeaseSet.ChangeSetExpiration
          Class used to log changes to the set expiration time.
private static class LeaseSet.ExpirationTime
          Utility class that holds and guards the second copy of our expiration time.
private static class LeaseSet.FailureEventRegistration
          Class used to log changes to failure event registrations
private static class LeaseSet.RemoveClientLease
          Class used to log the removal of a client lease from the set
private static class LeaseSet.RenewalFailure
          Class used to log a renewal failure
private static class LeaseSet.UpdateClientLease
          Class used to log adding or updating a client lease to the set
private static class LeaseSet.WarningEventRegistration
          Class used to log changes to warning event registrations
private  class LeaseSet.WarningFactory
          Nested class that implements EventFactory that generates ExpirationWarningEvents.
 
Field Summary
private  long expiration
          Expiration time of the set
private  LeaseSet.ExpirationTime expiration2
          We keep two copies of the expiration time guarded by different locks so the the client lease renewal threads don't have to wait on the set's lock.
private  EventType failureEventType
          The event type for failure events
private  Uuid ID
          ID that uniquely identifies this set
private  Set leases
          A collection of the client leases in this set (in wrapped form).
private  LeaseTable leaseTable
          A table that maps client leases to client lease wrappers.
private  long minWarning
          Time before expiration to send expiration warning events
private  NormServerBaseImpl normServerBaseImpl
          The NormServerBaseImpl are attached to
private static long serialVersionUID
           
private  PersistentStore store
          PersistentStore that changes should be logged to.
private  EventType warningEventType
          The event type for expiration warning events
private  long warningSeqNum
          The current sequence number for expiration warning events
 
Constructor Summary
LeaseSet(Uuid ID, EventTypeGenerator generator, PersistentStore store, NormServerBaseImpl normServerBaseImpl)
          Simple constructor.
 
Method Summary
(package private)  void addToLeaseTable(ClientLeaseWrapper clw)
          Add a lease already in the lease set to the lease table.
(package private)  void definiteException(EventType type, RemoteEvent ev, long registrationNumber)
          If the passed registrationNumber number matches the current registrationNumber for the passed event clear the current registration and persist the change
(package private)  Set destroy()
          Destroy a lease set
(package private)  boolean doesContainWrapper(ClientLeaseWrapper clw)
          Return true if the passed wrapper is in the set
(package private)  boolean ensureCurrent(long now)
          This method is used by the client lease renewal threads to make sure that the set associated with the lease they are renewing is non-expired.
(package private)  ClientLeaseWrapper getClientLeaseWrapper(Lease clientLease)
          Return the wrapper for the specified client lease, or null if not found.
 Uuid getCookie()
          Returns the universally unique identifier associated with this lease.
 long getExpiration()
          Returns the expiration time of the lease.
(package private)  MarshalledInstance[] getLeases()
          Return an array of leases in marshalled form.
(package private)  Uuid getUuid()
          Return the Uuid for this set.
(package private)  long getWarningTime()
          Return the absolute time when a expiration warning should be sent.
(package private)  boolean haveWarningRegistration()
          Return true if there is a non-null listener registered for the expiration warning event.
protected  boolean isolateSets()
          Returns whether to isolate renewal sets or batch leases across sets for all lease renewal sets associated with this set's service.
(package private)  void logRenewal(ClientLeaseWrapper clw)
          Log the renewal of a client lease.
private  SetProxy newSetProxy()
          Create a new SetProxy for this set that has a lease with the current expiration
private  void readObject(ObjectInputStream in)
          Override readObject so we can restore expiration2
(package private)  boolean remove(ClientLeaseWrapper clw)
          Remove the specified wrapped client lease from the set.
private  boolean removeInternal(ClientLeaseWrapper clw)
          Utility method to remove a client lease.
(package private)  void renewalFailure(ClientLeaseWrapper clw)
          Handle failures to renew a lease by removing the lease from the set and if needed schedule sending an event.
private  boolean replace(ClientLeaseWrapper clw)
          Utility method to replace a client lease in the lease set.
(package private)  Iterator restoreTransientState(EventTypeGenerator generator, PersistentStore store, NormServerBaseImpl normServerBaseImpl, ProxyPreparer recoveredListenerPreparer)
          Restore the transient state of the set that can't be restored automatically after a log recovery.
(package private)  void sendWarningEvent()
          Send an expiration warning event for this set
 void setExpiration(long newExpiration)
          Changes the expiration time of the lease.
(package private)  EventRegistration setExpirationWarningListener(RemoteEventListener listener, long minWarning, MarshalledObject handback)
          Set/update/clear the expiration warning listener.
(package private)  EventRegistration setRenewalFailureListener(RemoteEventListener listener, MarshalledObject handback)
          Set/update/clear the renewal failure listener
 String toString()
          Returns a string representation of this object.
(package private)  void update(ClientLeaseWrapper clw)
          Add or update the specified wrapped client lease to the set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

expiration

private long expiration
Expiration time of the set


expiration2

private transient LeaseSet.ExpirationTime expiration2
We keep two copies of the expiration time guarded by different locks so the the client lease renewal threads don't have to wait on the set's lock.


ID

private final Uuid ID
ID that uniquely identifies this set


leases

private final Set leases
A collection of the client leases in this set (in wrapped form).


leaseTable

private transient LeaseTable leaseTable
A table that maps client leases to client lease wrappers.


minWarning

private long minWarning
Time before expiration to send expiration warning events


warningEventType

private EventType warningEventType
The event type for expiration warning events


warningSeqNum

private long warningSeqNum
The current sequence number for expiration warning events


failureEventType

private EventType failureEventType
The event type for failure events


store

private transient PersistentStore store
PersistentStore that changes should be logged to.


normServerBaseImpl

private transient NormServerBaseImpl normServerBaseImpl
The NormServerBaseImpl are attached to

Constructor Detail

LeaseSet

LeaseSet(Uuid ID,
         EventTypeGenerator generator,
         PersistentStore store,
         NormServerBaseImpl normServerBaseImpl)
Simple constructor. Note expiration will be set when we allocate a lease for this set.

Parameters:
ID - for this set
generator - object set can use to create new event type objects
store - PersistentStore that changes should be logged to
normServerBaseImpl - the NormServerBaseImpl that created this set
Method Detail

readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Override readObject so we can restore expiration2

Throws:
IOException
ClassNotFoundException

restoreTransientState

Iterator restoreTransientState(EventTypeGenerator generator,
                               PersistentStore store,
                               NormServerBaseImpl normServerBaseImpl,
                               ProxyPreparer recoveredListenerPreparer)
Restore the transient state of the set that can't be restored automatically after a log recovery.

Parameters:
generator - event type generator associated with this set's events
store - PersistentStore that changes should be logged to
normServerBaseImpl - the normServerBaseImpl that created this set
recoveredListenerPreparer - the proxy preparer to use to prepare recovered listeners
Returns:
an iterator over the set of client leases

getClientLeaseWrapper

ClientLeaseWrapper getClientLeaseWrapper(Lease clientLease)
Return the wrapper for the specified client lease, or null if not found.


replace

private boolean replace(ClientLeaseWrapper clw)
Utility method to replace a client lease in the lease set. Returns true if an equal lease was not already present. Does not update the lease table.


update

void update(ClientLeaseWrapper clw)
Add or update the specified wrapped client lease to the set.

Parameters:
clw - lease to be added or updated

addToLeaseTable

void addToLeaseTable(ClientLeaseWrapper clw)
Add a lease already in the lease set to the lease table. Used during recovery to add the wrapper to the lease table only after it has been given its recovery proxy preparer and attempting to unpack the lease has attempted.


doesContainWrapper

boolean doesContainWrapper(ClientLeaseWrapper clw)
Return true if the passed wrapper is in the set


removeInternal

private boolean removeInternal(ClientLeaseWrapper clw)
Utility method to remove a client lease. Returns true if the lease is removed.


remove

boolean remove(ClientLeaseWrapper clw)
Remove the specified wrapped client lease from the set.

Parameters:
clw - lease to removed
Returns:
false if the lease has already been removed, or if logically the lease is no longer in the set (e.g. its membership expiration has been reached)

destroy

Set destroy()
Destroy a lease set

Returns:
a Set with all of the sets WrappedClientLeases

getLeases

MarshalledInstance[] getLeases()
Return an array of leases in marshalled form. For each lease we have in unmarshalled form serialize using the duration format, for each lease we can't unmarshal just use the MarshalledInstance we have on hand. If the set is empty return null.


setExpirationWarningListener

EventRegistration setExpirationWarningListener(RemoteEventListener listener,
                                               long minWarning,
                                               MarshalledObject handback)
                                         throws IOException
Set/update/clear the expiration warning listener.

Parameters:
listener - the new listener
minWarning - how long before the lease on the set expires should the event be sent
handback - the new handback
Returns:
if listener is non-null return an EventRegistration otherwise return null
Throws:
IOException - if listener cannot be serialized

setRenewalFailureListener

EventRegistration setRenewalFailureListener(RemoteEventListener listener,
                                            MarshalledObject handback)
                                      throws IOException
Set/update/clear the renewal failure listener

Parameters:
listener - the new listener
handback - the new handback
Returns:
if listener is non-null return an EventRegistration otherwise return null
Throws:
IOException - if listener can not be serialized

renewalFailure

void renewalFailure(ClientLeaseWrapper clw)
Handle failures to renew a lease by removing the lease from the set and if needed schedule sending an event.

Parameters:
clw - the wrapped client lease for the lease that could not be removed

sendWarningEvent

void sendWarningEvent()
Send an expiration warning event for this set


newSetProxy

private SetProxy newSetProxy()
Create a new SetProxy for this set that has a lease with the current expiration


haveWarningRegistration

boolean haveWarningRegistration()
Return true if there is a non-null listener registered for the expiration warning event.

Note, this method assumes the current thread owns the set's lock


getWarningTime

long getWarningTime()
Return the absolute time when a expiration warning should be sent.


logRenewal

void logRenewal(ClientLeaseWrapper clw)
Log the renewal of a client lease.

Parameters:
clw - the wrapper for the client lease that was renewed

setExpiration

public void setExpiration(long newExpiration)
Description copied from interface: LeasedResource
Changes the expiration time of the lease.

Specified by:
setExpiration in interface LeasedResource
Parameters:
newExpiration - The new expiration time in milliseconds since the beginning of the epoch

getExpiration

public long getExpiration()
Description copied from interface: LeasedResource
Returns the expiration time of the lease.

Specified by:
getExpiration in interface LeasedResource
Returns:
The expiration time in milliseconds since the beginning of the epoch

ensureCurrent

boolean ensureCurrent(long now)
This method is used by the client lease renewal threads to make sure that the set associated with the lease they are renewing is non-expired. Note, the method check expiration2, not expiration so the renewal thread does not need to block on the set's lock.

Parameters:
now - the current time in milliseconds since the beginning of the epoch

getCookie

public Uuid getCookie()
Description copied from interface: LeasedResource
Returns the universally unique identifier associated with this lease. Any proxies for this lease that implement ReferentUuid should return this object from their getReferentUuid method and should base their implementation of equals on this object.

Specified by:
getCookie in interface LeasedResource

getUuid

Uuid getUuid()
Return the Uuid for this set.


definiteException

void definiteException(EventType type,
                       RemoteEvent ev,
                       long registrationNumber)
If the passed registrationNumber number matches the current registrationNumber for the passed event clear the current registration and persist the change


isolateSets

protected boolean isolateSets()
Returns whether to isolate renewal sets or batch leases across sets for all lease renewal sets associated with this set's service.


toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object


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