protected void beforeCall() { SelectionKey currentKey = context.getSelectionKey(); SelectionKeyHandler selectionKeyHandler = context. getSelectorHandler().getSelectionKeyHandler(); selectionKeyHandler.process(currentKey); }
protected void afterCall() { SelectionKey currentKey = context.getSelectionKey(); SelectionKeyHandler selectionKeyHandler = context. getSelectorHandler().getSelectionKeyHandler(); selectionKeyHandler.postProcess(currentKey); }
@Override public void onRead(IOEvent<Context> ioEvent) { // We don't expect any read, so if any data comes - we suppose it's "close" notification final Context context = ioEvent.attachment(); final SelectionKey selectionKey = context.getSelectionKey(); // close the channel context.getSelectorHandler().addPendingKeyCancel(selectionKey); }
public boolean execute(Context ctx) throws IOException { final ProtocolChain chain = ctx.getProtocolChain(); synchronized (ssl) { if (!isSslInitialized) { isSslInitialized = true; isInitilizedOk = sslConfigHolder.configureSSL(); if (!isInitilizedOk) { logger.log(Level.SEVERE, "Failed to configure SSL on protocol ''{0}'' on network-listener ''{1}''", new Object[]{protocolName, networkListenerName}); } } } if (isInitilizedOk) { doConfigureFilters(chain); } else { logger.log(Level.FINE, "Closing connection to misconfigured SSL protocol"); ctx.getSelectorHandler().addPendingKeyCancel(ctx.getSelectionKey()); } return false; }
@Override public void onConnect(IOEvent<Context> ioEvent) { SelectionKey key = ioEvent.attachment().getSelectionKey(); if (connectorHandler instanceof AbstractConnectorHandler) { ((AbstractConnectorHandler) connectorHandler).setUnderlyingChannel( key.channel()); } try { connectorHandler.finishConnect(key); ioEvent.attachment().getSelectorHandler().register(key, SelectionKey.OP_READ); } catch (IOException ex) { Controller.logger().severe(ex.getMessage()); } }
/** * Configure {@link ProcessorTask}. */ protected void configureProcessorTask(ProcessorTask processorTask, Context context, StreamAlgorithm streamAlgorithm) { SelectionKey key = context.getSelectionKey(); processorTask.setSelectorHandler(context.getSelectorHandler()); processorTask.setSelectionKey(key); processorTask.setSocket(((SocketChannel) key.channel()).socket()); if (processorTask.getStreamAlgorithm() == null){ processorTask.setStreamAlgorithm(streamAlgorithm); } }
/** * Configure {@link com.sun.grizzly.ssl.SSLProcessorTask}. */ protected void configureProcessorTask(ProcessorTask processorTask, Context context, StreamAlgorithm streamAlgorithm, InputStream inputStream) { SelectionKey key = context.getSelectionKey(); processorTask.setSelectionKey(key); processorTask.setSelectorHandler(context.getSelectorHandler()); processorTask.setSocket(((SocketChannel) key.channel()).socket()); processorTask.setTaskListener(this); processorTask.setInputStream(inputStream); processorTask.setStreamAlgorithm(streamAlgorithm); }
/** * 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; }
@Override public boolean onAcceptInterest(SelectionKey key, Context context) throws IOException { ReadController auxController = nextController(); SelectorHandler protocolSelectorHandler = context.getSelectorHandler(); SelectableChannel channel = protocolSelectorHandler.acceptWithoutRegistration(key); if (channel != null) { protocolSelectorHandler.configureChannel(channel); SelectorHandler relativeSelectorHandler = auxController.getSelectorHandlerClone(protocolSelectorHandler); if (relativeSelectorHandler == null) { // Clone was not found - take correspondent protocol SelectorHandler relativeSelectorHandler = auxController.getSelectorHandler(protocolSelectorHandler.protocol()); } auxController.addChannel(channel, relativeSelectorHandler); } return false; }
DatagramChannel datagramChannel = (DatagramChannel)key.channel(); socketAddress = datagramChannel.receive(byteBuffer); ctx.getSelectorHandler().register(key, SelectionKey.OP_READ);
sh.setSelectorHandler(ctx.getSelectorHandler());
SelectionKey key = ct.getContext().getSelectionKey(); ct.getContext().getSelectorHandler().getSelectionKeyHandler().cancel(key); ct.recycle();
if (selectorThread.isAsyncHttpWriteEnabled()) { ctx.setKeyRegistrationState(Context.KeyRegistrationState.NONE); flushAsyncWriteQueueAndClose(ctx.getSelectorHandler(), key); } else { ctx.setKeyRegistrationState(Context.KeyRegistrationState.CANCEL);
((HttpSelectorHandler) ctx.getSelectorHandler()).getSelectorThread(); ctx.setKeyRegistrationState( Context.KeyRegistrationState.NONE); flushAsyncWriteQueueAndClose(ctx.getSelectorHandler(), key); } else { ctx.setKeyRegistrationState(
ctx.getSelectorHandler(); final SelectionKey key = ctx.getSelectionKey(); final Context.KeyRegistrationState state = ctx.getKeyRegistrationState();
context.getSelectorHandler().register(key, SelectionKey.OP_READ); return false;