net.jini.discovery
Class ConstrainableLookupLocator

java.lang.Object
  extended bynet.jini.core.discovery.LookupLocator
      extended bynet.jini.discovery.ConstrainableLookupLocator
All Implemented Interfaces:
RemoteMethodControl, Serializable

public final class ConstrainableLookupLocator
extends LookupLocator
implements RemoteMethodControl

LookupLocator subclass which supports constraint operations through the RemoteMethodControl interface. The constraints of a ConstrainableLookupLocator instance control how it performs unicast discovery, and apply only to its getRegistrar() and getRegistrar(int) methods. The constraints may also be used by other utilities, such as LookupLocatorDiscovery, to determine how unicast discovery should be performed on behalf of a given ConstrainableLookupLocator instance. Untrusted ConstrainableLookupLocator instances can be verified using the ConstrainableLookupLocatorTrustVerifier trust verifier.

Since:
2.0
See Also:
Serialized Form
Implementation Specifics:
This class supports use of the following constraint types to control unicast discovery behavior:

In addition, the MulticastMaxPacketSize and MulticastTimeToLive constraint types are trivially supported, but do not have any effect on unicast discovery operations. Constraints other than those mentioned above are passed on to the underlying implementations of versions 1 and 2 of the discovery protocols.

An example of using constraints with ConstrainableLookupLocator is:

 new ConstrainableLookupLocator("target_host", 4160, new BasicMethodConstraints(
     new InvocationConstraints(
         DiscoveryProtocolVersion.TWO, new UnicastSocketTimeout(120000))));
 
The resulting ConstrainableLookupLocator instance would (when used) perform unicast discovery to the host target_host on port 4160 using discovery protocol version 2, with a socket read timeout of 120000 milliseconds unless one was explicitly specified using the getRegistrar(int) method.

Field Summary
 
Fields inherited from class net.jini.core.discovery.LookupLocator
host, port
 
Constructor Summary
ConstrainableLookupLocator(String host, int port, MethodConstraints constraints)
          Constructs a new ConstrainableLookupLocator instance which can be used to perform unicast discovery to the given host and port with the provided constraints applied.
ConstrainableLookupLocator(String url, MethodConstraints constraints)
          Constructs a new ConstrainableLookupLocator instance which can be used to perform unicast discovery to the host and port named by the given URL with the provided constraints applied.
 
Method Summary
 MethodConstraints getConstraints()
          Returns the client constraints placed on this proxy.
 ServiceRegistrar getRegistrar()
          Perform unicast discovery and return the ServiceRegistrar object for the given lookup service.
 ServiceRegistrar getRegistrar(int timeout)
          Perform unicast discovery and return the ServiceRegistrar object for the given lookup service. Unicast discovery is performed anew each time this method is called.

If a connection can be established to start unicast discovery but the remote end fails to respond within the given time limit, an exception is thrown. The time limit is considered a requirement with respect to other constraints specified for this instance.

 RemoteMethodControl setConstraints(MethodConstraints constraints)
          Returns a new copy of this proxy with the client constraints set to the specified constraints.
 
Methods inherited from class net.jini.core.discovery.LookupLocator
equals, getHost, getPort, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstrainableLookupLocator

public ConstrainableLookupLocator(String url,
                                  MethodConstraints constraints)
                           throws MalformedURLException
Constructs a new ConstrainableLookupLocator instance which can be used to perform unicast discovery to the host and port named by the given URL with the provided constraints applied.

The given URL must be of the form jini://host/ or jini://host:port/. A null constraints value is interpreted as mapping both getRegistrar methods to empty constraints.

Parameters:
url - the URL to use
constraints - the constraints to apply to unicast discovery, or null
Throws:
MalformedURLException - if the given URL cannot be parsed
NullPointerException - if the given URL is null

ConstrainableLookupLocator

public ConstrainableLookupLocator(String host,
                                  int port,
                                  MethodConstraints constraints)
Constructs a new ConstrainableLookupLocator instance which can be used to perform unicast discovery to the given host and port with the provided constraints applied.

A null constraints value is interpreted as mapping both getRegistrar methods to empty constraints.

Parameters:
host - the name of the host to contact
port - the number of the port to connect to
constraints - the constraints to apply to unicast discovery, or null
Throws:
NullPointerException - if the host name is null
IllegalArgumentException - if the port number is out of range
Method Detail

getRegistrar

public ServiceRegistrar getRegistrar()
                              throws IOException,
                                     ClassNotFoundException
Description copied from class: LookupLocator
Perform unicast discovery and return the ServiceRegistrar object for the given lookup service. Unicast discovery is performed anew each time this method is called.

Overrides:
getRegistrar in class LookupLocator
Returns:
the ServiceRegistrar for the lookup service denoted by this LookupLocator object
Throws:
IOException - an error occurred during discovery
ClassNotFoundException - some discovery-related classes could not be found

getRegistrar

public ServiceRegistrar getRegistrar(int timeout)
                              throws IOException,
                                     ClassNotFoundException
Perform unicast discovery and return the ServiceRegistrar object for the given lookup service. Unicast discovery is performed anew each time this method is called.

If a connection can be established to start unicast discovery but the remote end fails to respond within the given time limit, an exception is thrown. The time limit is considered a requirement with respect to other constraints specified for this instance.

Overrides:
getRegistrar in class LookupLocator
Parameters:
timeout - the maximum time to wait for a response, in milliseconds
Returns:
the ServiceRegistrar for the lookup service denoted by this LookupLocator object
Throws:
IOException - an error occurred during discovery
ClassNotFoundException - some discovery-related classes could not be found

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)


Copyright © 2003 Sun Microsystems, Inc. All rights reserved