@Override public void doRegisterKey(SelectionKey key, int ops, long currentTime) { final Object attachment = key.attachment(); if (attachment != null && attachment.equals(SelectionKeyAttachment.DEREGISTERED)) { return; } if (!key.isValid()) { selectorHandler.getSelectionKeyHandler().cancel(key); } else { key.interestOps(key.interestOps() | ops); addExpirationStamp(key, currentTime); } }
protected void afterCall() { SelectionKey currentKey = context.getSelectionKey(); SelectionKeyHandler selectionKeyHandler = context. getSelectorHandler().getSelectionKeyHandler(); selectionKeyHandler.postProcess(currentKey); }
protected void beforeCall() { SelectionKey currentKey = context.getSelectionKey(); SelectionKeyHandler selectionKeyHandler = context. getSelectorHandler().getSelectionKeyHandler(); selectionKeyHandler.process(currentKey); }
/** * Cancel a SelectionKey * @param key <tt>SelectionKey</tt> to cancel * @deprecated */ public void cancelKey(SelectionKey key){ if (stateHolder.getState() == State.STOPPED) { return; } SelectorHandler selectorHandler = getSelectorHandler(key.selector()); if (selectorHandler != null) { selectorHandler.getSelectionKeyHandler().cancel(key); } else { throw new IllegalStateException("SelectionKey is not associated " + "with known SelectorHandler"); } }
/** * Cancel a {@link #suspend}ed {@link Context}. Invoking this method will * automatically clean the state of this Context and mark it as a candidate * for being re-used by another Thread and connection. * * <strong>Important. When cancelled, all operations done on this * object are not thread-safe and there is probability that another * thread is already using this object. Never use this object once cancelled.</strong> * * * When invoked this method will automatically close the underlying * connection (represented by its {@link SelectionKey}. * * If the Context hasn't been suspended, calling that method has no effet. */ public void cancel(){ if (!isSuspended) return; isSuspended = false; selectorHandler.getSelectionKeyHandler().cancel(key); getController().returnContext(this); } /**
/** * Interrupt a suspended SelectionKey that have timed out. */ protected void interrupted(SelectionKey key) { key.cancel(); KeyHandler kh = (KeyHandler) key.attachment(); kh.getSuspendableHandler().getSelectorHandler() .getSelectionKeyHandler().cancel(kh.getKey()); if (logger.isLoggable(Level.FINE) && kh != null) { logger.log(Level.FINE, "Interrupting: " + kh.getKey()); } if (kh != null) { kh.getSuspendableHandler().getSuspendableHandler(). interupted(kh.getSuspendableHandler().getAttachment()); kh.getSuspendableHandler().getSuspendableFilter() .suspendedKeys.remove(kh.getKey()); } } }.start();
if (selectorHandler.getSelectionKeyHandler() == null){ if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "Set DefaultSelectionKeyHandler to SelectorHandler: " + selectorHandler); selectorHandler.getSelectionKeyHandler().cancel(key); logger.log(Level.WARNING, "Channel was unexpectedly closed"); if (key != null){ selectorHandler.getSelectionKeyHandler().cancel(key); logger.log(Level.SEVERE,"doSelect exception",t); if (key != null){ selectorHandler.getSelectionKeyHandler().cancel(key);
SelectionKey key = ct.getContext().getSelectionKey(); ct.getContext().getSelectorHandler().getSelectionKeyHandler().cancel(key); ct.recycle();
/** * Cancel the connection by internalling cancelling the associated * {@link ReadableChannel} and it associated {@link SelectionKey} * @param key */ protected void cancel(SelectionKey key){ log("Cancelling: " + key); KeyHandler kh = suspendedKeys.remove(key); if (kh == null){ return; } if (kh.getSuspendableHandler() == null){ return; } kh.getSuspendableHandler().getSuspendableHandler() .interupted(kh.getSuspendableHandler().getAttachment()); kh.getSuspendableHandler().getSelectorHandler() .getSelectionKeyHandler().cancel(key); kh.setThreadAttachment(null); }
/** * If no bytes were available, close the connection by cancelling the * SelectionKey. If bytes were available, register the SelectionKey * for new bytes. * * @return <tt>true</tt> if the previous ProtocolFilter postExecute method * needs to be invoked. */ public boolean postExecute(Context ctx) throws IOException { if (ctx.getKeyRegistrationState() == Context.KeyRegistrationState.CANCEL){ ctx.getSelectorHandler().getSelectionKeyHandler(). cancel(ctx.getSelectionKey()); } else if (ctx.getKeyRegistrationState() == Context.KeyRegistrationState.REGISTER){ saveSecuredBufferRemainders(ctx.getSelectionKey()); ctx.getSelectorHandler().register(ctx.getSelectionKey(), SelectionKey.OP_READ); ctx.setKeyRegistrationState(Context.KeyRegistrationState.NONE); } return true; }
} else { if (state == Context.KeyRegistrationState.CANCEL){ selectorHandler.getSelectionKeyHandler().cancel(key); } else if (state == Context.KeyRegistrationState.REGISTER){ selectorHandler.register(key, SelectionKey.OP_READ);
((BaseSelectionKeyHandler) task.getSelectorHandler().getSelectionKeyHandler()) .setConnectionCloseHandler(closeHandler);