-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public class MergingDatagramSocket extends DatagramSocket
A DatagramSocket implementation which merges a set of sockets. It maintains a thread reading from each of the underlying sockets. Thus received datagrams are provided via the receive API, in the order in which they were originally received (or close to it, since the implementation is only based on timestamps). One of the underlying sockets is used as a delegate, and handles sending via send and calls to getLocalPort, getLocalAddress and getLocalSocketAddress.
-
-
Field Summary
Fields Modifier and Type Field Description private intsoTimeout
-
Constructor Summary
Constructors Constructor Description MergingDatagramSocket()Initializes a new MergingDatagramSocket instance. MergingDatagramSocket(Logger parentLogger)Initializes a new MergingDatagramSocket instance.
-
Method Summary
Modifier and Type Method Description intgetSoTimeout()voidsetSoTimeout(int soTimeout)booleanisClosed()voidclose()voidsend(DatagramPacket pkt)The current implementation delegates to the first container, but this is subject to change. voidadd(DelegatingSocket socket)Adds a DelegatingSocket instance to this merging socket. voidadd(IceSocketWrapper wrapper)Adds the socket instance wrapped by wrapperto this merging socket.voidadd(DatagramSocket socket)Adds a DatagramSocket instance to this merging socket. voidremove(DatagramSocket socket)Removes a specific DatagramSocket from the list of sockets merged by this MergingDatagramSocket. voidremove(DelegatingSocket socket)Removes a specific DelegatingSocket from the list of sockets merged by this MergingDatagramSocket. InetAddressgetLocalAddress()Delegates to the "active" socket, if one exists. intgetLocalPort()Delegates to the "active" socket, if one exists. SocketAddressgetLocalSocketAddress()Delegates to the "active" socket, if one exists. voidreceive(DatagramPacket p)Copies into pa packet already received from one of the underlying sockets.-
Methods inherited from class java.net.DatagramSocket
bind, connect, disconnect, getBroadcast, getChannel, getInetAddress, getOption, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isConnected, setBroadcast, setDatagramSocketImplFactory, setOption, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass, supportedOptions -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
MergingDatagramSocket
MergingDatagramSocket()
Initializes a new MergingDatagramSocket instance.
-
MergingDatagramSocket
MergingDatagramSocket(Logger parentLogger)
Initializes a new MergingDatagramSocket instance.- Parameters:
parentLogger- the Logger parent logger from which we'll derive this class' logger instance
-
-
Method Detail
-
getSoTimeout
int getSoTimeout()
-
setSoTimeout
void setSoTimeout(int soTimeout)
-
isClosed
boolean isClosed()
-
close
void close()
-
send
void send(DatagramPacket pkt)
The current implementation delegates to the first container, but this is subject to change.- Parameters:
pkt- the datagram to send.
-
add
void add(DelegatingSocket socket)
Adds a DelegatingSocket instance to this merging socket. Note that this will start a thread reading from the added socket.
- Parameters:
socket- the socket to add.
-
add
void add(IceSocketWrapper wrapper)
Adds the socket instance wrapped by
wrapperto this merging socket. Note that this will start a thread reading from the added socket.- Parameters:
wrapper- the wrapper of the socket to add.
-
add
void add(DatagramSocket socket)
Adds a DatagramSocket instance to this merging socket. Note that this will start a thread reading from the added socket.
- Parameters:
socket- the socket to add.
-
remove
void remove(DatagramSocket socket)
Removes a specific DatagramSocket from the list of sockets merged by this MergingDatagramSocket.
- Parameters:
socket- the DatagramSocket to remove.
-
remove
void remove(DelegatingSocket socket)
Removes a specific DelegatingSocket from the list of sockets merged by this MergingDatagramSocket.
- Parameters:
socket- the DelegatingSocket to remove.
-
getLocalAddress
InetAddress getLocalAddress()
Delegates to the "active" socket, if one exists. Else returnsnull.
-
getLocalPort
int getLocalPort()
Delegates to the "active" socket, if one exists. Else returns0. TODO: should we return 0 (unbound) or -1 (closed) if there are no sockets?
-
getLocalSocketAddress
SocketAddress getLocalSocketAddress()
Delegates to the "active" socket, if one exists. Else returnsnull.
-
receive
void receive(DatagramPacket p)
Copies intopa packet already received from one of the underlying sockets. The socket is chosen on the base of the timestamp of the reception of the first packet in its queue (so that earlier packets are received first).
-
-
-
-