net.jini.jeri.tcp
Class TcpEndpoint

java.lang.Object
  extended bynet.jini.jeri.tcp.TcpEndpoint
All Implemented Interfaces:
Endpoint, Serializable, TrustEquivalence

public final class TcpEndpoint
extends Object
implements Endpoint, TrustEquivalence, Serializable

An implementation of the Endpoint abstraction that uses TCP sockets (instances of Socket) for the underlying communication mechanism.

TcpEndpoint instances contain a host name and a TCP port number, as well as an optional SocketFactory for customizing the type of Socket to use. The host name and port number are used as the remote address to connect to when making socket connections.

TcpEndpoint uses the Jini(TM) extensible remote invocation (Jini ERI) multiplexing protocol to map outgoing requests to socket connections.

A SocketFactory used with a TcpEndpoint should be serializable and must implement Object.equals to obey the guidelines that are specified for equals methods of Endpoint instances.

Since:
2.0
See Also:
TcpServerEndpoint, Serialized Form

Method Summary
 boolean checkTrustEquivalence(Object obj)
          Returns true if the specified object (which is not yet known to be trusted) is equivalent in trust, content, and function to this known trusted object, and false otherwise.
 boolean equals(Object obj)
          Compares the specified object with this TcpEndpoint for equality.
 String getHost()
          Returns the host that this TcpEndpoint connects to.
static TcpEndpoint getInstance(String host, int port)
          Returns a TcpEndpoint instance for the given host name and TCP port number.
static TcpEndpoint getInstance(String host, int port, SocketFactory sf)
          Returns a TcpEndpoint instance for the given host name and TCP port number that contains the given SocketFactory.
 int getPort()
          Returns the TCP port that this TcpEndpoint connects to.
 SocketFactory getSocketFactory()
          Returns the SocketFactory that this endpoint uses to create Socket objects.
 int hashCode()
          Returns the hash code value for this TcpEndpoint.
 OutboundRequestIterator newRequest(InvocationConstraints constraints)
          Returns an OutboundRequestIterator to use to send a new request to this remote endpoint using the specified constraints.

The constraints must be the complete, absolute constraints for the request. The returned OutboundRequestIterator's next method behaves as follows: Initiates an attempt to communicate the request to this remote endpoint.

 String toString()
          Returns a string representation of this TcpEndpoint.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getInstance

public static TcpEndpoint getInstance(String host,
                                      int port)
Returns a TcpEndpoint instance for the given host name and TCP port number.

The SocketFactory contained in the returned TcpEndpoint will be null, indicating that this endpoint will create Socket objects directly.

Parameters:
host - the host for the endpoint to connect to
port - the TCP port on the given host for the endpoint to connect to
Returns:
a TcpEndpoint instance
Throws:
IllegalArgumentException - if the port number is out of the range 1 to 65535 (inclusive)
NullPointerException - if host is null

getInstance

public static TcpEndpoint getInstance(String host,
                                      int port,
                                      SocketFactory sf)
Returns a TcpEndpoint instance for the given host name and TCP port number that contains the given SocketFactory.

If the socket factory argument is null, then this endpoint will create Socket objects directly.

Parameters:
host - the host for the endpoint to connect to
port - the TCP port on the given host for the endpoint to connect to
sf - the SocketFactory to use for this TcpEndpoint, or null
Returns:
a TcpEndpoint instance
Throws:
IllegalArgumentException - if the port number is out of the range 1 to 65535 (inclusive)
NullPointerException - if host is null

getHost

public String getHost()
Returns the host that this TcpEndpoint connects to.

Returns:
the host that this endpoint connects to

getPort

public int getPort()
Returns the TCP port that this TcpEndpoint connects to.

Returns:
the TCP port that this endpoint connects to

getSocketFactory

public SocketFactory getSocketFactory()
Returns the SocketFactory that this endpoint uses to create Socket objects.

Returns:
the socket factory that this endpoint uses to create sockets, or null if no factory is used

newRequest

public OutboundRequestIterator newRequest(InvocationConstraints constraints)
Returns an OutboundRequestIterator to use to send a new request to this remote endpoint using the specified constraints.

The constraints must be the complete, absolute constraints for the request.

The returned OutboundRequestIterator's next method behaves as follows:

Initiates an attempt to communicate the request to this remote endpoint.

When the implementation of this method needs to create a new Socket, it will do so by invoking one of the createSocket methods on the SocketFactory of the TcpEndpoint that produced this iterator if non-null, or it will create a Socket directly otherwise.

If there is a security manager, its checkConnect method will be invoked with the remote IP address and port of the Socket to be used for the communication; this could result in a SecurityException.

Throws NoSuchElementException if this iterator does not support making another attempt to communicate the request (that is, if hasNext would return false).

Throws ConnectException if a failure occurs while connecting a socket to the remote host and port, such as if the connection was refused (no entity is listening on that port or the host is too busy).

Throws IOException if an I/O exception occurs while performing this operation.

Throws SecurityException if there is a security manager and the invocation of its checkConnect method fails.

Specified by:
newRequest in interface Endpoint
Parameters:
constraints - the complete, absolute constraints
Returns:
an OutboundRequestIterator to use to send a new request to this remote endpoint
Throws:
NullPointerException - if constraints is null

hashCode

public int hashCode()
Returns the hash code value for this TcpEndpoint.

Returns:
the hash code value for this TcpEndpoint

equals

public boolean equals(Object obj)
Compares the specified object with this TcpEndpoint for equality.

This method returns true if and only if

Parameters:
obj - the object to compare with
Returns:
true if obj is equivalent to this object; false otherwise

checkTrustEquivalence

public boolean checkTrustEquivalence(Object obj)
Returns true if the specified object (which is not yet known to be trusted) is equivalent in trust, content, and function to this known trusted object, and false otherwise.

This method returns true if and only if

Specified by:
checkTrustEquivalence in interface TrustEquivalence
Parameters:
obj - object to check that is not yet known to be trusted
Returns:
true if the specified object (that is not yet known to be trusted) is equivalent in trust, content, and function to this known trusted object, and returns false otherwise

toString

public String toString()
Returns a string representation of this TcpEndpoint.

Returns:
a string representation of this TcpEndpoint


Copyright © 2004 Sun Microsystems, Inc. All rights reserved