class SetProxy extends AbstractProxy implements LeaseRenewalSet
Modifier and Type | Class and Description |
---|---|
(package private) static class |
SetProxy.ConstrainableSetProxy
Defines a subclass of SetProxy that implements RemoteMethodControl.
|
Modifier and Type | Field and Description |
---|---|
(package private) Lease |
ourLease
Lease for this set.
|
private static long |
serialVersionUID |
server, uuid
EXPIRATION_WARNING_EVENT_ID, RENEWAL_FAILURE_EVENT_ID
Modifier | Constructor and Description |
---|---|
private |
SetProxy(NormServer server,
Uuid id,
Lease lease)
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clearExpirationWarningListener()
Remove the listener currently registered for expiration warning
events.
|
void |
clearRenewalFailureListener()
Remove the listener currently registered for renewal failure
events.
|
(package private) static SetProxy |
create(NormServer server,
Uuid id,
Lease lease)
Creates a lease set proxy, returning an instance that implements
RemoteMethodControl if the server does.
|
Lease[] |
getLeases()
Returns all the leases currently in the set.
|
Lease |
getRenewalSetLease()
Returns the lease that controls the lifetime of this set.
|
private void |
readObject(ObjectInputStream in)
Require lease to be non-null.
|
private void |
readObjectNoData()
Require fields to be non-null.
|
Lease |
remove(Lease leaseToRemove)
Removes the specified lease from set.
|
void |
renewFor(Lease leaseToRenew,
long membershipDuration)
Include a client lease in the set for a specified duration.
|
void |
renewFor(Lease leaseToRenew,
long membershipDuration,
long renewDuration)
Include a client lease in the set for a specified duration and
with a specified renewal duration.
|
(package private) NormServer |
server2()
Returns a second server proxy for use by methods that represent a second
client-side method for a single server-side method.
|
EventRegistration |
setExpirationWarningListener(RemoteEventListener listener,
long minWarning,
MarshalledObject handback)
Register for the expiration warning event associated with this
set.
|
EventRegistration |
setRenewalFailureListener(RemoteEventListener listener,
MarshalledObject handback)
Register for the renewal failure event associated with this set.
|
equals, getReferentUuid, hashCode
private static final long serialVersionUID
final Lease ourLease
private SetProxy(NormServer server, Uuid id, Lease lease)
static SetProxy create(NormServer server, Uuid id, Lease lease)
server
- the server proxyid
- the ID of the lease setlease
- the lease set's leaseprivate void readObjectNoData() throws InvalidObjectException
InvalidObjectException
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public void renewFor(Lease leaseToRenew, long membershipDuration) throws RemoteException
LeaseRenewalSet
Calling this method is equivalent to making the following call on this set:
renewFor(leaseToRenew, desiredDuration, Lease.FOREVER)
renewFor
in interface LeaseRenewalSet
leaseToRenew
- the lease to be added to the renewal setmembershipDuration
- the maximum length of time in milliseconds
the leaseToRenew
should remain in the set, or
Lease.FOREVER
which implies there is no
pre-specified time when the lease should be removed from
the setRemoteException
- if a communication-related exception
occurspublic void renewFor(Lease leaseToRenew, long membershipDuration, long renewDuration) throws RemoteException
LeaseRenewalSet
The leaseToRenew
argument specifies the lease to be
added to the set. An IllegalArgumentException
must
be thrown if the lease was granted by the renewal service
itself. If leaseToRenew
is null
, a
NullPointerException
must be thrown.
The desiredDuration
argument is the number of
milliseconds the client would like the lease to remain in the
set. It is used to calculate the lease's initial desired
expiration by adding desiredDuration
to the current
time (as viewed by the service). If this causes an overflow, a
desired expiration of Long.MAX_VALUE
will be
used. Unlike a lease duration, the desired duration is
unilaterally specified by the client, not negotiated between the
client and the service. Note, a negative value for
desiredDuration
(including Lease.ANY
)
will result in a desired expiration that is in the past, causing
leaseToRenew
to be dropped from the set; this action
will neither result in an exception or an event.
If the actual expiration time of leaseToRenew
is
less than the current time (as viewed by the renewal service) and
the current time is less than the desired expiration time for
leaseToRenew
, the method will return
normally. However, leaseToRenew
will be dropped from
the set and a renewal failure event will be generated.
The renewDuration
is the initial renewal duration to
associate with leaseToRenew
(in milliseconds). If
desiredDuration
is exactly
Long.MAX_VALUE
, the renewDuration
may
be any positive number or Lease.ANY
; otherwise it
must be a positive number. If these requirements are not met, the
renewal service must throw an
IllegalArgumentException
.
Calling this method with a lease that is equivalent to a client
lease already in the set will associate the existing client lease
in the set with the new desired duration and renew duration. The
client lease is not replaced because it is more likely that the
renewal service, rather than the client, has an up-to-date lease
expiration. The service is more likely to have an up-to-date
expiration because the client should not be renewing a lease that
it has passed to a lease renewal service unless the lease is
removed first. These semantics also allow renewFor
to be used in an idempotent fashion.
renewFor
in interface LeaseRenewalSet
leaseToRenew
- the lease to be added to the renewal setmembershipDuration
- the maximum length of time in milliseconds
the leaseToRenew
should remain in the set, or
Lease.FOREVER
which implies there is no
pre-specified time when the lease should be removed from
the setrenewDuration
- the lease duration to request when renewing
the lease, unless renewDuration
is greater
than the remainder of the desiredDuration
RemoteException
- if a communication-related exception
occurspublic Lease remove(Lease leaseToRemove) throws RemoteException
LeaseRenewalSet
null
will
be returned. leaseToRemove
will not be
canceled by this call.remove
in interface LeaseRenewalSet
leaseToRemove
- lease to be removed from the setnull
if it was notRemoteException
- if a communication-related exception
occurspublic Lease[] getLeases() throws LeaseUnmarshalException, RemoteException
LeaseRenewalSet
getLeases
in interface LeaseRenewalSet
LeaseUnmarshalException
- if one or more of the leases can
not be unmarshalled. The throwing of a
LeaseUnmarshalException
represents a,
possibly transient, failure in the ability to unmarshal
one or more client leases in the set, it does not
necessarily imply anything about the state of the renewal
service or the set themselves.RemoteException
- if a communication-related exception
occurspublic EventRegistration setExpirationWarningListener(RemoteEventListener listener, long minWarning, MarshalledObject handback) throws RemoteException
LeaseRenewalSet
This method allows the client to register for notification of
the approaching expiration of the set's lease. The
listener
argument specifies what listener should
be notified when the lease is about to expire. The
minWarning
argument specifies a minimum number of
milliseconds before lease expiration that the first event
delivery attempt should be made by the service. The service may
also make subsequent delivery attempts if the first and any
subsequent attempts have been indeterminate. The
minWarning
argument must be zero or a positive
number; if it is not, an IllegalArgumentException
must be thrown. If the current expiration of the set's lease is
less than minWarning
milliseconds away, the event
will occur immediately (though it will take time to propagate
to the listener).
The handback
argument to this method specifies an
object that will be part of the expiration warning event
notification. This mechanism is detailed in the Jini
Distributed Event Specification.
This method returns the event registration for this event. The
Lease
object associated with the registration will
be equivalent (in the sense of equals
) to the
Lease
on the renewal set. Because the event
registration shares a lease with the set, clients that want to
just remove their expiration warning registration without
destroying the set should use the
clearExpirationWarningListener
method instead of
cancelling the registration's lease. The registration's event
ID will be
LeaseRenewalSet.EXPIRATION_WARNING_EVENT_ID
. The
source of the registration will be the set. The method must
throw a NullPointerException
if the
listener
argument is null
. If an
event handler has already been specified for this event the
current registration is replaced with the new one. Because both
registrations are for the same kind of event, the events sent
to the new registration must be in the same sequence as the
events sent to the old registration.
setExpirationWarningListener
in interface LeaseRenewalSet
listener
- the listener to be notified when this event
occursminWarning
- how long before the lease on the set expires
should the event be senthandback
- an object to be handed back to the listener when
the warning event occursEventRegistration
describing the event
registrationRemoteException
- if a communication-related exception
occurspublic void clearExpirationWarningListener() throws RemoteException
LeaseRenewalSet
clearExpirationWarningListener
in interface LeaseRenewalSet
RemoteException
- if a communication-related exception
occurspublic EventRegistration setRenewalFailureListener(RemoteEventListener listener, MarshalledObject handback) throws RemoteException
LeaseRenewalSet
This method allows the client to register for the event associated with the failure to renew a client lease in the set. These events are generated when a client lease expires while it is still in the set, or when the service attempts to renew a client lease and gets a definite exception. The listener argument specifies the listener to be notified if a client lease could not be renewed.
The handback
argument specifies an object that
will be part of the renewal failure event notification. This
mechanism is detailed in the Jini Distributed Event
Specification.
This method returns the event registration for this event. The
Lease
object associated with the registration will
be equivalent (in the sense of equals
) to the
Lease
on the renewal set. Because the event
registration shares a lease with the set, clients that want to
just remove their expiration warning registration without
destroying the set should use the
clearRenewalFailureListener
method, instead of
cancelling the registration's lease. The registration's event
ID will be
LeaseRenewalSet.RENEWAL_FAILURE_EVENT_ID
. The
source of the registration will be the set. The method must
throw NullPointerException
if the
listener
argument is null
. If an
event handler has already been specified for this event the
current registration is replaced with the new one. The returned
event registration must have the same event ID as the replaced
registration. Because both registrations are for the same kind
of event, the events sent to the new registration must be in
the same sequence as the events sent to the old registration.
setRenewalFailureListener
in interface LeaseRenewalSet
listener
- the listener to be notified when this event
occurshandback
- an object to be handed back to the listener when
the warning event occursEventRegistration
describing the event
registrationRemoteException
- if a communication-related exception
occurspublic void clearRenewalFailureListener() throws RemoteException
LeaseRenewalSet
clearRenewalFailureListener
in interface LeaseRenewalSet
RemoteException
- if a communication-related exception
occursNormServer server2()
public Lease getRenewalSetLease()
LeaseRenewalSet
getRenewalSetLease
in interface LeaseRenewalSet
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.