use of java.nio.channels.Selector in project jeromq by zeromq.
the class Poller method rebuildSelector.
private void rebuildSelector() {
Selector newSelector;
try {
newSelector = Selector.open();
} catch (IOException e) {
throw new ZError.IOException(e);
}
try {
selector.close();
} catch (IOException e) {
}
selector = newSelector;
for (PollSet pollSet : fdTable.values()) {
pollSet.key = null;
}
retired.set(true);
}
use of java.nio.channels.Selector in project robovm by robovm.
the class UnixSelectorTest method testSelectUnConnectedChannel.
public void testSelectUnConnectedChannel() throws Exception {
SocketChannel socketChannel2 = SocketChannel.open();
socketChannel2.configureBlocking(false);
Selector sel3 = Selector.open();
SelectionKey mkey3 = socketChannel2.register(sel3, SelectionKey.OP_WRITE);
// HUP is also treating as writable
assertEquals(1, sel3.select(100));
assertEquals(false, mkey3.isConnectable());
// even the channel is not connected, the selector could be writable
assertEquals(false, socketChannel2.isConnected());
assertEquals(true, mkey3.isWritable());
Selector sel4 = Selector.open();
SelectionKey mkey4 = socketChannel2.register(sel4, SelectionKey.OP_CONNECT);
assertEquals(1, sel4.select(100));
assertEquals(false, mkey4.isWritable());
assertEquals(true, mkey4.isConnectable());
Selector sel5 = Selector.open();
SelectionKey mkey5 = socketChannel2.register(sel5, SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE);
assertEquals(1, sel5.select(100));
assertEquals(true, mkey5.isWritable());
assertEquals(true, mkey5.isConnectable());
}
use of java.nio.channels.Selector in project robovm by robovm.
the class AbstractSelectableChannelTest method test_keyfor_LSelector.
/**
* @tests AbstractSelectableChannel#keyFor(Selector)
*/
public void test_keyfor_LSelector() throws Exception {
SocketChannel sc = SocketChannel.open();
Object argObj = new Object();
sc.configureBlocking(false);
Selector acceptSelector = SelectorProvider.provider().openSelector();
Selector acceptSelectorOther = SelectorProvider.provider().openSelector();
SelectionKey acceptKey = sc.register(acceptSelector, SelectionKey.OP_READ, argObj);
assertEquals(sc.keyFor(acceptSelector), acceptKey);
SelectionKey acceptKeyObjNull = sc.register(acceptSelector, SelectionKey.OP_READ, null);
assertSame(sc.keyFor(acceptSelector), acceptKeyObjNull);
assertSame(acceptKeyObjNull, acceptKey);
SelectionKey acceptKeyOther = sc.register(acceptSelectorOther, SelectionKey.OP_READ, null);
assertSame(sc.keyFor(acceptSelectorOther), acceptKeyOther);
}
use of java.nio.channels.Selector in project robovm by robovm.
the class AbstractSelectableChannelTest method test_register_LSelectorILObject.
/**
* @tests AbstractSelectableChannel#register(Selector, int, Object)
*/
public void test_register_LSelectorILObject() throws IOException {
assertFalse(testChannel.isRegistered());
Selector acceptSelector1 = SelectorProvider.provider().openSelector();
Selector acceptSelector2 = new MockAbstractSelector(SelectorProvider.provider());
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
SelectionKey acceptKey = sc.register(acceptSelector1, SelectionKey.OP_READ, null);
assertNotNull(acceptKey);
assertTrue(acceptKey.isValid());
assertSame(sc, acceptKey.channel());
//test that sc.register invokes Selector.register()
acceptKey = sc.register(acceptSelector2, SelectionKey.OP_READ, null);
assertNull(acceptKey);
// Regression test to ensure acceptance of a selector with empty
// interest set.
SocketChannel channel = SocketChannel.open();
channel.configureBlocking(false);
Selector selector = Selector.open();
channel.register(selector, 0);
selector.close();
channel.close();
}
use of java.nio.channels.Selector in project robovm by robovm.
the class AbstractSelectorTest method test_register_LSelectorI.
/**
* @tests AbstractSelector#register(Selector,int)
*/
public void test_register_LSelectorI() throws Exception {
Selector acceptSelector = SelectorProvider.provider().openSelector();
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.configureBlocking(false);
assertFalse(ssc.isRegistered());
SelectionKey acceptKey = ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
assertTrue(ssc.isRegistered());
assertNotNull(acceptKey);
assertTrue(acceptSelector.keys().contains(acceptKey));
}
Aggregations