HCOLL-167 when running the profile I found that we were not closing every connection, so no being super fussy about adding everything to closable.

This commit is contained in:
Rob Austin
2014-10-20 13:02:42 +01:00
parent 0043b16d5e
commit 023d12a6d0
6 changed files with 170 additions and 94 deletions
@@ -27,10 +27,7 @@ import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.*;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -65,8 +62,7 @@ abstract class AbstractChannelReplicator implements Closeable {
throws IOException {
executorService = Executors.newSingleThreadExecutor(
new NamedThreadFactory(name, true));
selector = Selector.open();
closeables.add(selector);
selector = openSelector();
throttler = throttlingConfig.throttling(DAYS) > 0 ?
new Throttler(selector,
@@ -74,6 +70,29 @@ abstract class AbstractChannelReplicator implements Closeable {
maxEntrySizeBytes, throttlingConfig.throttling(DAYS)) : null;
}
Selector openSelector() throws IOException {
Selector result = null;
try {
result = Selector.open();
} finally {
if (result != null)
closeables.add(result);
}
return result;
}
SocketChannel openSocketChannel() throws IOException {
SocketChannel result = null;
try {
result = SocketChannel.open();
} finally {
if (result != null)
closeables.add(result);
}
return result;
}
void addPendingRegistration(Runnable registration) {
pendingRegistrations.add(registration);
}
@@ -389,4 +408,5 @@ abstract class AbstractChannelReplicator implements Closeable {
}
}
}