Package com.ibm.di.api.remote.impl.rmi
Class ServerSocketWrapper
- java.lang.Object
-
- java.net.ServerSocket
-
- com.ibm.di.api.remote.impl.rmi.ServerSocketWrapper
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ServerSocketWrapper extends java.net.ServerSocket
A wrapper class of ServerSocket class for use by the RMI. ServerSocket class implements server sockets. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester.
-
-
Constructor Summary
Constructors Constructor Description ServerSocketWrapper(java.net.ServerSocket aServer)
Creates an unbound server socket.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.Socket
accept()
Listens for a connection to be made to this socket and accepts it.void
bind(java.net.SocketAddress aEndpoint)
Binds theServerSocketWrapper
to a specific address (IP address and port number).void
bind(java.net.SocketAddress aEndpoint, int aBacklog)
Binds theServerSocketWrapper
to a specific address (IP address and port number) with specified backlog length.void
close()
Closes this socket.java.nio.channels.ServerSocketChannel
getChannel()
Returns the uniqueServerSocketChannel
object associated with this socket, if any.java.net.InetAddress
getInetAddress()
Returns the local address of this server socket.int
getLocalPort()
Returns the port on which this socket is listening.java.net.SocketAddress
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, ornull
if it is not bound yet.int
getReceiveBufferSize()
Gets the value of the SO_RCVBUF option for this ServerSocketWrapper, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocketWrapper.boolean
getReuseAddress()
Tests if SO_REUSEADDR is enabled.int
getSoTimeout()
Retrive setting for SO_TIMEOUT.boolean
isBound()
Returns the binding state of the ServerSocket.boolean
isClosed()
Returns the closed state of the ServerSocketWrapper.void
setReceiveBufferSize(int aSize)
Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocketWrapper.void
setReuseAddress(boolean aOn)
Enable/disable the SO_REUSEADDR socket option.void
setSoTimeout(int aTimeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.java.lang.String
toString()
Returns the implementation address and implementation port of this socket as aString
.
-
-
-
Method Detail
-
bind
public void bind(java.net.SocketAddress aEndpoint) throws java.io.IOException
Binds theServerSocketWrapper
to a specific address (IP address and port number).- Overrides:
bind
in classjava.net.ServerSocket
- Parameters:
aEndpoint
- The IP address & port number to bind to.- Throws:
java.io.IOException
- if the bind operation fails, or if the socket is already bound.
-
bind
public void bind(java.net.SocketAddress aEndpoint, int aBacklog) throws java.io.IOException
Binds theServerSocketWrapper
to a specific address (IP address and port number) with specified backlog length.- Overrides:
bind
in classjava.net.ServerSocket
- Parameters:
aEndpoint
- The IP address & port number to bind to.aBacklog
- The listen backlog length.- Throws:
java.io.IOException
- if the bind operation fails, or if the socket is already bound.
-
getInetAddress
public java.net.InetAddress getInetAddress()
Returns the local address of this server socket.- Overrides:
getInetAddress
in classjava.net.ServerSocket
- Returns:
- the address to which this socket is bound, or
null
if the socket is unbound.
-
getLocalPort
public int getLocalPort()
Returns the port on which this socket is listening.- Overrides:
getLocalPort
in classjava.net.ServerSocket
- Returns:
- the port number to which this socket is listening or -1 if the socket is not bound yet.
-
getLocalSocketAddress
public java.net.SocketAddress getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, ornull
if it is not bound yet.- Overrides:
getLocalSocketAddress
in classjava.net.ServerSocket
- Returns:
- a
SocketAddress
representing the local endpoint of this socket, ornull
if it is not bound yet. - See Also:
getInetAddress()
,getLocalPort()
-
accept
public java.net.Socket accept() throws java.io.IOException
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.- Overrides:
accept
in classjava.net.ServerSocket
- Returns:
- the new SocketWrapper
- Throws:
java.io.IOException
- if an I/O error occurs when waiting for a connection.
-
close
public void close() throws java.io.IOException
Closes this socket.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.net.ServerSocket
- Throws:
java.io.IOException
- if an I/O error occurs when closing the socket.
-
getChannel
public java.nio.channels.ServerSocketChannel getChannel()
Returns the uniqueServerSocketChannel
object associated with this socket, if any.- Overrides:
getChannel
in classjava.net.ServerSocket
- Returns:
- the server-socket channel associated with this socket, or null if this socket was not created for a channel
-
isBound
public boolean isBound()
Returns the binding state of the ServerSocket.- Overrides:
isBound
in classjava.net.ServerSocket
- Returns:
- true if the ServerSocketWrapper succesfuly bound to an address
-
isClosed
public boolean isClosed()
Returns the closed state of the ServerSocketWrapper.- Overrides:
isClosed
in classjava.net.ServerSocket
- Returns:
- true if the socket has been closed
-
setSoTimeout
public void setSoTimeout(int aTimeout) throws java.net.SocketException
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.- Overrides:
setSoTimeout
in classjava.net.ServerSocket
- Parameters:
aTimeout
- the specified timeout, in milliseconds.- Throws:
java.net.SocketException
- if there is an error in the underlying protocol, such as a TCP error.
-
getSoTimeout
public int getSoTimeout() throws java.io.IOException
Retrive setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).- Overrides:
getSoTimeout
in classjava.net.ServerSocket
- Returns:
- the SO_TIMEOUT value
- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
setSoTimeout(int)
-
setReuseAddress
public void setReuseAddress(boolean aOn) throws java.net.SocketException
Enable/disable the SO_REUSEADDR socket option.- Overrides:
setReuseAddress
in classjava.net.ServerSocket
- Parameters:
aOn
- whether to enable or disable the socket option- Throws:
java.net.SocketException
- if an error occurs enabling or disabling the SO_RESUEADDR socket option, or the socket is closed.
-
getReuseAddress
public boolean getReuseAddress() throws java.net.SocketException
Tests if SO_REUSEADDR is enabled.- Overrides:
getReuseAddress
in classjava.net.ServerSocket
- Returns:
- a
boolean
indicating whether or not SO_REUSEADDR is enabled. - Throws:
java.net.SocketException
- if there is an error in the underlying protocol, such as a TCP error.- See Also:
setReuseAddress(boolean)
-
toString
public java.lang.String toString()
Returns the implementation address and implementation port of this socket as aString
.- Overrides:
toString
in classjava.net.ServerSocket
- Returns:
- a string representation of this socket.
-
setReceiveBufferSize
public void setReceiveBufferSize(int aSize) throws java.net.SocketException
Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocketWrapper.- Overrides:
setReceiveBufferSize
in classjava.net.ServerSocket
- Parameters:
aSize
- the size to which to set the receive buffer size. This value must be greater than 0.- Throws:
java.net.SocketException
- if there is an error in the underlying protocol, such as a TCP error.- See Also:
getReceiveBufferSize()
-
getReceiveBufferSize
public int getReceiveBufferSize() throws java.net.SocketException
Gets the value of the SO_RCVBUF option for this ServerSocketWrapper, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocketWrapper.- Overrides:
getReceiveBufferSize
in classjava.net.ServerSocket
- Returns:
- the value of the SO_RCVBUF option for this Socket.
- Throws:
java.net.SocketException
- if there is an error in the underlying protocol, such as a TCP error.- See Also:
setReceiveBufferSize(int)
-
-