本文整理了Java中java.nio.channels.Selector.open()
方法的一些代码示例,展示了Selector.open()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Selector.open()
方法的具体详情如下:
包路径:java.nio.channels.Selector
类名称:Selector
方法名:open
[英]Returns a selector returned by SelectorProvider#provider's SelectorProvider#openSelector method.
[中]返回SelectorProvider#提供程序的SelectorProvider#openSelector方法返回的选择器。
代码示例来源:origin: iluwatar/java-design-patterns
/**
* Creates a reactor which will use provided {@code dispatcher} to dispatch events. The application can provide
* various implementations of dispatcher which suits its needs.
*
* @param dispatcher
* a non-null dispatcher used to dispatch events on registered channels.
* @throws IOException
* if any I/O error occurs.
*/
public NioReactor(Dispatcher dispatcher) throws IOException {
this.dispatcher = dispatcher;
this.selector = Selector.open();
}
代码示例来源:origin: alibaba/nacos
public TcpSuperSenseProcessor() {
try {
selector = Selector.open();
TCP_CHECK_EXECUTOR.submit(this);
} catch (Exception e) {
throw new IllegalStateException("Error while initializing SuperSense(TM).");
}
}
代码示例来源:origin: apache/hbase
Reader() throws IOException {
this.pendingConnections = new LinkedBlockingQueue<>(readerPendingConnectionQueueLength);
this.readSelector = Selector.open();
}
代码示例来源:origin: alibaba/cobar
private R() throws IOException {
this.selector = Selector.open();
this.registerQueue = new LinkedBlockingQueue<NIOConnection>();
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
Reader(String name) throws IOException {
super(name);
this.pendingConnections =
new LinkedBlockingQueue<Connection>(readerPendingConnectionQueue);
this.readSelector = Selector.open();
}
代码示例来源:origin: alibaba/cobar
public NIOConnector(String name) throws IOException {
super.setName(name);
this.name = name;
this.selector = Selector.open();
this.connectQueue = new LinkedBlockingQueue<BackendConnection>();
}
代码示例来源:origin: apache/zookeeper
public AbstractSelectThread(String name) throws IOException {
super(name);
// Allows the JVM to shutdown even if this thread is still running.
setDaemon(true);
this.selector = Selector.open();
}
代码示例来源:origin: alibaba/cobar
public NIOAcceptor(String name, int port, FrontendConnectionFactory factory) throws IOException {
super.setName(name);
this.port = port;
this.selector = Selector.open();
this.serverChannel = ServerSocketChannel.open();
this.serverChannel.socket().bind(new InetSocketAddress(port));
this.serverChannel.configureBlocking(false);
this.serverChannel.register(selector, SelectionKey.OP_ACCEPT);
this.factory = factory;
}
代码示例来源:origin: apache/kafka
private enum CloseMode {
GRACEFUL(true), // process outstanding staged receives, notify disconnect
NOTIFY_ONLY(true), // discard any outstanding receives, notify disconnect
DISCARD_NO_NOTIFY(false); // discard any outstanding receives, no disconnect notification
boolean notifyDisconnect;
CloseMode(boolean notifyDisconnect) {
this.notifyDisconnect = notifyDisconnect;
}
}
代码示例来源:origin: voldemort/voldemort
public AbstractSelectorManager(long maxHeartBeatTimeMs) {
try {
this.selector = Selector.open();
} catch(IOException e) {
throw new VoldemortException(e);
}
this.isClosed = new AtomicBoolean(false);
this.maxHeartBeatTimeMs = maxHeartBeatTimeMs;
}
代码示例来源:origin: rapidoid/rapidoid
public AbstractEventLoop(String name) {
super(name);
Selector sel;
try {
sel = Selector.open();
} catch (IOException e) {
Log.error("Cannot open selector!", e);
throw new RuntimeException(e);
}
this.selector = sel;
}
代码示例来源:origin: apache/nifi
public ChannelListener(final int threadPoolSize, final StreamConsumerFactory consumerFactory, final BufferPool bufferPool, int timeout,
TimeUnit unit, final boolean readSingleDatagram) throws IOException {
this.executor = Executors.newScheduledThreadPool(threadPoolSize + 1); // need to allow for long running ChannelDispatcher thread
this.serverSocketSelector = Selector.open();
this.socketChannelSelector = Selector.open();
this.bufferPool = bufferPool;
this.initialBufferPoolSize = bufferPool.size();
channelDispatcher = new ChannelDispatcher(serverSocketSelector, socketChannelSelector, executor, consumerFactory, bufferPool,
timeout, unit, readSingleDatagram);
executor.schedule(channelDispatcher, 50, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: EsotericSoftware/kryonet
public Client (int writeBufferSize, int objectBufferSize, Serialization serialization) {
super();
endPoint = this;
this.serialization = serialization;
this.discoveryHandler = ClientDiscoveryHandler.DEFAULT;
initialize(serialization, writeBufferSize, objectBufferSize);
try {
selector = Selector.open();
} catch (IOException ex) {
throw new RuntimeException("Error opening selector.", ex);
}
}
代码示例来源:origin: apache/incubator-gobblin
private Tunnel open() throws IOException {
try {
this.server = ServerSocketChannel.open().bind(null);
this.server.configureBlocking(false);
Selector selector = Selector.open();
startTunnelThread(selector);
return this;
} catch (IOException ioe) {
LOG.error("Failed to open the tunnel", ioe);
throw ioe;
}
}
代码示例来源:origin: apache/activemq
public SelectorWorker(SelectorManager manager) throws IOException {
this.manager = manager;
selector = Selector.open();
maxChannelsPerWorker = manager.getMaxChannelsPerWorker();
manager.getSelectorExecutor().execute(this);
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCloseQuietly_Selector() {
Selector selector = null;
try {
selector = Selector.open();
} catch (final IOException ignore) {
} finally {
IOUtils.closeQuietly(selector);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCloseQuietly_SelectorTwice() {
Selector selector = null;
try {
selector = Selector.open();
} catch (final IOException ignore) {
} finally {
IOUtils.closeQuietly(selector);
IOUtils.closeQuietly(selector);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
Responder() throws IOException {
this.setName("IPC Server Responder");
this.setDaemon(true);
writeSelector = Selector.open(); // create a selector
pending = 0;
}
代码示例来源:origin: apache/hbase
SimpleRpcServerResponder(SimpleRpcServer simpleRpcServer) throws IOException {
this.simpleRpcServer = simpleRpcServer;
this.setName("RpcServer.responder");
this.setDaemon(true);
this.setUncaughtExceptionHandler(Threads.LOGGING_EXCEPTION_HANDLER);
writeSelector = Selector.open(); // create a selector
}
代码示例来源:origin: apache/kafka
public void run() {
try {
java.nio.channels.Selector acceptSelector = java.nio.channels.Selector.open();
serverSocketChannel.register(acceptSelector, SelectionKey.OP_ACCEPT);
while (serverSocketChannel.isOpen()) {
if (acceptSelector.select(1000) > 0) {
Iterator<SelectionKey> it = acceptSelector.selectedKeys().iterator();
while (it.hasNext()) {
SelectionKey key = it.next();
if (key.isAcceptable()) {
SocketChannel socketChannel = ((ServerSocketChannel) key.channel()).accept();
socketChannel.configureBlocking(false);
newChannels.add(socketChannel);
selector.wakeup();
}
it.remove();
}
}
}
} catch (IOException e) {
// ignore
}
}
}
内容来源于网络,如有侵权,请联系作者删除!