public void detachSelectorRunner() throws IOException { final SelectorRunner selectorRunnerLocal = this.selectorRunner; this.selectionKey = null; this.selectorRunner = null; if (selectorRunnerLocal != null) { transport.getSelectorHandler().deregisterChannel(selectorRunnerLocal, channel); } }
@Override public void registerChannel(final SelectableChannel channel, final int interestOps, final Object attachment) throws IOException { transport.getSelectorHandler().registerChannel(it.next(), channel, interestOps, attachment); }
@Override public void registerChannelAsync( final SelectableChannel channel, final int interestOps, final Object attachment, final CompletionHandler<RegisterChannelResult> completionHandler) { transport.getSelectorHandler().registerChannelAsync( it.next(), channel, interestOps, attachment, completionHandler); }
if (!selectorHandler.preSelect(this)) { return false; readyKeySet = selectorHandler.select(this); selectorWakeupFlag.set(false); selectorHandler.postSelect(this); } catch (ClosedSelectorException e) { if (isRunning()) { if (selectorHandler.onSelectorClosed(this)) { return true;
@Override public void simulateIOEvent(final IOEvent ioEvent) throws IOException { if (!isOpen()) { // don't simulate IOEvent for closed connection return; } final SelectorHandler selectorHandler = transport.getSelectorHandler(); switch (ioEvent) { case WRITE: selectorHandler.enque(selectorRunner, writeSimulatorRunnable, null); break; case READ: selectorHandler.enque(selectorRunner, readSimulatorRunnable, null); break; default: throw new IllegalArgumentException("We support only READ and WRITE events. Got " + ioEvent); } }
@Override public final void disableIOEvent(final IOEvent ioEvent) throws IOException { final int interest = ioEvent.getSelectionKeyInterest(); if (interest == 0) { return; } notifyIOEventDisabled(this, ioEvent); final SelectorHandler selectorHandler = transport.getSelectorHandler(); selectorHandler.deregisterKeyInterest(selectorRunner, selectionKey, interest); }
@Override public final void enableIOEvent(final IOEvent ioEvent) throws IOException { final boolean isOpRead = (ioEvent == IOEvent.READ); final int interest = ioEvent.getSelectionKeyInterest(); if (interest == 0 || // don't register OP_READ for a connection scheduled to be closed (isOpRead && isCloseScheduled.get()) || // don't register any OP for a closed connection closeReason != null) { return; } notifyIOEventEnabled(this, ioEvent); // if OP_READ was enabled at least once - isInitialReadRequired should be false isInitialReadRequired = isInitialReadRequired && !isOpRead; final SelectorHandler selectorHandler = transport.getSelectorHandler(); selectorHandler.registerKeyInterest(selectorRunner, selectionKey, interest); }
notifyProbesClose(this); transport.getSelectorHandler().execute( selectorRunner, new SelectorHandler.Task() {
if (!selectorHandler.preSelect(this)) { return false; readyKeySet = selectorHandler.select(this); selectorWakeupFlag.set(false); selectorHandler.postSelect(this); } catch (ClosedSelectorException e) { if (isRunning()) { if (selectorHandler.onSelectorClosed(this)) { return true;
@Override public void simulateIOEvent(final IOEvent ioEvent) throws IOException { if (!isOpen()) { // don't simulate IOEvent for closed connection return; } final SelectorHandler selectorHandler = transport.getSelectorHandler(); switch (ioEvent) { case WRITE: selectorHandler.enque(selectorRunner, writeSimulatorRunnable, null); break; case READ: selectorHandler.enque(selectorRunner, readSimulatorRunnable, null); break; default: throw new IllegalArgumentException("We support only READ and WRITE events. Got " + ioEvent); } }
@Override public final void disableIOEvent(final IOEvent ioEvent) throws IOException { final int interest = ioEvent.getSelectionKeyInterest(); if (interest == 0) { return; } notifyIOEventDisabled(this, ioEvent); final SelectorHandler selectorHandler = transport.getSelectorHandler(); selectorHandler.deregisterKeyInterest(selectorRunner, selectionKey, interest); }
@Override public final void enableIOEvent(final IOEvent ioEvent) throws IOException { final boolean isOpRead = (ioEvent == IOEvent.READ); final int interest = ioEvent.getSelectionKeyInterest(); if (interest == 0 || // don't register OP_READ for a connection scheduled to be closed (isOpRead && isCloseScheduled.get()) || // don't register any OP for a closed connection closeReason != null) { return; } notifyIOEventEnabled(this, ioEvent); // if OP_READ was enabled at least once - isInitialReadRequired should be false isInitialReadRequired = isInitialReadRequired && !isOpRead; final SelectorHandler selectorHandler = transport.getSelectorHandler(); selectorHandler.registerKeyInterest(selectorRunner, selectionKey, interest); }
notifyProbesClose(this); transport.getSelectorHandler().execute( selectorRunner, new SelectorHandler.Task() {
if (!selectorHandler.preSelect(this)) { return false; readyKeySet = selectorHandler.select(this); selectorWakeupFlag.set(false); selectorHandler.postSelect(this); } catch (ClosedSelectorException e) { if (isRunning()) { if (selectorHandler.onSelectorClosed(this)) { return true;
@Override public void registerChannel(final SelectableChannel channel, final int interestOps, final Object attachment) throws IOException { transport.getSelectorHandler().registerChannel(it.next(), channel, interestOps, attachment); }
public void detachSelectorRunner() throws IOException { final SelectorRunner selectorRunnerLocal = this.selectorRunner; this.selectionKey = null; this.selectorRunner = null; if (selectorRunnerLocal != null) { transport.getSelectorHandler().deregisterChannel(selectorRunnerLocal, channel); } }
@Override public void registerServiceChannelAsync( final SelectableChannel channel, final int interestOps, final Object attachment, final CompletionHandler<RegisterChannelResult> completionHandler) { transport.getSelectorHandler().registerChannelAsync( it.nextService(), channel, interestOps, attachment, completionHandler); }
@Override public void executeInEventThread(final IOEvent event, final Runnable runnable) { final Executor threadPool = transport.getIOStrategy() .getThreadPoolFor(this, event); if (threadPool == null) { transport.getSelectorHandler().enque(selectorRunner, new SelectorHandler.Task() { @Override public boolean run() throws Exception { runnable.run(); return true; } }, null); } else { threadPool.execute(runnable); } }
@Override public final void disableIOEvent(final IOEvent ioEvent) throws IOException { final int interest = ioEvent.getSelectionKeyInterest(); if (interest == 0) { return; } notifyIOEventDisabled(this, ioEvent); final SelectorHandler selectorHandler = transport.getSelectorHandler(); selectorHandler.deregisterKeyInterest(selectorRunner, selectionKey, interest); }
@Override public final void enableIOEvent(final IOEvent ioEvent) throws IOException { final boolean isOpRead = (ioEvent == IOEvent.READ); final int interest = ioEvent.getSelectionKeyInterest(); if (interest == 0 || // don't register OP_READ for a connection scheduled to be closed (isOpRead && isCloseScheduled.get()) || // don't register any OP for a closed connection closeReason != null) { return; } notifyIOEventEnabled(this, ioEvent); // if OP_READ was enabled at least once - isInitialReadRequired should be false isInitialReadRequired = isInitialReadRequired && !isOpRead; final SelectorHandler selectorHandler = transport.getSelectorHandler(); selectorHandler.registerKeyInterest(selectorRunner, selectionKey, interest); }