org.xsocket.datagram
Class Endpoint

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

public final class Endpoint
extends java.lang.Object
implements IEndpoint

Endpoint implementation


Field Summary
 
Fields inherited from interface org.xsocket.datagram.IEndpoint
IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TOS, SO_BROADCAST, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF
 
Constructor Summary
Endpoint()
          Constructs a datagram socket and binds it to any available port on the local host machine.
Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize)
          Deprecated.  
Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler)
          Deprecated.  
Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler, java.util.concurrent.Executor workerPool, java.net.InetAddress address, int port)
          Deprecated.  
Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler, java.net.InetAddress address, int port)
          Deprecated.  
Endpoint(int receivePacketSize)
          Constructs a datagram socket and binds it to any available port on the local host machine.
Endpoint(int receivePacketSize, IDatagramHandler datagramHandler)
          Constructs a datagram socket and binds it to any available port on the local host machine.
Endpoint(int receivePacketSize, IDatagramHandler datagramHandler, java.util.concurrent.Executor workerPool)
          Constructs a datagram socket and binds it to any available port on the local host machine.
Endpoint(int receivePacketSize, IDatagramHandler datagramHandler, java.util.concurrent.Executor workerPool, java.net.InetAddress address, int port)
          Constructs a datagram socket and binds it to the given port on the local host machine.
Endpoint(int receivePacketSize, IDatagramHandler datagramHandler, java.net.InetAddress address, int port)
          Constructs a datagram socket and binds it to the given port on the local host machine.
Endpoint(java.util.Map<java.lang.String,java.lang.Object> options, int receivePacketSize, IDatagramHandler datagramHandler, java.util.concurrent.Executor workerPool, java.net.InetAddress address, int port)
          Constructs a datagram socket and binds it to the given 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.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, send, setDefaultEncoding, setReceiveSize, setWorkerPool
 
Methods inherited from interface java.io.Closeable
close
 

Constructor Detail

Endpoint

public Endpoint()
         throws java.io.IOException
Constructs a 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.

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

Endpoint

public Endpoint(int receivePacketSize)
         throws java.io.IOException
Constructs a 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.

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

Endpoint

public Endpoint(DatagramSocketConfiguration socketConfiguration,
                int receivePacketSize)
         throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

Endpoint

public Endpoint(int receivePacketSize,
                IDatagramHandler datagramHandler)
         throws java.io.IOException
Constructs a 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.

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

Endpoint

public Endpoint(int receivePacketSize,
                IDatagramHandler datagramHandler,
                java.util.concurrent.Executor workerPool)
         throws java.io.IOException
Constructs a 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.

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

Endpoint

public Endpoint(DatagramSocketConfiguration socketConfiguration,
                int receivePacketSize,
                IDatagramHandler datagramHandler)
         throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

Endpoint

public Endpoint(int receivePacketSize,
                IDatagramHandler datagramHandler,
                java.net.InetAddress address,
                int port)
         throws java.io.IOException
Constructs a datagram socket and binds it to the given port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel.

Parameters:
receivePacketSize - the receive packet size
datagramHandler - the datagram handler
address - the local address
port - the local port which must be between 0 and 65535 inclusive.
Throws:
java.io.IOException - If some I/O error occurs

Endpoint

public Endpoint(DatagramSocketConfiguration socketConfiguration,
                int receivePacketSize,
                IDatagramHandler datagramHandler,
                java.net.InetAddress address,
                int port)
         throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

Endpoint

public Endpoint(DatagramSocketConfiguration socketConfiguration,
                int receivePacketSize,
                IDatagramHandler datagramHandler,
                java.util.concurrent.Executor workerPool,
                java.net.InetAddress address,
                int port)
         throws java.io.IOException
Deprecated. 

Throws:
java.io.IOException

Endpoint

public Endpoint(java.util.Map<java.lang.String,java.lang.Object> options,
                int receivePacketSize,
                IDatagramHandler datagramHandler,
                java.util.concurrent.Executor workerPool,
                java.net.InetAddress address,
                int port)
         throws java.io.IOException
Constructs a datagram socket and binds it to the given port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel.

Parameters:
options - the socket options
receivePacketSize - the receive packet size
datagramHandler - the datagram handler
address - the local address
port - the local port which must be between 0 and 65535 inclusive.
workerPool - the workerPool
Throws:
java.io.IOException - If some I/O error occurs

Endpoint

public Endpoint(int receivePacketSize,
                IDatagramHandler datagramHandler,
                java.util.concurrent.Executor workerPool,
                java.net.InetAddress address,
                int port)
         throws java.io.IOException
Constructs a datagram socket and binds it to the given port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel.

Parameters:
receivePacketSize - the receive packet size
datagramHandler - the datagram handler
address - the local address
port - the local port which must be between 0 and 65535 inclusive.
workerPool - the workerPool
Throws:
java.io.IOException - If some I/O error occurs
Method Detail

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

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

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