com.sun.jini.fiddler
Class FiddlerLease

java.lang.Object
  extended by com.sun.jini.lease.AbstractLease
      extended by com.sun.jini.fiddler.FiddlerLease
All Implemented Interfaces:
Serializable, Lease, ReferentUuid
Direct Known Subclasses:
FiddlerLease.ConstrainableFiddlerLease

 class FiddlerLease
extends AbstractLease
implements ReferentUuid

When the Fiddler implementation of the lookup discovery service grants a lease on a registration requested by a client, a proxy to that lease is provided to allow the client to interact with the granted lease. This class is the implementation of that proxy.

Clients only see instances of this class via the Lease interface.

Author:
Sun Microsystems, Inc.

Nested Class Summary
(package private) static class FiddlerLease.ConstrainableFiddlerLease
          The constrainable version of the class FiddlerLease.
 
Field Summary
(package private)  Uuid leaseID
          The internal identifier assigned to this lease by the granting entity.
(package private)  Uuid registrationID
          The unique identifier assigned by the lookup discovery service to the registration to which this lease corresponds.
private static long serialVersionUID
           
(package private)  Fiddler server
          The reference to the back-end server of the lookup discovery service that granted this lease (the granting entity).
(package private)  Uuid serverID
          The unique ID associated with the server referenced in this class (used to compare server references).
 
Fields inherited from class com.sun.jini.lease.AbstractLease
expiration, serialFormat
 
Fields inherited from interface net.jini.core.lease.Lease
ABSOLUTE, ANY, DURATION, FOREVER
 
Constructor Summary
private FiddlerLease(Fiddler server, Uuid serverID, Uuid registrationID, Uuid leaseID, long expiration)
          Constructs a proxy to the lease the Fiddler implementation of the lookup discovery service places on a client's requested registration.
 
Method Summary
 boolean canBatch(Lease lease)
          Examines the input parameter to determine if that parameter, along with the current lease (the current instance of this class), can be batched in a LeaseMap.
 void cancel()
          This method allows the entity to which the current lease is granted (the lease holder) to indicate that it is no longer interested in the resources provided to the entity by the lookup discovery service.
static FiddlerLease createLease(Fiddler server, Uuid serverID, Uuid registrationID, Uuid leaseID, long expiration)
          Public static factory method that creates and returns an instance of FiddlerLease.
 LeaseMap createLeaseMap(long duration)
          Creates a LeaseMap object that can contain leases whose renewal or cancellation can be batched.
protected  long doRenew(long duration)
          This method allows the entity to which the current lease is granted (the lease holder) to indicate that it is still interested in the resources of the lookup discovery service, and to request continued access to those resources for an amount of time (in milliseconds) relative to the current time.
 boolean equals(Object obj)
          For any instance of this class, indicates whether the object input to this method is equal to the current instance of this class; where equality of leases granted by a lookup discovery service is defined by reference equality.
(package private)  Uuid getLeaseID()
          Returns the identifier assigned to the current lease by the entity that granted it.
 Uuid getReferentUuid()
          Returns the universally unique identifier that has been assigned to the resource this proxy represents.
(package private)  Uuid getRegistrationID()
          Returns the unique identifier assigned by the lookup discovery service to the registration to which the current lease corresponds.
(package private)  Fiddler getServer()
          Returns a reference to the back-end server of the lookup discovery service that granted this lease.
(package private)  Uuid getServerID()
          Returns the unique ID associated with the server referenced in this class.
 int hashCode()
          For any instance of this class, returns the hashcode value generated by the hashCode method of the lease ID associated with the current instance of this lease.
private  void readObject(ObjectInputStream s)
          When an instance of this class is deserialized, this method is automatically invoked.
private  void readObjectNoData()
          During deserialization of an instance of this class, if it is found that the stream contains no data, this method is automatically invoked.
(package private)  void setExpiration(long expiration)
          Replaces the current value of the expiration field (defined in the AbstractLease super class) with the value contained in the input parameter.
 
Methods inherited from class com.sun.jini.lease.AbstractLease
getExpiration, getSerialFormat, renew, setSerialFormat
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

server

final Fiddler server
The reference to the back-end server of the lookup discovery service that granted this lease (the granting entity).


serverID

final Uuid serverID
The unique ID associated with the server referenced in this class (used to compare server references).


registrationID

final Uuid registrationID
The unique identifier assigned by the lookup discovery service to the registration to which this lease corresponds.


leaseID

final Uuid leaseID
The internal identifier assigned to this lease by the granting entity.

Constructor Detail

FiddlerLease

private FiddlerLease(Fiddler server,
                     Uuid serverID,
                     Uuid registrationID,
                     Uuid leaseID,
                     long expiration)
Constructs a proxy to the lease the Fiddler implementation of the lookup discovery service places on a client's requested registration. The lease corresponding to the constructed proxy will have as its expiration time, the time input to the expiration parameter.

Parameters:
server - reference to the back-end server of the lookup discovery service that granted this lease (the granting entity)
serverID - the service ID of the service referenced by the server parameter
registrationID - unique identifier assigned to the registration to which this lease corresponds
leaseID - identifier assigned to this lease by the granting entity
expiration - the time of expiration of the lease being granted
Method Detail

createLease

public static FiddlerLease createLease(Fiddler server,
                                       Uuid serverID,
                                       Uuid registrationID,
                                       Uuid leaseID,
                                       long expiration)
Public static factory method that creates and returns an instance of FiddlerLease. If the server associated with this proxy implements RemoteMethodControl, then the object returned by this method will also implement RemoteMethodControl.

Parameters:
server - reference to the server object through which communication occurs between the client-side and server-side of the associated service.
serverID - the service ID of the service referenced by the server parameter
registrationID - the unique identifier assigned by the service to each instance of this proxy
leaseID - identifier assigned to this lease by the granting entity
expiration - the time of expiration of the lease being granted
Returns:
an instance of FiddlerLease that implements RemoteMethodControl if the given server does.

createLeaseMap

public LeaseMap createLeaseMap(long duration)
Creates a LeaseMap object that can contain leases whose renewal or cancellation can be batched. Additionally, upon creating the map the current lease is placed in the map as a key, and the value of the duration parameter is placed in the map as the lease's corresponding mapped value of type Long.

Specified by:
createLeaseMap in interface Lease
Parameters:
duration - the amount of time (in milliseconds) during which the lease being placed in the map will remain in effect. This value will be converted to an instance of Long prior to being placed in the map with its associated lease. the lease in the map.
Returns:
an instance of LeaseMap that contains as its first mapping, the ordered pair consisting of this lease and the value of the duration parameter.
See Also:
Lease.createLeaseMap(long)

canBatch

public boolean canBatch(Lease lease)
Examines the input parameter to determine if that parameter, along with the current lease (the current instance of this class), can be batched in a LeaseMap.

For this implementation of the service, two leases can be batched (placed in the same service-specific instance of LeaseMap) if those leases satisfy the following conditions:


getServer

Fiddler getServer()
Returns a reference to the back-end server of the lookup discovery service that granted this lease.

Returns:
an instance of the Fiddler implementation of the lookup discovery service.

getServerID

Uuid getServerID()
Returns the unique ID associated with the server referenced in this class.

Returns:
an instance of the Uuid that contains the universally unique ID associated with the server referenced in this class.

getRegistrationID

Uuid getRegistrationID()
Returns the unique identifier assigned by the lookup discovery service to the registration to which the current lease corresponds.

Returns:
a net.jini.id.Uuid value corresponding to the unique ID assigned to the registration associated with the current lease.

getLeaseID

Uuid getLeaseID()
Returns the identifier assigned to the current lease by the entity that granted it.

Returns:
a long value corresponding to the ID assigned to the current lease.

setExpiration

void setExpiration(long expiration)
Replaces the current value of the expiration field (defined in the AbstractLease super class) with the value contained in the input parameter. The value contained in the expiration field represents the absolute (non-relative) time (in milliseconds) at which the current lease will expire.

Parameters:
expiration - the new value of the expiration field

cancel

public void cancel()
            throws UnknownLeaseException,
                   RemoteException
This method allows the entity to which the current lease is granted (the lease holder) to indicate that it is no longer interested in the resources provided to the entity by the lookup discovery service. When an entity invokes this method, the overall effect is the same as if the lease expired, except that expiration occurs immediately instead of at the end of a pre-agreed duration.

Specified by:
cancel in interface Lease
Throws:
UnknownLeaseException - this exception occurs when the lease being cancelled is unknown to the lease grantor.
RemoteException - typically, this exception occurs when there is a communication failure between the client and the server. When this exception does occur, the lease may or may not have been cancelled successfully.
See Also:
Lease.cancel()

doRenew

protected long doRenew(long duration)
                throws UnknownLeaseException,
                       RemoteException
This method allows the entity to which the current lease is granted (the lease holder) to indicate that it is still interested in the resources of the lookup discovery service, and to request continued access to those resources for an amount of time (in milliseconds) relative to the current time. That is, the duration is not added added to the current expiration, but is added to the current time.

Note that the duration of the renewed lease will be no greater than the requested duration, and may be less than that duration.

Specified by:
doRenew in class AbstractLease
Parameters:
duration - the requested duration for the lease being renewed
Returns:
long value representing the actual duration that was granted for the renewed lease. Note that the actual duration granted and returned by this method may be less than the duration requested.
Throws:
UnknownLeaseException - this exception occurs when the lease being renewed does not exist, or is unknown to the lease grantor; typically because the lease has expired.
RemoteException - typically, this exception occurs when there is a communication failure between the client and the server. When this exception does occur, the lease may or may not have been renewed successfully.
See Also:
Lease.renew(long), AbstractLease.renew(long), AbstractLease.doRenew(long)

getReferentUuid

public Uuid getReferentUuid()
Returns the universally unique identifier that has been assigned to the resource this proxy represents.

Specified by:
getReferentUuid in interface ReferentUuid
Returns:
the instance of Uuid that is associated with the resource this proxy represents. This method will not return null.
See Also:
ReferentUuid

hashCode

public int hashCode()
For any instance of this class, returns the hashcode value generated by the hashCode method of the lease ID associated with the current instance of this lease.

Overrides:
hashCode in class Object
Returns:
int value representing the hashcode for an instance of this class.

equals

public boolean equals(Object obj)
For any instance of this class, indicates whether the object input to this method is equal to the current instance of this class; where equality of leases granted by a lookup discovery service is defined by reference equality. That is, two leases are equal if they reference (are proxies to) the same backend lease server.

Overrides:
equals in class Object
Parameters:
obj - reference to the object that is to be compared to the object on which this method is invoked.
Returns:
true if the object input is referentially equal to the object on which this method is invoked; false otherwise.

readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
When an instance of this class is deserialized, this method is automatically invoked. This implementation of this method validates the state of the deserialized instance.

Throws:
InvalidObjectException - if the state of the deserialized instance of this class is found to be invalid.
IOException
ClassNotFoundException

readObjectNoData

private void readObjectNoData()
                       throws InvalidObjectException
During deserialization of an instance of this class, if it is found that the stream contains no data, this method is automatically invoked. Because it is expected that the stream should always contain data, this implementation of this method simply declares that something must be wrong.

Throws:
InvalidObjectException - to indicate that there was no data in the stream during deserialization of an instance of this class; declaring that something is wrong.
InvalidObjectException


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