use of java.nio.channels.Selector in project hazelcast by hazelcast.
the class NonBlockingIOThread method rebuildSelector.
// this method is always invoked in this thread
// after we have blocked for selector.select in #runSelectLoopWithSelectorFix
private void rebuildSelector() {
selectorRebuildCount.inc();
Selector newSelector = newSelector(logger);
Selector oldSelector = this.selector;
// reset each handler's selectionKey, cancel the old keys
for (SelectionKey key : oldSelector.keys()) {
AbstractHandler handler = (AbstractHandler) key.attachment();
SelectableChannel channel = key.channel();
try {
int ops = key.interestOps();
SelectionKey newSelectionKey = channel.register(newSelector, ops, handler);
handler.setSelectionKey(newSelectionKey);
} catch (ClosedChannelException e) {
logger.info("Channel was closed while trying to register with new selector.");
} catch (CancelledKeyException e) {
// a CancelledKeyException may be thrown in key.interestOps
// in this case, since the key is already cancelled, just do nothing
EmptyStatement.ignore(e);
}
key.cancel();
}
// close the old selector and substitute with new one
closeSelector();
this.selector = newSelector;
logger.warning("Recreated Selector because of possible java/network stack bug.");
}
use of java.nio.channels.Selector in project hazelcast by hazelcast.
the class SelectorOptimizerTest method optimize.
@Test
public void optimize() throws Exception {
Selector selector = Selector.open();
assumeTrue(findOptimizableSelectorClass(selector) != null);
SelectorOptimizer.SelectionKeysSet keys = SelectorOptimizer.optimize(selector, logger);
assertNotNull(keys);
}
use of java.nio.channels.Selector in project hazelcast by hazelcast.
the class SocketAcceptorThread method shutdown.
public synchronized void shutdown() {
if (!live) {
return;
}
logger.finest("Shutting down SocketAcceptor thread.");
live = false;
Selector sel = selector;
if (sel != null) {
sel.wakeup();
}
try {
join(SHUTDOWN_TIMEOUT_MILLIS);
} catch (InterruptedException e) {
logger.finest(e);
}
}
use of java.nio.channels.Selector in project robovm by robovm.
the class SelectorTest method testLeakingPipes.
// We previously leaked a file descriptor for each selector instance created.
//
// http://code.google.com/p/android/issues/detail?id=5993
// http://code.google.com/p/android/issues/detail?id=4825
public void testLeakingPipes() throws IOException {
for (int i = 0; i < 2000; i++) {
Selector selector = Selector.open();
selector.close();
}
}
use of java.nio.channels.Selector in project robovm by robovm.
the class SelectorTest method testNonBlockingConnect_slow.
public void testNonBlockingConnect_slow() throws Exception {
// Test the case where we have to wait for the connection.
Selector selector = Selector.open();
StuckServer ss = new StuckServer(true);
try {
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
sc.connect(ss.getLocalSocketAddress());
SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
assertEquals(1, selector.select());
assertEquals(SelectionKey.OP_CONNECT, key.readyOps());
sc.finishConnect();
} finally {
selector.close();
ss.close();
}
}
Aggregations