Adds a method that allows to check if there is a MultiplexedDatagramSocket for a particular DatagramPacketFilter.

This commit is contained in:
boris 2014-08-05 14:06:30 +00:00
parent 08766354dc
commit c25c0915b5

View File

@ -320,6 +320,32 @@ public class MultiplexingDatagramSocket
* fails
*/
public MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter)
throws SocketException
{
return getSocket(filter, true);
}
/**
* Gets a <tt>MultiplexedDatagramSocket</tt> which filters
* <tt>DatagramPacket</tt>s away from this <tt>DatagramSocket</tt> using a
* specific <tt>DatagramPacketFilter</tt>. If <tt>create</tt> is true and
* such a <tt>MultiplexedDatagramSocket</tt> does not exist in this
* instance, it is created.
*
* @param filter the <tt>DatagramPacketFilter</tt> to get a
* <tt>MultiplexedDatagramSocket</tt> for
* @param create whether or not to create a <tt>MultiplexedDatagramSocket</tt>
* if this instance does not already have a socket for the given
* <tt>filter</tt>.
* @return a <tt>MultiplexedDatagramSocket</tt> which filters
* <tt>DatagramPacket</tt>s away from this <tt>DatagramSocket</tt> using the
* specified <tt>filter</tt>
* @throws SocketException if creating the
* <tt>MultiplexedDatagramSocket</tt> for the specified <tt>filter</tt>
* fails.
*/
public MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter,
boolean create)
throws SocketException
{
if (filter == null)
@ -337,6 +363,9 @@ public class MultiplexingDatagramSocket
return socket;
}
if (!create)
return null;
// Create a new socket for the specified filter.
MultiplexedDatagramSocket socket
= new MultiplexedDatagramSocket(this, filter);