Class ConstrainableLookupLocator
- All Implemented Interfaces:
Serializable,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
This class supports use of the following constraint types to control unicast discovery behavior:
-
DiscoveryProtocolVersion: this constraint can be used to control which version of the unicast discovery protocol is used. -
UnicastSocketTimeout: this constraint can be used to control the read timeout set on sockets over which unicast discovery is performed. -
ConnectionRelativeTime: this constraint can be used to control the relative connection timeout set on sockets over which unicast discovery is performed. -
ConnectionAbsoluteTime: this constraint can be used to control the absolute connection timeout set on sockets over which unicast discovery is performed.
In addition, the
MulticastMaxPacketSizeandMulticastTimeToLiveconstraint 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
ConstrainableLookupLocatoris:
The resultingnew ConstrainableLookupLocator("target_host", 4162, newBasicMethodConstraints( newInvocationConstraints( DiscoveryProtocolVersion.TWO, new UnicastSocketTimeout(120000))));ConstrainableLookupLocatorinstance would (when used) perform unicast discovery to the hosttarget_hoston port 4162 using discovery protocol version 2, with a socket read timeout of 120000 milliseconds unless one was explicitly specified using thegetRegistrar(int)method. -
- Author:
- Sun Microsystems, Inc.
- See Also:
-
Field Summary
Fields inherited from class net.jini.core.discovery.LookupLocator
host, port -
Constructor Summary
ConstructorsConstructorDescriptionConstrainableLookupLocator(String host, int port, MethodConstraints constraints) Constructs a newConstrainableLookupLocatorinstance 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 newConstrainableLookupLocatorinstance 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
Modifier and TypeMethodDescriptionReturns the client constraints placed on this proxy.Performs unicast discovery as specified byLookupLocator.getRegistrar()with the following differences.getRegistrar(int timeout) Performs unicast discovery as specified byLookupLocator.getRegistrar(int), additionally applying the supplied discovery constraints.setConstraints(MethodConstraints constraints) Returns a new copy of this proxy with the client constraints set to the specified constraints.toString()Returns a string representation of this object.Methods inherited from class net.jini.core.discovery.LookupLocator
equals, getHost, getPort, hashCode
-
Constructor Details
-
ConstrainableLookupLocator
public ConstrainableLookupLocator(String url, MethodConstraints constraints) throws MalformedURLException Constructs a newConstrainableLookupLocatorinstance which can be used to perform unicast discovery to the host and port named by the given URL with the provided constraints applied. This constructor invokes its superclassLookupLocator(String)constructor. Any exceptions thrown by the superclass constructor are rethrown.The
urlmust be a valid URL of scheme"jini"as described inLookupLocator(String). Anull constraintsvalue is interpreted as mapping bothgetRegistrarmethods to empty constraints.- Parameters:
url- the URL to useconstraints- the constraints to apply to unicast discovery, ornull- Throws:
MalformedURLException- ifurlcannot be parsedNullPointerException- ifurlisnull
-
ConstrainableLookupLocator
Constructs a newConstrainableLookupLocatorinstance which can be used to perform unicast discovery to the given host and port with the provided constraints applied. This constructor invokes its superclassLookupLocator(String, int)constructor. Any exceptions thrown by the superclass constructor are rethrown.A
null constraintsvalue is interpreted as mapping bothgetRegistrarmethods to empty constraints. Thehostandportmust satisfy the requirements of theLookupLocator(String, int)constructor.- Parameters:
host- the name of the host to contactport- the number of the port to connect toconstraints- the constraints to apply to unicast discovery, ornull- Throws:
NullPointerException- ifhostisnullIllegalArgumentException- if the port and host do not meet the requirements ofLookupLocator(String, int).
-
-
Method Details
-
getRegistrar
Performs unicast discovery as specified byLookupLocator.getRegistrar()with the following differences.- It applies the supplied constraints (if any) for this method.
- It does not invoke the
getRegistrar(int)method. - If no timeout
constraints are specified, this method assumes a default timeout of 60 seconds. A non
default timeout can only be specified through the supplied constraints, the
net.jini.discovery.timeoutsystem property is ignored.
ConstrainableLookupLocatorimplements this method to use the values of thehostandportfield in determining the host and port to connect to.- Overrides:
getRegistrarin classLookupLocator- Returns:
- the ServiceRegistrar for the lookup service denoted by this LookupLocator object
- Throws:
UnsupportedConstraintException- if the discovery-related constraints contain conflicts, or otherwise cannot be processedIOException- an error occurred during discoveryClassNotFoundException- if a class required to unmarshal theServiceRegistrarproxy cannot be found
-
getRegistrar
Performs unicast discovery as specified byLookupLocator.getRegistrar(int), additionally applying the supplied discovery constraints. Thetimeoutis considered a requirement with respect to other constraints specified for this instance.- Overrides:
getRegistrarin classLookupLocator- Parameters:
timeout- the maximum time to wait for a response, in milliseconds. A value of0specifies an infinite timeout.- Returns:
- the ServiceRegistrar for the lookup service denoted by this LookupLocator object
- Throws:
UnsupportedConstraintException- if the discovery-related constraints contain conflicts, or otherwise cannot be processedIOException- an error occurred during discoveryClassNotFoundException- if a class required to unmarshal theServiceRegistrarproxy cannot be found
-
toString
Returns a string representation of this object.- Overrides:
toStringin classLookupLocator- Returns:
- the string representation
-
setConstraints
Description copied from interface:RemoteMethodControlReturns 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 thegetConstraintsmethod of the copy returns the identical constraints instance. The original proxy is not modified. Anullvalue 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 thegetConstraintsmethod of the specifiedMethodConstraintsinstance with aMethodobject 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
s1obtains a proxy for remote objects2, and passes that proxy to remote objects3, expectings3to invoke a remote method ons2, thens1can control that call by placing its constraints directly on the proxy before passing it tos3. Ifs3does 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:
setConstraintsin interfaceRemoteMethodControl- Parameters:
constraints- client constraints, ornull- Returns:
- a new copy of this proxy with the client constraints set to the specified constraints
- See Also:
-
getConstraints
Description copied from interface:RemoteMethodControlReturns the client constraints placed on this proxy. The return value can benull, which is interpreted as mapping all methods to empty constraints (one that has no requirements and no preferences).- Specified by:
getConstraintsin interfaceRemoteMethodControl- Returns:
- the client constraints, or
null - See Also:
-