com.sun.jini.landlord
Class ConstrainableLandlordLease

java.lang.Object
  extended by com.sun.jini.lease.AbstractLease
      extended by com.sun.jini.landlord.LandlordLease
          extended by com.sun.jini.landlord.ConstrainableLandlordLease
All Implemented Interfaces:
Serializable, RemoteMethodControl, Lease, ReferentUuid

public final class ConstrainableLandlordLease
extends LandlordLease
implements RemoteMethodControl

Constrainable sub-class of LandlordLease. Instances of this class can be verified using the LandlordProxyVerifier class.

Since:
2.0
Author:
Sun Microsystems, Inc.
See Also:
LandlordProxyVerifier, Serialized Form

Field Summary
private static Method cancelAllMethod
          Convenience field containing the cancelAll method defined in the Landlord interface.
private static Method cancelMethod
          Convenience field containing the cancel method defined in the Lease interface.
private static Method[] comparableMethodsMapArray
          canBatch needs to check if this lease and the passed in lease have compatible constraints, this is the set of methods to compare.
(package private) static Method[] leaseMapMethodMapArray
          When creating a LeaseMap we generate an implicit set of constraints based on the constraints found on the the initial lease, where Lease.renew maps to Landlord.renewAll and Lease.cancel maps to Landlord.cancelAll.
private  MethodConstraints methodConstraints
          Client constraints placed on this proxy (may be null)
private static Method[] methodMapArray
          Array containing element pairs in which each pair of elements represents a mapping between two methods having the following characteristics: the first element in the pair is one of the public, remote methods that may be invoked by the client through Lease.
private static Method renewAllMethod
          Convenience field containing the renewAll method defined in the Landlord interface.
private static Method renewMethod
          Convenience field containing the renew method defined in the Lease interface.
(package private) static long serialVersionUID
           
 
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
ConstrainableLandlordLease(Uuid cookie, Landlord landlord, Uuid landlordUuid, long expiration, MethodConstraints methodConstraints)
          Create a new ConstrainableLandlordLease.
 
Method Summary
 boolean canBatch(Lease lease)
          Returns a boolean indicating whether or not the lease given as a parameter can be batched (placed in the same LeaseMap) with the current lease.
private static Landlord constrainServer(Landlord server, MethodConstraints constraints, Method[] mapping)
          Returns a copy of the given Landlord proxy having the client method constraints that result after a specified mapping is applied to the given method constraints.
 LeaseMap createLeaseMap(long duration)
          Creates a Map object that can contain leases whose renewal or cancellation can be batched, and adds the current lease to that map.
 MethodConstraints getConstraints()
          Returns the client constraints placed on this proxy.
private static Method getMethod(Class type, String name, Class[] parameterTypes)
          Returns the public method for the specified Class type, method name, and array of parameter types.
private  ProxyTrustIterator getProxyTrustIterator()
          Returns a proxy trust iterator that is used in ProxyTrustVerifier to retrieve this object's trust verifier.
private  void readObject(ObjectInputStream s)
           
 RemoteMethodControl setConstraints(MethodConstraints constraints)
          Returns a new copy of this proxy with the client constraints set to the specified constraints.
 
Methods inherited from class com.sun.jini.landlord.LandlordLease
cancel, cookie, doRenew, equals, getReferentUuid, hashCode, landlord, landlordUuid, setExpiration, toString
 
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, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

renewMethod

private static final Method renewMethod
Convenience field containing the renew method defined in the Lease interface. This field is used in the method mapping arrays and when retrieving method constraints for comparison in canBatch.


cancelMethod

private static final Method cancelMethod
Convenience field containing the cancel method defined in the Lease interface. This field is used in the method mapping arrays and when retrieving method constraints for comparison in canBatch.


renewAllMethod

private static final Method renewAllMethod
Convenience field containing the renewAll method defined in the Landlord interface. This field is used in the method mapping arrays.


cancelAllMethod

private static final Method cancelAllMethod
Convenience field containing the cancelAll method defined in the Landlord interface. This field is used in the method mapping arrays.


methodMapArray

private static final Method[] methodMapArray
Array containing element pairs in which each pair of elements represents a mapping between two methods having the following characteristics:


leaseMapMethodMapArray

static final Method[] leaseMapMethodMapArray
When creating a LeaseMap we generate an implicit set of constraints based on the constraints found on the the initial lease, where Lease.renew maps to Landlord.renewAll and Lease.cancel maps to Landlord.cancelAll. This array holds this mapping. Mapping also used by ConstrainableLandlordLeaseMap in canContainKey.


comparableMethodsMapArray

private static final Method[] comparableMethodsMapArray
canBatch needs to check if this lease and the passed in lease have compatible constraints, this is the set of methods to compare. Structured so we can use ConstrainableProxyUtil.equivalentConstraints(net.jini.core.constraint.MethodConstraints, net.jini.core.constraint.MethodConstraints, java.lang.reflect.Method[]).


methodConstraints

private final MethodConstraints methodConstraints
Client constraints placed on this proxy (may be null)

Constructor Detail

ConstrainableLandlordLease

public ConstrainableLandlordLease(Uuid cookie,
                                  Landlord landlord,
                                  Uuid landlordUuid,
                                  long expiration,
                                  MethodConstraints methodConstraints)
Create a new ConstrainableLandlordLease.

Parameters:
cookie - a Uuid that universally and uniquely identifies the lease this object is to be a proxy for
landlord - Landlord object that will be used to communicate renew and cancel requests to the granter of the lease.
landlordUuid - a universally unique id that has been assigned to the server granting of the lease. Ideally the Uuid landlord.getUuid would return if landlord implemented ReferentUuid. Used to determine when two leases can be batched together.
expiration - The initial expiration time of the lease in milliseconds since the beginning of the epoch.
methodConstraints - the client method constraints to place on this proxy (may be null).
Throws:
NullPointerException - if landlord, landlordUuid, or cookie is null.
ClassCastException - if landlord does not implement RemoteMethodControl.
Method Detail

getMethod

private static Method getMethod(Class type,
                                String name,
                                Class[] parameterTypes)
Returns the public method for the specified Class type, method name, and array of parameter types.

This method is typically used in place of Class.getMethod to get a method that should definitely be defined; thus, this method throws an error instead of an exception if the given method is missing.

This method is convenient for the initialization of a static variable for use as the mappings argument to ConstrainableProxyUtil.translateConstraints.

Parameters:
type - the Class type that defines the method of interest
name - String containing the name of the method of interest
parameterTypes - the Class types of the parameters to the method of interest
Returns:
a Method object that provides information about, and access to, the method of interest
Throws:
NoSuchMethodError - if the method of interest cannot be found
NullPointerException - if type or name is null

constrainServer

private static Landlord constrainServer(Landlord server,
                                        MethodConstraints constraints,
                                        Method[] mapping)
Returns a copy of the given Landlord proxy having the client method constraints that result after a specified mapping is applied to the given method constraints. For details on the mapping see ConstrainableProxyUtil.translateConstraints.

Parameters:
server - the proxy to attach constraints to
constraints - the source method constraints
mapping - mapping of methods to methods
Throws:
NullPointerException - if server is null.
ClassCastException - if server does not implement RemoteMethodControl.

setConstraints

public RemoteMethodControl setConstraints(MethodConstraints constraints)
Description copied from interface: RemoteMethodControl
Returns a new copy of this proxy with the client constraints set to the specified constraints. These constraints completely replace (in the copy) any client constraints previously placed on this proxy; calling the getConstraints method of the copy returns the identical constraints instance. The original proxy is not modified. A null value is interpreted as mapping all methods to empty constraints (one that has no requirements and no preferences). For any given remote call, the specific client requirements and preferences to be satisfied are given by the return value of invoking the getConstraints method of the specified MethodConstraints instance with a Method object representing the remote method.

Client constraints placed on a proxy are included in the serialized state of the proxy. This allows third-party services to be transparent to the client's needs. For example, if remote object s1 obtains a proxy for remote object s2, and passes that proxy to remote object s3, expecting s3 to invoke a remote method on s2, then s1 can control that call by placing its constraints directly on the proxy before passing it to s3. If s3 does not wish to be transparent in this way, then it should explicitly replace the client constraints on received proxies with whatever constraints are appropriate to implement its own policy.

Specified by:
setConstraints in interface RemoteMethodControl
Parameters:
constraints - client constraints, or null
Returns:
a new copy of this proxy with the client constraints set to the specified constraints
See Also:
RemoteMethodControl.getConstraints()

getConstraints

public MethodConstraints getConstraints()
Description copied from interface: RemoteMethodControl
Returns the client constraints placed on this proxy. The return value can be null, which is interpreted as mapping all methods to empty constraints (one that has no requirements and no preferences).

Specified by:
getConstraints in interface RemoteMethodControl
Returns:
the client constraints, or null
See Also:
RemoteMethodControl.setConstraints(net.jini.core.constraint.MethodConstraints)

getProxyTrustIterator

private ProxyTrustIterator getProxyTrustIterator()
Returns a proxy trust iterator that is used in ProxyTrustVerifier to retrieve this object's trust verifier.


readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
Throws:
IOException
ClassNotFoundException

canBatch

public boolean canBatch(Lease lease)
Description copied from interface: Lease
Returns a boolean indicating whether or not the lease given as a parameter can be batched (placed in the same LeaseMap) with the current lease. Whether or not two Lease objects can be batched is an implementation detail determined by the objects.

Specified by:
canBatch in interface Lease
Overrides:
canBatch in class LandlordLease
Parameters:
lease - the Lease to be evaluated
Returns:
a boolean indicating whether or not the lease given as a parameter can be batched (placed in the same LeaseMap) with the current lease

createLeaseMap

public LeaseMap createLeaseMap(long duration)
Description copied from interface: Lease
Creates a Map object that can contain leases whose renewal or cancellation can be batched, and adds the current lease to that map. The current lease is put in the map with the duration value given by the parameter.

Specified by:
createLeaseMap in interface Lease
Overrides:
createLeaseMap in class LandlordLease
Parameters:
duration - the duration to put into a Long and use as the value for the current lease in the created LeaseMap
Returns:
the created LeaseMap object


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