com.sun.jini.lease
Class AbstractLease

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

public abstract class AbstractLease
extends Object
implements Lease, Serializable

A base class for implementing lease objects. This class takes care of absolute vs relative time issues and implements some of the Lease methods. The subclass is responsible for implementing: doRenew, cancel, createLeaseMap, canBatch, hashCode, equals, and serialization of any subclass state.

Author:
Sun Microsystems, Inc.
See Also:
Serialized Form

Field Summary
protected  long expiration
          The lease expiration, in local absolute time.
protected  int serialFormat
          Serialization format for the expiration.
private static long serialVersionUID
           
 
Fields inherited from interface net.jini.core.lease.Lease
ABSOLUTE, ANY, DURATION, FOREVER
 
Constructor Summary
protected AbstractLease(long expiration)
          Construct a relative-format lease.
 
Method Summary
protected abstract  long doRenew(long duration)
          Renew the lease for a duration relative to now, and return the duration actually granted.
 long getExpiration()
          Return the lease expiration.
 int getSerialFormat()
          Return the serialization format for the expiration.
private  void readObject(ObjectInputStream stream)
          If serialFormat is DURATION, add the current time to the expiration, to make it absolute (and if the result of the addition is negative, correct the overflow by resetting the expiration to Long.MAX_VALUE).
private  void readObjectNoData()
          Throws an InvalidObjectException.
 void renew(long duration)
          Renew the lease for a duration relative to now.
 void setSerialFormat(int format)
          Set the serialization format for the expiration.
private  void writeObject(ObjectOutputStream stream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.jini.core.lease.Lease
canBatch, cancel, createLeaseMap
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

expiration

protected transient long expiration
The lease expiration, in local absolute time.


serialFormat

protected int serialFormat
Serialization format for the expiration.

Constructor Detail

AbstractLease

protected AbstractLease(long expiration)
Construct a relative-format lease.

Method Detail

getExpiration

public long getExpiration()
Return the lease expiration.

Specified by:
getExpiration in interface Lease
Returns:
a long that indicates the time that the lease will expire

getSerialFormat

public int getSerialFormat()
Return the serialization format for the expiration.

Specified by:
getSerialFormat in interface Lease
Returns:
an int representing the serial format value
See Also:
Lease.setSerialFormat(int)

setSerialFormat

public void setSerialFormat(int format)
Set the serialization format for the expiration.

Specified by:
setSerialFormat in interface Lease
Parameters:
format - DURATION or ABSOLUTE
See Also:
Lease.getSerialFormat()

renew

public void renew(long duration)
           throws UnknownLeaseException,
                  LeaseDeniedException,
                  RemoteException
Renew the lease for a duration relative to now.

Specified by:
renew in interface Lease
Parameters:
duration - the requested duration in milliseconds
Throws:
UnknownLeaseException - the lease being renewed is unknown to the lease grantor
LeaseDeniedException - the lease grantor is unable or unwilling to renew the lease
RemoteException

doRenew

protected abstract long doRenew(long duration)
                         throws UnknownLeaseException,
                                LeaseDeniedException,
                                RemoteException
Renew the lease for a duration relative to now, and return the duration actually granted.

Throws:
UnknownLeaseException
LeaseDeniedException
RemoteException

writeObject

private void writeObject(ObjectOutputStream stream)
                  throws IOException
Throws:
IOException

readObjectNoData

private void readObjectNoData()
                       throws InvalidObjectException
Throws an InvalidObjectException.

Throws:
InvalidObjectException - unconditionally

readObject

private void readObject(ObjectInputStream stream)
                 throws IOException,
                        ClassNotFoundException
If serialFormat is DURATION, add the current time to the expiration, to make it absolute (and if the result of the addition is negative, correct the overflow by resetting the expiration to Long.MAX_VALUE).

Throws:
InvalidObjectException - if serialFormat is neither ABSOLUTE nor DURATION
IOException
ClassNotFoundException


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