public final class TcpServerEndpoint extends Object implements ServerEndpoint
ServerEndpoint abstraction that
 uses TCP sockets (instances of ServerSocket) for the
 underlying communication mechanism.
 TcpServerEndpoint instances contain a host name and
 a TCP port number, as well as an optional ServerSocketFactory for customizing the type of
 ServerSocket to use and an optional SocketFactory for customizing the type of Socket that
 client endpoints will use.  The port number is the local TCP port
 to bind to when listening for incoming socket connections.  If the
 port number is zero, then each listen operation will bind to a free
 (non-zero) port, which will be the port number contained in the
 resulting TcpEndpoint.  The host name contained in a
 TcpServerEndpoint controls the host name that will be
 contained in the TcpEndpoint instances produced when
 enumerateListenEndpoints is
 invoked to listen on the TcpServerEndpoint (this host
 name does not affect the behavior of listen operations themselves).
 If the host name in a TcpServerEndpoint is
 null, then the host name in the
 TcpEndpoint instances that it produces will be the IP
 address string obtained from InetAddress.getLocalHost when enumerateListenEndpoints is invoked.
 
TcpServerEndpoint uses the Jini extensible remote
 invocation (Jini ERI) multiplexing protocol to map incoming
 requests to socket connections.
 
A ServerSocketFactory used with a
 TcpServerEndpoint must implement Object.equals to obey the guidelines that are specified for
 equals methods of ListenEndpoint
 instances.  A SocketFactory used with a
 TcpServerEndpoint should be serializable and must
 implement Object.equals to obey the guidelines that
 are specified for equals methods of Endpoint
 instances.
TcpEndpointServerEndpoint.ListenContext, ServerEndpoint.ListenCookie, ServerEndpoint.ListenEndpoint, ServerEndpoint.ListenHandle| Modifier and Type | Method and Description | 
|---|---|
InvocationConstraints | 
checkConstraints(InvocationConstraints constraints)
Verifies that this instance supports the transport layer
 aspects of all of the specified requirements (both in general
 and in the current security context), and returns the
 requirements that must be at least partially implemented by
 higher layers in order to fully satisfy all of the specified
 requirements. 
 | 
Endpoint | 
enumerateListenEndpoints(ServerEndpoint.ListenContext listenContext)
Passes the  
ListenEndpoint for this TcpServerEndpoint to
 listenContext, which will ensure an active listen
 operation on the endpoint, and returns a
 TcpEndpoint instance corresponding to the listen
 operation chosen by listenContext. | 
boolean | 
equals(Object obj)
Compares the specified object with this
  
TcpServerEndpoint for equality. | 
String | 
getHost()
Returns the host name that will be used in
  
TcpEndpoint instances produced by listening on
 this TcpServerEndpoint, or null if
 the IP address string obtained from InetAddress.getLocalHost will be
 used. | 
static TcpServerEndpoint | 
getInstance(int port)
Returns a  
TcpServerEndpoint instance for the given
 TCP port number. | 
static TcpServerEndpoint | 
getInstance(String host,
           int port)
Returns a  
TcpServerEndpoint instance for the given
 host name and TCP port number. | 
static TcpServerEndpoint | 
getInstance(String host,
           int port,
           SocketFactory sf,
           ServerSocketFactory ssf)
Returns a  
TcpServerEndpoint instance for the given
 host name and TCP port number that contains the given
 SocketFactory and
 ServerSocketFactory. | 
int | 
getPort()
Returns the TCP port that this  
TcpServerEndpoint
 listens on. | 
ServerSocketFactory | 
getServerSocketFactory()
Returns the  
ServerSocketFactory that this endpoint
 uses to create ServerSocket objects. | 
SocketFactory | 
getSocketFactory()
Returns the  
SocketFactory that
 TcpEndpoint objects produced by listening on this
 TcpServerEndpoint will use to create
 Socket objects. | 
int | 
hashCode()
Returns the hash code value for this
  
TcpServerEndpoint. | 
String | 
toString()
Returns a string representation of this
  
TcpServerEndpoint. | 
public static TcpServerEndpoint getInstance(int port)
TcpServerEndpoint instance for the given
 TCP port number.
 The host name contained in the returned
 TcpServerEndpoint will be null, so
 that when its enumerateListenEndpoints method produces a TcpEndpoint, the TcpEndpoint's host name will be
 the IP address string obtained from InetAddress.getLocalHost.
 
The ServerSocketFactory contained in the
 returned TcpServerEndpoint will be
 null, indicating that this endpoint will create
 ServerSocket objects directly.  The
 SocketFactory contained in the returned
 TcpServerEndpoint will also be null.
port - the TCP port on the local host to listen onTcpServerEndpoint instanceIllegalArgumentException - if the port number is out of
 the range 0 to 65535 (inclusive)public static TcpServerEndpoint getInstance(String host, int port)
TcpServerEndpoint instance for the given
 host name and TCP port number.
 If host is null, then when the
 returned TcpServerEndpoint's enumerateListenEndpoints method
 produces a TcpEndpoint, the TcpEndpoint's
 host name will be the IP address string obtained from InetAddress.getLocalHost.
 
The ServerSocketFactory contained in the
 returned TcpServerEndpoint will be
 null, indicating that this endpoint will create
 ServerSocket objects directly.  The
 SocketFactory contained in the returned
 TcpServerEndpoint will also be null.
host - the host name to be used in
 TcpEndpoint instances produced by listening on the
 returned TcpServerEndpoint, or nullport - the TCP port on the local host to listen onTcpServerEndpoint instanceIllegalArgumentException - if the port number is out of
 the range 0 to 65535 (inclusive)public static TcpServerEndpoint getInstance(String host, int port, SocketFactory sf, ServerSocketFactory ssf)
TcpServerEndpoint instance for the given
 host name and TCP port number that contains the given
 SocketFactory and
 ServerSocketFactory.
 If host is null, then when the
 returned TcpServerEndpoint's enumerateListenEndpoints method
 produces a TcpEndpoint, the TcpEndpoint's
 host name will be the IP address string obtained from InetAddress.getLocalHost.
 
If the server socket factory argument is null,
 then this endpoint will create ServerSocket
 objects directly.
host - the host name to be used in
 TcpEndpoint instances produced by listening on the
 returned TcpServerEndpoint, or nullport - the TCP port on the local host to listen onsf - the SocketFactory to use for this
 TcpServerEndpoint, or nullssf - the ServerSocketFactory to use for this
 TcpServerEndpoint, or nullTcpServerEndpoint instanceIllegalArgumentException - if the port number is out of
 the range 0 to 65535 (inclusive)public String getHost()
TcpEndpoint instances produced by listening on
 this TcpServerEndpoint, or null if
 the IP address string obtained from InetAddress.getLocalHost will be
 used.TcpEndpoint
 instances produced from this object, or nullpublic int getPort()
TcpServerEndpoint
 listens on.public SocketFactory getSocketFactory()
SocketFactory that
 TcpEndpoint objects produced by listening on this
 TcpServerEndpoint will use to create
 Socket objects.null if no factory will be usedpublic ServerSocketFactory getServerSocketFactory()
ServerSocketFactory that this endpoint
 uses to create ServerSocket objects.null if no factory is usedpublic InvocationConstraints checkConstraints(InvocationConstraints constraints) throws UnsupportedConstraintException
For any given constraint, there must be a clear delineation
 of which aspects (if any) must be implemented by the transport
 layer.  This method must not return a constraint (as a
 requirement or a preference, directly or as an element of
 another constraint) unless this instance can implement all of
 those aspects.  Also, this method must not return a constraint
 for which all aspects must be implemented by the transport
 layer.  Most of the constraints in the net.jini.core.constraint package must be fully implemented by
 the transport layer and thus must not be returned by this
 method; the one exception is Integrity, for which the
 transport layer is responsible for the data integrity aspect
 and higher layers are responsible for the code integrity
 aspect.
 
For any ConstraintAlternatives in the specified
 constraints, this method should only return a corresponding
 constraint if all of the alternatives supported by this
 instance need to be at least partially implemented by higher
 layers in order to be fully satisfied.
 
The constraints passed to this method may include constraints based on relative time.
checkConstraints in interface ServerCapabilitiesconstraints - the constraints that must be supportedNullPointerException - if constraints is
 nullUnsupportedConstraintException - if the transport layer
 aspects of any of the specified requirements are not supported
 by this instance (either in general or in the current security
 context)public Endpoint enumerateListenEndpoints(ServerEndpoint.ListenContext listenContext) throws IOException
ListenEndpoint for this TcpServerEndpoint to
 listenContext, which will ensure an active listen
 operation on the endpoint, and returns a
 TcpEndpoint instance corresponding to the listen
 operation chosen by listenContext.
 If this TcpServerEndpoint's host name is not
 null, then the returned TcpEndpoint
 will contain that host name.  If this
 TcpServerEndpoint's host name is
 null, then this method invokes InetAddress.getLocalHost to obtain an
 InetAddress for the local host.  If
 InetAddress.getLocalHost throws an UnknownHostException, this method throws an
 UnknownHostException.  The returned
 TcpEndpoint's host name will be the string
 returned by invoking getHostAddress on that InetAddress.  If there is
 a security manager, its checkConnect method
 will be invoked with the string returned by invoking getHostName on that same
 InetAddress as the host argument and
 -1 as the port argument; this could result in a
 SecurityException.
 
This method invokes addListenEndpoint on
 listenContext once, passing a
 ListenEndpoint as described below.  If
 addListenEndpoint throws an exception, then this
 method throws that exception.  Otherwise, this method returns a
 TcpEndpoint instance with the host name described
 above, the TCP port number bound by the listen operation
 represented by the ListenHandle
 returned by addListenEndpoint, and the same
 SocketFactory as this
 TcpServerEndpoint.
 
The ListenEndpoint passed to
 addListenEndpoint represents the TCP port number
 and ServerSocketFactory of this
 TcpServerEndpoint.  Its methods behave as follows:
 
ListenHandle listen(RequestDispatcher):
 
Listens for requests received on this endpoint's TCP port, dispatching them to the suppliedRequestDispatcherin the form ofInboundRequestinstances.When the implementation of this method needs to create a new
ServerSocket, it will do so by invoking one of thecreateServerSocketmethods that returns a bound server socket on the containedServerSocketFactoryif non-null, or it will create aServerSocketdirectly otherwise.If there is a security manager, its
checkListenmethod will be invoked with this endpoint's TCP port; this could result in aSecurityException. Furthermore, before a givenInboundRequestgets dispatched to the supplied request dispatcher, the security manager'scheckAcceptmethod must have been successfully invoked in the security context of thislisteninvocation with the remote IP address and port of theSocketused to receive the request. ThecheckPermissionsmethod of the dispatchedInboundRequestalso performs this latter security check. (Note that in some cases, the implementation may carry out these security checks indirectly, such as through invocations ofServerSocket's constructors oracceptmethod.)Requests will be dispatched in a
PrivilegedActionwrapped by aSecurityContextobtained when this method was invoked, with theAccessControlContextof thatSecurityContextin effect.Dispatched requests will implement
populateContextto populate the given collection with an element that implements theClientHostinterface. ThatClientHostelement implementsgetClientHostto return the IP address of theSocketthat the request was received over (seeSocket.getInetAddress()).Throws
IOExceptionif an I/O exception occurs while performing this operation, such as if the TCP port is already in use.Throws
SecurityExceptionif there is a security manager and the invocation of itscheckListenmethod fails.Throws
NullPointerExceptionifrequestDispatcherisnull
Verifies that the current security context has all of the security permissions necessary to listen for requests on this endpoint.If there is a security manager, its
checkListenmethod will be invoked with this endpoint's TCP port; this could result in aSecurityException.Throws
SecurityExceptionif there is a security manager and the invocation of itscheckListenmethod fails.
Compares the specified object with thisListenEndpointfor equality.This method returns
trueif and only if
- the specified object is also a
 ListenEndpointproduced by aTcpServerEndpoint,- the port in the specified object is equal to the port in this object, and
 - either this object and the specified object both have no
 ServerSocketFactoryor theServerSocketFactoryin the specified object has the same class and is equal to the one in this object.
enumerateListenEndpoints in interface ServerEndpointlistenContext - the ListenContext to pass
 this TcpServerEndpoint's
 ListenEndpoint toTcpEndpoint instance for sending
 requests to this TcpServerEndpoint's endpoint
 being listened onUnknownHostException - if this
 TcpServerEndpoint's host name is null
 and InetAddress.getLocalHost throws an
 UnknownHostExceptionIOException - if an I/O exception occurs while performing
 this operation, such as if the TCP port is already in useSecurityException - if there is a security manager and
 either the invocation of its checkListen method
 fails or this TcpServerEndpoint's host name is
 null and the invocation of the security manager's
 checkConnect method failsIllegalArgumentException - if an invocation of the
 addListenEndpoint method on the supplied
 ListenContext returns a ListenCookie
 that does not correspond to the ListenEndpoint
 that was passed to itNullPointerException - if listenContext is
 nullpublic int hashCode()
TcpServerEndpoint.public boolean equals(Object obj)
TcpServerEndpoint for equality.
 This method returns true if and only if
 
TcpServerEndpoint,
 SocketFactory or the ServerFactory in
 the specified object has the same class and is equal to the one
 in this object, and
 ServerSocketFactory or the
 ServerSocketFactory in the specified object has
 the same class and is equal to the one in this object.