public final class TcpEndpoint extends Object implements Endpoint, TrustEquivalence, Serializable
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 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.
TcpServerEndpoint,
Serialized Form| Modifier and Type | Method and Description |
|---|---|
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. |
String |
toString()
Returns a string representation of this
TcpEndpoint. |
public static TcpEndpoint getInstance(String host, int port)
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.
host - the host for the endpoint to connect toport - the TCP port on the given host for the endpoint to
connect toTcpEndpoint instanceIllegalArgumentException - if the port number is out of
the range 1 to 65535 (inclusive)NullPointerException - if host is
nullpublic static TcpEndpoint getInstance(String host, int port, SocketFactory sf)
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.
host - the host for the endpoint to connect toport - the TCP port on the given host for the endpoint to
connect tosf - the SocketFactory to use for this
TcpEndpoint, or nullTcpEndpoint instanceIllegalArgumentException - if the port number is out of
the range 1 to 65535 (inclusive)NullPointerException - if host is
nullpublic String getHost()
TcpEndpoint connects to.public int getPort()
TcpEndpoint connects to.public SocketFactory getSocketFactory()
SocketFactory that this endpoint uses
to create Socket objects.null if no factory is usedpublic OutboundRequestIterator newRequest(InvocationConstraints constraints)
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 thecreateSocketmethods on theSocketFactoryof thisTcpEndpoint(which produced this iterator) if non-null, or it will create aSocketdirectly otherwise.When the implementation needs to connect a
Socket, if the host name to connect to (thisTcpEndpoint's host name) resolves to multiple addresses (according toInetAddress.getAllByName), it attempts to connect to the first resolved address; if that attempt fails with anIOExceptionor aSecurityException, it then attempts to connect to the next address; and this iteration continues as long as there is another resolved address and the attempt to connect to the previous address fails with anIOExceptionor aSecurityException. If the host name resolves to just one address, the implementation makes one attempt to connect to that address. If the host name does not resolve to any addresses (InetAddress.getAllByNamewould throw anUnknownHostException), the implementation still makes an attempt to connect theSocketto that host name, which could result in anUnknownHostException. If the final connection attempt fails with anIOExceptionor aSecurityException, then if any connection attempt failed with anIOException, this method throws anIOException, and otherwise (if all connection attempts failed with aSecurityException), this method throws aSecurityException.If there is a security manager:
- If a new connection is to be created, the security manager's
checkConnectmethod is invoked with thisTcpEndpoint's host and-1for the port; if this results in aSecurityException, this method throws that exception.checkConnectis also invoked for each connection attempt, with the remote IP address (or the host name, if it could not be resolved) and port to connect to; this could result in aSecurityExceptionfor that attempt. (Note that the implementation may carry out these security checks indirectly, such as through invocations ofInetAddress.getAllByNameorSocket's constructors orconnectmethod.)In order to reuse an existing connection for the communication, the current security context must have all of the permissions that would be necessary if the connection were being created. Specifically, it must be possible to invoke
checkConnectin the current security context with thisTcpEndpoint's host and-1for the port without resulting in aSecurityException, and it also must be possible to invokecheckConnectwith the remote IP address and port of theSocketwithout resulting in aSecurityException(if the remote socket address is unresolved, its host name is used instead). If no existing connection satisfies these requirements, then this method must behave as if there are no existing connections.Throws
NoSuchElementExceptionif this iterator does not support making another attempt to communicate the request (that is, ifhasNextwould returnfalse).Throws
IOExceptionif an I/O exception occurs while performing this operation, such as if a connection attempt timed out or was refused.Throws
SecurityExceptionif there is a security manager and an invocation of itscheckConnectmethod fails.
newRequest in interface Endpointconstraints - the complete, absolute constraintsOutboundRequestIterator to use to send
a new request to this remote endpointNullPointerException - if constraints is
nullpublic int hashCode()
TcpEndpoint.public boolean equals(Object obj)
TcpEndpoint for equality.
This method returns true if and only if
TcpEndpoint,
SocketFactory or the SocketFactory in
the specified object has the same class and is equal to the one
in this object.
public boolean checkTrustEquivalence(Object obj)
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
TcpEndpoint,
SocketFactory or the SocketFactory in
the specified object has the same class and is equal to the one
in this object.
checkTrustEquivalence in interface TrustEquivalenceobj - object to check that is not yet known to be trustedtrue 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 otherwiseCopyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.