net.jini.core.discovery
Class LookupLocator

java.lang.Object
  extended by net.jini.core.discovery.LookupLocator
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ConstrainableLookupLocator

public class LookupLocator
extends Object
implements Serializable

LookupLocator supports unicast discovery, using only version 1 of the unicast discovery protocol. It's main purpose now is to contain a host name and port number. It is used as a parameter in LookupLocatorDiscovery constructors. LookupLocatorDiscovery has methods to perform Discovery using either version 1 or 2 with constraints. ConstrainableLookupLocator is a subclass which uses discovery V1 or V2 and enables the use of constraints.

Since:
1.0
Author:
Sun Microsystems, Inc.
See Also:
LookupLocatorDiscovery, ConstrainableLookupLocator, Serialized Form

Field Summary
(package private) static int defaultTimeout
          The timeout after which we give up waiting for a response from the lookup service.
private static short discoveryPort
          The port for both unicast and multicast boot requests.
protected  String host
          The name of the host at which to perform discovery.
protected  int port
          The port number on the host at which to perform discovery.
private static int protoVersion
          The current version of the unicast discovery protocol.
private static long serialVersionUID
           
protected  SocketFactory sf
          The socket factory that this LookupLocator uses to create Socket objects.
 
Constructor Summary
LookupLocator(String url)
          Construct a new LookupLocator object, set up to perform discovery to the given URL.
LookupLocator(String host, int port)
          Construct a new LookupLocator object, set to perform unicast discovery to the input host and port.
LookupLocator(String host, int port, SocketFactory sf)
          Construct a new LookupLocator object, set to perform unicast discovery to the input host and port using the socketFactory.
 
Method Summary
 boolean equals(Object o)
          Two locators are equal if they have the same host and port fields.
 String getHost()
          Returns the name of the host that this instance should contact.
private static String getHost0(String host)
           
 int getPort()
          Returns the number of the port to which this instance should connect.
 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, with the given discovery timeout.
private static ServiceRegistrar getRegistrarFromSocket(Socket sock, int timeout)
           
private  void handle3986Authority(URI uri)
           
 int hashCode()
          Returns a hash code value calculated from the host and port field values.
private  void parseHostPort(String authority, URI uri)
           
 String toString()
          Return the string form of this LookupLocator, as a URL of scheme "jini".
private  URI try3986Authority(String host, int port)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

discoveryPort

private static final short discoveryPort
The port for both unicast and multicast boot requests.

See Also:
Constant Field Values

protoVersion

private static final int protoVersion
The current version of the unicast discovery protocol.

See Also:
Constant Field Values

host

protected String host
The name of the host at which to perform discovery.


port

protected int port
The port number on the host at which to perform discovery.


sf

protected SocketFactory sf
The socket factory that this LookupLocator uses to create Socket objects.


defaultTimeout

static final int defaultTimeout
The timeout after which we give up waiting for a response from the lookup service.

Constructor Detail

LookupLocator

public LookupLocator(String url)
              throws MalformedURLException
Construct a new LookupLocator object, set up to perform discovery to the given URL. The host and port fields will be populated with the host and port components of the input URL. No host name resolution is attempted.

The syntax of the URL must be that of a hierarchical URI with a server-based naming authority. Requirements for the components are as follows:

The four allowed forms of the URL are thus:


LookupLocator

public LookupLocator(String host,
                     int port)
Construct a new LookupLocator object, set to perform unicast discovery to the input host and port. The host and port fields will be populated with the host and port arguments. No host name resolution is attempted.

The host argument must meet any one of the following syntactical requirements:

Parameters:
host - the name of the host to contact
port - the number of the port to connect to
Throws:
IllegalArgumentException - if port is not between 1 and 65535 (both included) or if host cannot be parsed.
NullPointerException - if host is null

LookupLocator

public LookupLocator(String host,
                     int port,
                     SocketFactory sf)
Construct a new LookupLocator object, set to perform unicast discovery to the input host and port using the socketFactory. The host, port and sf fields will be populated with the host, port and sf arguments. No host name resolution is attempted.

The host argument must meet any one of the following syntactical requirements:

Parameters:
host - the name of the host to contact
port - the number of the port to connect to
sf - the factory to use for creating the socket
Throws:
IllegalArgumentException - if port is not between 1 and 65535 (both included) or if host cannot be parsed.
NullPointerException - if host is null
Method Detail

getHost

public String getHost()
Returns the name of the host that this instance should contact. LookupLocator implements this method to return the host field.

Returns:
a String representing the host value

getPort

public int getPort()
Returns the number of the port to which this instance should connect. LookupLocator implements this method to return the port field.

Returns:
an int representing the port value

getRegistrar

public ServiceRegistrar getRegistrar()
                              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. LookupLocator implements this method to simply invoke getRegistrar(int) with a timeout value, which is determined by the value of the net.jini.discovery.timeout system property. If the property is set, is not negative, and can be parsed as an Integer, the value of the property is used as the timeout value. Otherwise, a default value of 60 seconds is assumed.

Returns:
the ServiceRegistrar for the lookup service denoted by this LookupLocator object
Throws:
IOException - an error occurred during discovery
ClassNotFoundException - if a class required to unmarshal the ServiceRegistrar proxy cannot be found

getRegistrar

public ServiceRegistrar getRegistrar(int timeout)
                              throws IOException,
                                     ClassNotFoundException
Perform unicast discovery and return the ServiceRegistrar object for the given lookup service, with the given discovery timeout. Unicast discovery is performed anew each time this method is called. LookupLocator implements this method to use the values of the host and port field in determining the host and port to connect to.

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.

Parameters:
timeout - the maximum time to wait for a response, in milliseconds. A value of 0 specifies an infinite timeout.
Returns:
the ServiceRegistrar for the lookup service denoted by this LookupLocator object
Throws:
IOException - an error occurred during discovery
ClassNotFoundException - if a class required to unmarshal the ServiceRegistrar proxy cannot be found
IllegalArgumentException - if timeout is negative

getRegistrarFromSocket

private static ServiceRegistrar getRegistrarFromSocket(Socket sock,
                                                       int timeout)
                                                throws IOException,
                                                       ClassNotFoundException
Throws:
IOException
ClassNotFoundException

toString

public String toString()
Return the string form of this LookupLocator, as a URL of scheme "jini".

Overrides:
toString in class Object

equals

public boolean equals(Object o)
Two locators are equal if they have the same host and port fields. The case of the host is ignored. Alternative forms of the same IPv6 addresses for the host value are treated as being unequal.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value calculated from the host and port field values.

Overrides:
hashCode in class Object

getHost0

private static String getHost0(String host)

try3986Authority

private URI try3986Authority(String host,
                             int port)

handle3986Authority

private void handle3986Authority(URI uri)
                          throws MalformedURLException
Throws:
MalformedURLException

parseHostPort

private void parseHostPort(String authority,
                           URI uri)
                    throws MalformedURLException
Throws:
MalformedURLException


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