org.xsocket.datagram
Class ConnectedEndpoint

Package class diagram package ConnectedEndpoint
java.lang.Object
  extended by org.xsocket.datagram.ConnectedEndpoint
All Implemented Interfaces:
java.io.Closeable, IConnectedEndpoint, IEndpoint

public final class ConnectedEndpoint
extends java.lang.Object
implements IConnectedEndpoint

connected endpoint implementation


Field Summary
 
Fields inherited from interface org.xsocket.datagram.IEndpoint
DEFAULT_HOST_ADDRESS, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TOS, SO_BROADCAST, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF
 
Constructor Summary
ConnectedEndpoint(java.net.SocketAddress remoteAddress)
          Constructs a client/server datagram socket and binds it to any available port on the local host machine.
ConnectedEndpoint(java.net.SocketAddress remoteAddress, DatagramSocketConfiguration socketConfiguration)
          Deprecated.  
ConnectedEndpoint(java.net.SocketAddress remoteAddress, DatagramSocketConfiguration socketConfiguration, int receivePacketSize)
          Deprecated.  
ConnectedEndpoint(java.net.SocketAddress remoteAddress, DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler)
          Deprecated.  
ConnectedEndpoint(java.net.SocketAddress remoteAddress, DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler, java.util.concurrent.Executor workerPool)
          Deprecated.  
ConnectedEndpoint(java.net.SocketAddress remoteAddress, int receivePacketSize)
          Constructs a client/server datagram socket and binds it to the given available port on the local host machine.
ConnectedEndpoint(java.net.SocketAddress remoteAddress, int receivePacketSize, IDatagramHandler datagramHandler)
          Constructs a client/server datagram socket and binds it to the given available port on the local host machine.
ConnectedEndpoint(java.net.SocketAddress remoteAddress, java.util.Map<java.lang.String,java.lang.Object> options, int receivePacketSize, IDatagramHandler datagramHandler, java.util.concurrent.Executor workerPool)
          Constructs a client/server datagram socket and binds it to the given available port on the local host machine.
ConnectedEndpoint(java.lang.String host, int port)
          Constructs a client/server datagram socket and binds it to any available port on the local host machine.
ConnectedEndpoint(java.lang.String host, int port, DatagramSocketConfiguration socketConfiguration)
          Deprecated.  
ConnectedEndpoint(java.lang.String host, int port, DatagramSocketConfiguration socketConfiguration, int receivePacketSize)
          Deprecated.  
ConnectedEndpoint(java.lang.String host, int port, int receivePacketSize)
          Constructs a client/server datagram socket and binds it to the given available port on the local host machine.
 
Method Summary
 void close()
          
 java.lang.String getDefaultEncoding()
          gets the default encoding used by this endpoint
 java.lang.String getId()
          return the id
 java.net.InetAddress getLocalAddress()
          returns the address of the endpoint
 int getLocalPort()
          returns the port of the endpoint
 java.net.SocketAddress getLocalSocketAddress()
          Deprecated.  
 java.lang.Object getOption(java.lang.String name)
          returns the vlaue of a option
 java.util.Map<java.lang.String,java.lang.Class> getOptions()
          Returns an unmodifiable map of the options supported by this endpont.
 int getReceiveSize()
          get the size of the datagram that will be received
 java.net.SocketAddress getRemoteSocketAddress()
          return the connected remote address or null if not connected
 java.util.concurrent.Executor getWorkerpool()
          return the worker pool
 IWorkerPool getWorkerPool()
          Deprecated.  
 boolean isOpen()
          returns, if the endpoint is open
 UserDatagram receive()
          receive a datagram packet (receive timeout = 0)
 UserDatagram receive(long timeoutMillis)
          receive a datagram packet
 void send(UserDatagram packet)
          send a datagram to the remote endpoint
 void setDefaultEncoding(java.lang.String defaultEncoding)
          sets the default encoding used by this endpoint
 void setReceiveSize(int receivePacketSize)
          set the size of the datagram that will be received
 void setWorkerPool(IWorkerPool workerPool)
          Deprecated.  
 java.lang.String toCompactString()
          a compact string of this endpoint
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xsocket.datagram.IEndpoint
getDefaultEncoding, getId, getLocalAddress, getLocalPort, getLocalSocketAddress, getOption, getOptions, getReceiveSize, isOpen, receive, receive, setDefaultEncoding, setReceiveSize, setWorkerPool
 
Methods inherited from interface java.io.Closeable
close
 

Constructor Detail

ConnectedEndpoint

public ConnectedEndpoint(java.lang.String host,
                         int port)
                  throws java.io.IOException
Constructs a client/server datagram socket and binds it to any available port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel. The local socket will be connected to the server by using the passed over addresses

Parameters:
host - the remote host
port - the remote port
Throws:
java.io.IOException - If some I/O error occurs

ConnectedEndpoint

public ConnectedEndpoint(java.lang.String host,
                         int port,
                         DatagramSocketConfiguration socketConfiguration)
                  throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress)
                  throws java.io.IOException
Constructs a client/server datagram socket and binds it to any available port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel. The local socket will be connected to the server by using the passed over addresses

Throws:
java.io.IOException - If some I/O error occurs

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress,
                         DatagramSocketConfiguration socketConfiguration)
                  throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress,
                         int receivePacketSize)
                  throws java.io.IOException
Constructs a client/server datagram socket and binds it to the given available port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel. The local socket will be connected to the server by using the passed over addresses

Parameters:
remoteAddress - the remote socket address
receivePacketSize - the receive packet size
Throws:
java.io.IOException - If some I/O error occurs

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress,
                         DatagramSocketConfiguration socketConfiguration,
                         int receivePacketSize)
                  throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

ConnectedEndpoint

public ConnectedEndpoint(java.lang.String host,
                         int port,
                         int receivePacketSize)
                  throws java.io.IOException
Constructs a client/server datagram socket and binds it to the given available port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel. The local socket will be connected to the server by using the passed over addresses

Parameters:
host - the remote host
port - the remote port
receivePacketSize - the receive packet size
Throws:
java.io.IOException - If some I/O error occurs

ConnectedEndpoint

public ConnectedEndpoint(java.lang.String host,
                         int port,
                         DatagramSocketConfiguration socketConfiguration,
                         int receivePacketSize)
                  throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress,
                         int receivePacketSize,
                         IDatagramHandler datagramHandler)
                  throws java.io.IOException
Constructs a client/server datagram socket and binds it to the given available port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel. The local socket will be connected to the server by using the passed over addresses

Parameters:
remoteAddress - the remote socket address
receivePacketSize - the receive packet size
datagramHandler - the datagram handler
Throws:
java.io.IOException - If some I/O error occurs

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress,
                         DatagramSocketConfiguration socketConfiguration,
                         int receivePacketSize,
                         IDatagramHandler datagramHandler)
                  throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress,
                         DatagramSocketConfiguration socketConfiguration,
                         int receivePacketSize,
                         IDatagramHandler datagramHandler,
                         java.util.concurrent.Executor workerPool)
                  throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

ConnectedEndpoint

public ConnectedEndpoint(java.net.SocketAddress remoteAddress,
                         java.util.Map<java.lang.String,java.lang.Object> options,
                         int receivePacketSize,
                         IDatagramHandler datagramHandler,
                         java.util.concurrent.Executor workerPool)
                  throws java.io.IOException
Constructs a client/server datagram socket and binds it to the given available port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel. The local socket will be connected to the server by using the passed over addresses

Parameters:
remoteAddress - the remote socket address
socketOptions - the socket options
receivePacketSize - the receive packet size
datagramHandler - the datagram handler
workerPool - the worker pool
Throws:
java.io.IOException - If some I/O error occurs
Method Detail

send

public void send(UserDatagram packet)
          throws java.io.IOException
send a datagram to the remote endpoint

Specified by:
send in interface IEndpoint
Parameters:
packet - the datagram to send
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

getRemoteSocketAddress

public java.net.SocketAddress getRemoteSocketAddress()
return the connected remote address or null if not connected

Specified by:
getRemoteSocketAddress in interface IConnectedEndpoint
Returns:
the connected address

close

public final void close()

Specified by:
close in interface java.io.Closeable

getLocalSocketAddress

public final java.net.SocketAddress getLocalSocketAddress()
Deprecated. 

Specified by:
getLocalSocketAddress in interface IEndpoint

getLocalAddress

public final java.net.InetAddress getLocalAddress()
returns the address of the endpoint

Specified by:
getLocalAddress in interface IEndpoint
Returns:
the address

getLocalPort

public final int getLocalPort()
returns the port of the endpoint

Specified by:
getLocalPort in interface IEndpoint
Returns:
the port

isOpen

public final boolean isOpen()
returns, if the endpoint is open

Specified by:
isOpen in interface IEndpoint
Returns:
true if the endpoint is open

toCompactString

public java.lang.String toCompactString()
a compact string of this endpoint


getOption

public java.lang.Object getOption(java.lang.String name)
                           throws java.io.IOException
returns the vlaue of a option

Specified by:
getOption in interface IEndpoint
Parameters:
name - the name of the option
Returns:
the value of the option
Throws:
java.io.IOException - In an I/O error occurs

getOptions

public java.util.Map<java.lang.String,java.lang.Class> getOptions()
Description copied from interface: IEndpoint
Returns an unmodifiable map of the options supported by this endpont. The key in the returned map is the name of a option, and its value is the type of the option value. The returned map will never contain null keys or values.

Specified by:
getOptions in interface IEndpoint
Returns:
An unmodifiable map of the options supported by this channel

setWorkerPool

public void setWorkerPool(IWorkerPool workerPool)
Deprecated. 

set the worker pool to use

Specified by:
setWorkerPool in interface IEndpoint
Parameters:
workerPool - the worker pool to use

getWorkerPool

public IWorkerPool getWorkerPool()
Deprecated. 

return the worker pool

Returns:
the worker pool

getWorkerpool

public java.util.concurrent.Executor getWorkerpool()
return the worker pool

Returns:
the worker pool

setReceiveSize

public final void setReceiveSize(int receivePacketSize)
set the size of the datagram that will be received

Specified by:
setReceiveSize in interface IEndpoint
Parameters:
receivePacketSize - the receive size

getReceiveSize

public final int getReceiveSize()
get the size of the datagram that will be received

Specified by:
getReceiveSize in interface IEndpoint
Returns:
the receive size

receive

public final UserDatagram receive(long timeoutMillis)
                           throws java.io.IOException,
                                  java.net.SocketTimeoutException
receive a datagram packet

Specified by:
receive in interface IEndpoint
Parameters:
timeoutMillis - the receive timeout in millis
Returns:
the received datagram packet
Throws:
java.net.SocketTimeoutException - If the receive timeout has been reached
java.io.IOException - If some other I/O error occurs

receive

public UserDatagram receive()
Description copied from interface: IEndpoint
receive a datagram packet (receive timeout = 0)

Specified by:
receive in interface IEndpoint
Returns:
the received datagram packet or null if no datagram is available

getDefaultEncoding

public final java.lang.String getDefaultEncoding()
gets the default encoding used by this endpoint

Specified by:
getDefaultEncoding in interface IEndpoint
Returns:
the default encoding

setDefaultEncoding

public final void setDefaultEncoding(java.lang.String defaultEncoding)
sets the default encoding used by this endpoint

Specified by:
setDefaultEncoding in interface IEndpoint
Parameters:
defaultEncoding - the default encoding

getId

public final java.lang.String getId()
return the id

Specified by:
getId in interface IEndpoint
Returns:
the id

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object