/** * 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(); }
public TcpSuperSenseProcessor() { try { selector = Selector.open(); TCP_CHECK_EXECUTOR.submit(this); } catch (Exception e) { throw new IllegalStateException("Error while initializing SuperSense(TM)."); } }
Reader() throws IOException { this.pendingConnections = new LinkedBlockingQueue<>(readerPendingConnectionQueueLength); this.readSelector = Selector.open(); }
private R() throws IOException { this.selector = Selector.open(); this.registerQueue = new LinkedBlockingQueue<NIOConnection>(); }
Reader(String name) throws IOException { super(name); this.pendingConnections = new LinkedBlockingQueue<Connection>(readerPendingConnectionQueue); this.readSelector = Selector.open(); }
public NIOConnector(String name) throws IOException { super.setName(name); this.name = name; this.selector = Selector.open(); this.connectQueue = new LinkedBlockingQueue<BackendConnection>(); }
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(); }
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; }
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; } }
public AbstractSelectorManager(long maxHeartBeatTimeMs) { try { this.selector = Selector.open(); } catch(IOException e) { throw new VoldemortException(e); } this.isClosed = new AtomicBoolean(false); this.maxHeartBeatTimeMs = maxHeartBeatTimeMs; }
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; }
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); }
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); } }
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; } }
public SelectorWorker(SelectorManager manager) throws IOException { this.manager = manager; selector = Selector.open(); maxChannelsPerWorker = manager.getMaxChannelsPerWorker(); manager.getSelectorExecutor().execute(this); }
@Test public void testCloseQuietly_Selector() { Selector selector = null; try { selector = Selector.open(); } catch (final IOException ignore) { } finally { IOUtils.closeQuietly(selector); } }
@Test public void testCloseQuietly_SelectorTwice() { Selector selector = null; try { selector = Selector.open(); } catch (final IOException ignore) { } finally { IOUtils.closeQuietly(selector); IOUtils.closeQuietly(selector); } }
Responder() throws IOException { this.setName("IPC Server Responder"); this.setDaemon(true); writeSelector = Selector.open(); // create a selector pending = 0; }
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 }
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 } } }