Fixes warnings.

This commit is contained in:
Lyubomir Marinov 2016-03-04 20:27:09 -06:00
parent 902321c4e1
commit 91c7888085
4 changed files with 96 additions and 77 deletions

View File

@ -55,9 +55,10 @@ public class MuxServerSocketChannelFactory
/**
* The name of the {@code boolean} property of the {@code socket} property
* of the {@code ServerSocketChannel} returned by {@link #openAndBind(Map,
* SocketAddress, int, DatagramPacketFilter)} which specifies the value of
* the {@code SO_REUSEADDR} socket option.
* of the {@code ServerSocketChannel} returned by
* {@link #openAndBindMuxServerSocketChannel(Map, SocketAddress, int,
* DatagramPacketFilter)} which specifies the value of the
* {@code SO_REUSEADDR} socket option.
*/
public static final String SOCKET_REUSE_ADDRESS_PROPERTY_NAME
= "socket.reuseAddress";
@ -89,6 +90,7 @@ public class MuxServerSocketChannelFactory
"ICE4J does not support sharing of listening endpoints"
+ " (probably because it is not running on JDK 8).");
}
Method method;
if (clazz == null)
@ -128,6 +130,8 @@ public class MuxServerSocketChannelFactory
}
catch (IOException ioe)
{
// The whole idea of the method is to close a specific Channel
// without caring about any possible IOException.
}
}
@ -245,7 +249,7 @@ public class MuxServerSocketChannelFactory
if (value == null)
on = false;
else if (value instanceof Boolean)
on = ((Boolean) value).booleanValue();
on = (Boolean) value;
else
on = Boolean.valueOf(value.toString());

View File

@ -93,8 +93,7 @@ public class MuxServerSocketChannel
* The (ordered) list (i.e. queue) of <tt>SocketChannel</tt>s to be returned
* by {@link #accept()}.
*/
private final Queue<SocketChannel> acceptQ
= new LinkedList<SocketChannel>();
private final Queue<SocketChannel> acceptQ = new LinkedList<>();
/**
* The {@code DatagramPacketFilter} which demultiplexes
@ -141,54 +140,66 @@ public class MuxServerSocketChannel
throws IOException
{
SocketChannel accepted;
boolean interrupted = false;
// Pop a SocketChannel from acceptQ.
do
try
{
if (!isOpen())
do
{
throw new ClosedChannelException();
}
else if (!isBound())
{
throw new NotYetBoundException();
}
else
{
synchronized (syncRoot)
if (!isOpen())
{
accepted = acceptQ.poll();
if (accepted == null)
throw new ClosedChannelException();
}
else if (!isBound())
{
throw new NotYetBoundException();
}
else
{
synchronized (syncRoot)
{
if (isBlocking())
accepted = acceptQ.poll();
if (accepted == null)
{
try
if (isBlocking())
{
syncRoot.wait();
try
{
syncRoot.wait();
}
catch (InterruptedException ie)
{
interrupted = true;
}
}
catch (InterruptedException ie)
else
{
break;
}
}
else
else if (accepted.isOpen())
{
break;
// Allow the MuxServerSocketChannel class and/or its
// super(s) to have a final say on the accepted
// SocketChannel such as wrapping it into a suitable
// specialization of DelegatingSocketChannel.
accepted = implAccept(accepted);
if (accepted != null)
break;
}
}
else if (accepted.isOpen())
{
// Allow the MuxServerSocketChannel class and/or its
// super(s) to have a final say on the accepted
// SocketChannel such as wrapping it into a suitable
// specialization of DelegatingSocketChannel.
accepted = implAccept(accepted);
if (accepted != null)
break;
}
}
}
while (true);
}
finally
{
// Restore the interrupted state of the current thread if we've
// cleared it in the loop above.
if (interrupted)
Thread.currentThread().interrupt();
}
while (true);
return accepted;
}
@ -210,13 +221,8 @@ public class MuxServerSocketChannel
*/
protected boolean filterAccept(DatagramPacket p, SocketChannel channel)
{
boolean b;
if (filter.accept(p))
b = qAccept(new PreReadSocketChannel(p, channel));
else
b = false;
return b;
return
filter.accept(p) && qAccept(new PreReadSocketChannel(p, channel));
}
/**

View File

@ -60,7 +60,7 @@ class MuxingServerSocketChannel
*/
private static final List<MuxingServerSocketChannel>
muxingServerSocketChannels
= new LinkedList<MuxingServerSocketChannel>();
= new LinkedList<>();
/**
* The maximum number of milliseconds to wait for an accepted
@ -230,6 +230,8 @@ class MuxingServerSocketChannel
}
catch (IOException ioe)
{
// I don't know what to do about any IOException during
// Selector#close() even if I log it.
}
}
acceptSelector = null;
@ -369,27 +371,31 @@ class MuxingServerSocketChannel
}
catch (InterruptedException ie)
{
// I don't know that we care about the interrupted state
// of the current thread because that the method
// runInAcceptThread() is pretty much the whole
// execution of the current thread that could
// potentially care about the interrupted state and it
// doesn't.
}
continue;
}
}
// Wait for a new iteration of acceptance.
if (select)
// Wait for a new iteration of acceptance. (The value of the local
// variable select is guaranteed to be true.)
try
{
try
{
sel.select();
}
catch (ClosedSelectorException cse)
{
break;
}
catch (IOException ioe)
{
// Well, we're selecting from multiple SelectableChannels so
// we're not sure what the IOException signals here.
}
sel.select();
}
catch (ClosedSelectorException cse)
{
break;
}
catch (IOException ioe)
{
// Well, we're selecting from multiple SelectableChannels so
// we're not sure what the IOException signals here.
}
}
while (true);
@ -476,7 +482,7 @@ class MuxingServerSocketChannel
* this instance.
*/
private final List<MuxServerSocketChannel> muxServerSocketChannels
= new ArrayList<MuxServerSocketChannel>();
= new ArrayList<>();
/**
* The list of {@code SocketChannel}s which have been accepted by this
@ -484,7 +490,7 @@ class MuxingServerSocketChannel
* accepted by the {@link DatagramPacketFilter} of any
* {@link MuxServerSocketChannel} yet.
*/
private final Queue<SocketChannel> readQ = new LinkedList<SocketChannel>();
private final Queue<SocketChannel> readQ = new LinkedList<>();
/**
* The {@code Selector} which waits for incoming packets on all
@ -862,27 +868,30 @@ class MuxingServerSocketChannel
}
catch (InterruptedException ie)
{
// I don't know that we care about the interrupted state
// of the current thread because that the method
// runInReadThread() is pretty much the whole execution
// of the current thread that could potentially care
// about the interrupted state and it doesn't.
}
continue;
}
}
// Wait for a new iteration of acceptance.
if (select)
// Wait for a new iteration of acceptance. (The value of the local
// variable select is guaranteed to be true.)
try
{
try
{
sel.select();
}
catch (ClosedSelectorException cse)
{
break;
}
catch (IOException ioe)
{
// Well, we're selecting from multiple SelectableChannels so
// we're not sure what the IOException signals here.
}
sel.select();
}
catch (ClosedSelectorException cse)
{
break;
}
catch (IOException ioe)
{
// Well, we're selecting from multiple SelectableChannels so
// we're not sure what the IOException signals here.
}
}
while (true);

View File

@ -40,7 +40,7 @@ class PreReadSocketChannel
/**
* Initializes a new {@code PreReadSocketChannel} instance which is to
* prepend a specific {@link DatagrapPacket} to a specific
* prepend a specific {@link DatagramPacket} to a specific
* {@link SocketChannel}.
*
* @param preRead the {@code DatagramPacket} to prepend to {@code delegate}