HCOLL-133 CloseablesManager.checkState is throwing java.lang.IllegalStateException

This commit is contained in:
Rob Austin
2014-09-23 19:17:04 +01:00
parent 511f195a9f
commit abc56b855a
3 changed files with 45 additions and 4 deletions
@@ -329,16 +329,39 @@ abstract class AbstractChannelReplicator implements Closeable {
final Thread thread = new Thread(new Runnable() {
public void run() {
SelectableChannel socketChannel = null;
try {
if (reconnectionInterval > 0)
Thread.sleep(reconnectionInterval);
SelectableChannel socketChannel = doConnect();
closeables.add(socketChannel);
socketChannel = doConnect();
try {
closeables.add(socketChannel);
} catch (IllegalStateException e) {
// close could have be called from another thread, while we were in Thread.sleep()
// which would cause a IllegalStateException
closeQuietly(socketChannel);
return;
}
AbstractConnector.this.socketChannel = socketChannel;
} catch (Exception e) {
LOG.error("", e);
closeQuietly(socketChannel);
LOG.debug("", e);
}
}
private void closeQuietly(SelectableChannel socketChannel) {
if (socketChannel == null)
return;
try {
socketChannel.close();
} catch (Exception e1) {
// do nothing
}
}
});
@@ -346,6 +369,8 @@ abstract class AbstractChannelReplicator implements Closeable {
thread.setName(name);
thread.setDaemon(true);
thread.start();
}
public void setSuccessfullyConnected() {
@@ -29,7 +29,7 @@ final class CloseablesManager implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(CloseablesManager.class.getName());
private boolean isClosed = false;
private List<Closeable> closeables = new ArrayList<Closeable>();
private final List<Closeable> closeables = new ArrayList<>();
private void checkState() {
if (isClosed)
@@ -84,4 +84,8 @@ final class CloseablesManager implements Closeable {
// do nothing
}
}
boolean isClosed() {
return isClosed;
}
}