diff --git a/src/main/java/org/ice4j/socket/MuxServerSocketChannelFactory.java b/src/main/java/org/ice4j/socket/MuxServerSocketChannelFactory.java
index 44e8e82..b63e5c5 100644
--- a/src/main/java/org/ice4j/socket/MuxServerSocketChannelFactory.java
+++ b/src/main/java/org/ice4j/socket/MuxServerSocketChannelFactory.java
@@ -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());
diff --git a/src/main/java/org/ice4j/socket/jdk8/MuxServerSocketChannel.java b/src/main/java/org/ice4j/socket/jdk8/MuxServerSocketChannel.java
index a256ee7..0fac6da 100644
--- a/src/main/java/org/ice4j/socket/jdk8/MuxServerSocketChannel.java
+++ b/src/main/java/org/ice4j/socket/jdk8/MuxServerSocketChannel.java
@@ -93,8 +93,7 @@ public class MuxServerSocketChannel
* The (ordered) list (i.e. queue) of SocketChannels to be returned
* by {@link #accept()}.
*/
- private final Queue acceptQ
- = new LinkedList();
+ private final Queue 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));
}
/**
diff --git a/src/main/java/org/ice4j/socket/jdk8/MuxingServerSocketChannel.java b/src/main/java/org/ice4j/socket/jdk8/MuxingServerSocketChannel.java
index dca270a..fbf3834 100644
--- a/src/main/java/org/ice4j/socket/jdk8/MuxingServerSocketChannel.java
+++ b/src/main/java/org/ice4j/socket/jdk8/MuxingServerSocketChannel.java
@@ -60,7 +60,7 @@ class MuxingServerSocketChannel
*/
private static final List
muxingServerSocketChannels
- = new LinkedList();
+ = 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 muxServerSocketChannels
- = new ArrayList();
+ = 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 readQ = new LinkedList();
+ private final Queue 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);
diff --git a/src/main/java/org/ice4j/socket/jdk8/PreReadSocketChannel.java b/src/main/java/org/ice4j/socket/jdk8/PreReadSocketChannel.java
index 85ade97..8dcc7dc 100644
--- a/src/main/java/org/ice4j/socket/jdk8/PreReadSocketChannel.java
+++ b/src/main/java/org/ice4j/socket/jdk8/PreReadSocketChannel.java
@@ -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}