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 * The name of the {@code boolean} property of the {@code socket} property
* of the {@code ServerSocketChannel} returned by {@link #openAndBind(Map, * of the {@code ServerSocketChannel} returned by
* SocketAddress, int, DatagramPacketFilter)} which specifies the value of * {@link #openAndBindMuxServerSocketChannel(Map, SocketAddress, int,
* the {@code SO_REUSEADDR} socket option. * DatagramPacketFilter)} which specifies the value of the
* {@code SO_REUSEADDR} socket option.
*/ */
public static final String SOCKET_REUSE_ADDRESS_PROPERTY_NAME public static final String SOCKET_REUSE_ADDRESS_PROPERTY_NAME
= "socket.reuseAddress"; = "socket.reuseAddress";
@ -89,6 +90,7 @@ public class MuxServerSocketChannelFactory
"ICE4J does not support sharing of listening endpoints" "ICE4J does not support sharing of listening endpoints"
+ " (probably because it is not running on JDK 8)."); + " (probably because it is not running on JDK 8).");
} }
Method method; Method method;
if (clazz == null) if (clazz == null)
@ -128,6 +130,8 @@ public class MuxServerSocketChannelFactory
} }
catch (IOException ioe) 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) if (value == null)
on = false; on = false;
else if (value instanceof Boolean) else if (value instanceof Boolean)
on = ((Boolean) value).booleanValue(); on = (Boolean) value;
else else
on = Boolean.valueOf(value.toString()); 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 * The (ordered) list (i.e. queue) of <tt>SocketChannel</tt>s to be returned
* by {@link #accept()}. * by {@link #accept()}.
*/ */
private final Queue<SocketChannel> acceptQ private final Queue<SocketChannel> acceptQ = new LinkedList<>();
= new LinkedList<SocketChannel>();
/** /**
* The {@code DatagramPacketFilter} which demultiplexes * The {@code DatagramPacketFilter} which demultiplexes
@ -141,54 +140,66 @@ public class MuxServerSocketChannel
throws IOException throws IOException
{ {
SocketChannel accepted; SocketChannel accepted;
boolean interrupted = false;
// Pop a SocketChannel from acceptQ. // Pop a SocketChannel from acceptQ.
do try
{ {
if (!isOpen()) do
{ {
throw new ClosedChannelException(); if (!isOpen())
}
else if (!isBound())
{
throw new NotYetBoundException();
}
else
{
synchronized (syncRoot)
{ {
accepted = acceptQ.poll(); throw new ClosedChannelException();
if (accepted == null) }
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; return accepted;
} }
@ -210,13 +221,8 @@ public class MuxServerSocketChannel
*/ */
protected boolean filterAccept(DatagramPacket p, SocketChannel channel) protected boolean filterAccept(DatagramPacket p, SocketChannel channel)
{ {
boolean b; return
filter.accept(p) && qAccept(new PreReadSocketChannel(p, channel));
if (filter.accept(p))
b = qAccept(new PreReadSocketChannel(p, channel));
else
b = false;
return b;
} }
/** /**

View File

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

View File

@ -40,7 +40,7 @@ class PreReadSocketChannel
/** /**
* Initializes a new {@code PreReadSocketChannel} instance which is to * 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}. * {@link SocketChannel}.
* *
* @param preRead the {@code DatagramPacket} to prepend to {@code delegate} * @param preRead the {@code DatagramPacket} to prepend to {@code delegate}