use of java.nio.channels.spi.SelectorProvider in project robovm by robovm.
the class AbstractSelectableChannelTest method test_provider.
/**
* @tests AbstractSelectableChannel#provider()
*/
public void test_provider() {
SelectorProvider provider = testChannel.provider();
assertSame(SelectorProvider.provider(), provider);
testChannel = new MockSelectableChannel(null);
provider = testChannel.provider();
assertNull(provider);
}
use of java.nio.channels.spi.SelectorProvider in project baseio by generallycloud.
the class SocketSelectorEventLoop method openSelector.
@SuppressWarnings("rawtypes")
private SocketSelector openSelector(SelectableChannel channel) throws IOException {
SelectorProvider provider = SelectorProvider.provider();
Object res = AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
return Class.forName("sun.nio.ch.SelectorImpl");
} catch (Throwable cause) {
return cause;
}
}
});
final Selector selector = provider.openSelector();
if (res instanceof Throwable) {
return new NioSocketSelector(this, channel, selector);
}
final Class selectorImplClass = (Class) res;
final SelectionKeySet keySet = new SelectionKeySet();
res = AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys");
Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys");
Throwable cause = ClassUtil.trySetAccessible(selectedKeysField);
if (cause != null) {
return cause;
}
cause = ClassUtil.trySetAccessible(publicSelectedKeysField);
if (cause != null) {
return cause;
}
selectedKeysField.set(selector, keySet);
publicSelectedKeysField.set(selector, keySet);
return null;
} catch (Exception e) {
return e;
}
}
});
if (res instanceof Throwable) {
return new NioSocketSelector(this, channel, selector);
}
selectionKeySet = keySet;
return new SelectionKeyNioSocketSelector(this, channel, selector, keySet);
}
use of java.nio.channels.spi.SelectorProvider in project webpieces by deanhiller.
the class TestXEvaluateNIOBehavior method testNormalNio.
/**
* This test is interesting. If a Socket is registered with a Selector, and
* you close the socket, the socket cannot be closed until the select statement.
*
* NOTE: Appears to be fixed in 1.5.0_06 on windows, so we only run this on
* linux now!!!!!!!!!
*
* @throws Exception
*/
public void testNormalNio() throws Exception {
SocketChannel channel1 = SocketChannel.open();
channel1.configureBlocking(false);
channel1.socket().setReuseAddress(true);
InetAddress loopBack = InetAddress.getByName("127.0.0.1");
InetSocketAddress addr1 = new InetSocketAddress(loopBack, 0);
channel1.socket().bind(addr1);
channel1.connect(svrAddr);
channel1.finishConnect();
mockServer.expect(MockNIOServer.CONNECTED);
SelectorProvider prov = SelectorProvider.provider();
AbstractSelector sel = prov.openSelector();
log.info("about to register client");
channel1.register(sel, SelectionKey.OP_READ);
log.info("registered channel");
log.info("about to close------------------");
channel1.close();
log.info("channel is now closed-----------");
mockServer.expect(MockNIOServer.FAR_END_CLOSED);
}
use of java.nio.channels.spi.SelectorProvider in project netty by netty.
the class NioEventLoopGroup method newChild.
@Override
protected EventLoop newChild(Executor executor, Object... args) throws Exception {
SelectorProvider selectorProvider = (SelectorProvider) args[0];
SelectStrategyFactory selectStrategyFactory = (SelectStrategyFactory) args[1];
RejectedExecutionHandler rejectedExecutionHandler = (RejectedExecutionHandler) args[2];
EventLoopTaskQueueFactory taskQueueFactory = null;
EventLoopTaskQueueFactory tailTaskQueueFactory = null;
int argsLength = args.length;
if (argsLength > 3) {
taskQueueFactory = (EventLoopTaskQueueFactory) args[3];
}
if (argsLength > 4) {
tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[4];
}
return new NioEventLoop(this, executor, selectorProvider, selectStrategyFactory.newSelectStrategy(), rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
}
use of java.nio.channels.spi.SelectorProvider in project j2objc by google.
the class AbstractSelectableChannelTest method test_provider.
/**
* @tests AbstractSelectableChannel#provider()
*/
public void test_provider() {
SelectorProvider provider = testChannel.provider();
assertSame(SelectorProvider.provider(), provider);
testChannel = new MockSelectableChannel(null);
provider = testChannel.provider();
assertNull(provider);
}
Aggregations