/** * Cancel the current {@link SelectionKey} */ public void cancelKey(SelectionKey key){ selectorHandler.getSelectionKeyHandler().cancel(key); }
/** * Cancel the current {@link SelectionKey} */ public void cancelKey(SelectionKey key){ selectorHandler.getSelectionKeyHandler().cancel(key); }
@Override public void removeRemotePeer(String instanceName) { for (Map.Entry<SelectionKey, String> entry : selectionKeyMap.entrySet()) { if (entry.getValue().equals(instanceName)) { if (getLogger().isLoggable(Level.FINE)) { getLogger().log(Level.FINE, "remove selection key for instance name: " + entry.getValue() + " selectionKey:" + entry.getKey()); } tcpSelectorHandler.getSelectionKeyHandler().cancel(entry.getKey()); selectionKeyMap.remove(entry.getKey()); } } }
@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); } }
/** * 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); } /**
/** * Close the underlying connection. */ public void close() throws IOException{ if (socketChannel != null){ if (selectorHandler != null){ SelectionKey key = socketChannel.keyFor(selectorHandler.getSelector()); if (key == null) return; selectorHandler.getSelectionKeyHandler().cancel(key); } else { socketChannel.close(); } } if (controller != null && isStandalone){ controller.stop(); controller = null; } isStandalone = false; isConnected = false; connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; }
/** * 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();
/** * Close the underlying connection. */ public void close() throws IOException{ if (datagramChannel != null){ if (selectorHandler != null){ SelectionKey key = datagramChannel.keyFor(selectorHandler.getSelector()); if (key == null) return; selectorHandler.getSelectionKeyHandler().cancel(key); } else { datagramChannel.close(); } } if (controller != null && isStandalone){ controller.stop(); controller = null; } isStandalone = false; isConnected = false; }
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);