ctx.getSelectorHandler(); final SelectionKey key = ctx.getSelectionKey(); final Context.KeyRegistrationState state = ctx.getKeyRegistrationState(); final Protocol protocol = ctx.getProtocol(); ProtocolChain protocolChain = ctx.getProtocolChain(); && state == Context.KeyRegistrationState.REGISTER && Boolean.FALSE != (Boolean)ctx.getAttribute(ProtocolFilter.SUCCESSFUL_READ)){ ctx.setAttribute(ProtocolFilter.SUCCESSFUL_READ, Boolean.TRUE); } else { ctx.removeAttribute(Context.THROWABLE); ctx.removeAttribute(UDP_SOCKETADDRESS);
/** * 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; }
/** * Polls {@link Context} from pool and initializes it. * * @param serverContext {@link Controller} context * @param key {@link SelectionKey} * @return {@link Context} */ protected Context pollContext(final Context serverContext, final SelectionKey key, final Context.OpType opType) { ProtocolChain protocolChain = instanceHandler != null ? instanceHandler.poll() : serverContext.getController().getProtocolChainInstanceHandler().poll(); final Context context = serverContext.getController().pollContext(key, opType); context.setSelectionKey(key); context.setSelectorHandler(this); context.setAsyncQueueReader(asyncQueueReader); context.setAsyncQueueWriter(asyncQueueWriter); context.setProtocolChain(protocolChain); return context; }
/** * Suspend the execution of this {@link Context}. Suspending the execution * allow application to store the current instance, and re-use it later * by not only the Thread used when called suspend, but also from any other Thread. * A suspended Context will not be re-used by any other transaction and Thread. * A suspended Context will keep its current state intact, meaning its * SelectionKey, attributes, SelectorHandler, etc, will not change. Internally, * The Context will not be recyled and will not be re-used by any Thread. * * When invoked this method will automatically set the * {@link Context#setKeyRegistrationState} to {@link KeyRegistrationState} * to KeyRegistrationState.NONE. * * Invoking this method many times as not effect once suspended. */ public void suspend(){ if (isSuspended) return; isSuspended = true; incrementRefCount(); setKeyRegistrationState(keyRegistrationState.NONE); }
public boolean postExecute(Context ctx) throws IOException { if (isInitilizedOk) { final ProtocolChain chain = ctx.getProtocolChain(); chain.removeFilter(this); ctx.setAttribute(ProtocolChain.PROTOCOL_CHAIN_POST_INSTRUCTION, ProtocolChainInstruction.REINVOKE); } return true; } }
public boolean execute( Context ctx ) throws IOException { Object obj = ctx.removeAttribute( ProtocolParser.MESSAGE ); if( !( obj instanceof Message ) ) throw new IOException( "received message is not valid: " + obj ); final Message incomingMessage = (Message)obj; final SelectionKey selectionKey = ctx.getSelectionKey(); Map<String, Object> piggyback = null; if( selectionKey != null ) { piggyback = new HashMap<String, Object>(); piggyback.put( GrizzlyNetworkManager1_9.MESSAGE_SELECTION_KEY_TAG, selectionKey ); } networkManager.receiveMessage( incomingMessage, piggyback ); return false; }
if (ctx.getCurrentOpType() == Context.OpType.OP_WRITE){ if (Controller.logger().isLoggable(Level.FINE)){ Controller.logger().fine("ReadFilter cannont handle OP_WRITE"); SocketAddress socketAddress = null; Exception exception = null; SelectionKey key = ctx.getSelectionKey(); Protocol protocol = ctx.getProtocol(); try { int loop = 0; if (ctx.getKeyRegistrationState() != Context.KeyRegistrationState.NONE){ ctx.setAttribute(ProtocolFilter.SUCCESSFUL_READ, Boolean.FALSE); invokeNextFilter = false; DatagramChannel datagramChannel = (DatagramChannel)key.channel(); socketAddress = datagramChannel.receive(byteBuffer); ctx.getSelectorHandler().register(key, SelectionKey.OP_READ); } finally { if (exception != null){ ctx.setAttribute(Context.THROWABLE,exception); if (protocol != UDP){ ctx.setKeyRegistrationState( Context.KeyRegistrationState.CANCEL);
public SelectionKey getSelectionKey() { return context.getSelectionKey(); }
public boolean execute(Context ctx) throws IOException { if (Boolean.TRUE.equals(ctx.getAttribute(ReadFilter.DELAYED_CLOSE_NOTIFICATION))) { ctx.setKeyRegistrationState(Context.KeyRegistrationState.CANCEL); return false; ((HttpSelectorHandler) ctx.getSelectorHandler()).getSelectorThread(); SelectionKey key = ctx.getSelectionKey(); configureInputBuffer(inputStream, ctx, ctx.getSelectionKey().attach(k); ctx.setKeyRegistrationState( Context.KeyRegistrationState.NONE); return true; if (ctx.getProtocol() == Controller.Protocol.TCP){ ctx.getSelectionKey().attach(null); } else { workerThread.getAttachment().setTimeout(SelectionKeyAttachment.UNLIMITED_TIMEOUT); final Object attachement = ctx.getSelectionKey().attachment(); if (attachement instanceof SelectionKeyAttachment) { final SelectionKeyAttachment selectionKeyAttachment = ctx.setKeyRegistrationState( Context.KeyRegistrationState.REGISTER); } else { if (selectorThread.isAsyncHttpWriteEnabled()) {
protected void afterCall() { SelectionKey currentKey = context.getSelectionKey(); SelectionKeyHandler selectionKeyHandler = context. getSelectorHandler().getSelectionKeyHandler(); selectionKeyHandler.postProcess(currentKey); }
DatagramChannel datagramChannel = null; Exception exception = null; SelectionKey key = ctx.getSelectionKey(); key.attach(null); } finally { if (exception != null){ ctx.setAttribute(Context.THROWABLE,exception); result = false; } else if (socketAddress == null){ ctx.setKeyRegistrationState( Context.KeyRegistrationState.REGISTER); result = false; } else { ctx.setAttribute(UDP_SOCKETADDRESS,socketAddress);
DatagramChannel datagramChannel = null; Exception exception = null; SelectionKey key = ctx.getSelectionKey(); key.attach(null); ((WorkerThread)Thread.currentThread()).getByteBuffer(); try { socketAddress = (SocketAddress)ctx.getAttribute(UDP_SOCKETADDRESS); } finally { if (exception != null){ ctx.setAttribute(Context.THROWABLE,exception); result = false; } else { ctx.setKeyRegistrationState( Context.KeyRegistrationState.REGISTER);
@Override public boolean postExecute(Context context) throws IOException { ProtocolParser parser = (ProtocolParser) context.getAttribute(ProtocolParser.PARSER); context.setAttribute(ProtocolChain.PROTOCOL_CHAIN_POST_INSTRUCTION, ProtocolChainInstruction.REINVOKE); return true; if (context.getKeyRegistrationState() != Context.KeyRegistrationState.CANCEL) { SelectionKey key = context.getSelectionKey(); if (parser.isExpectingMoreData()) { if (parser.releaseBuffer()) { context.getSelectorHandler().register(key, SelectionKey.OP_READ); return false;
public boolean execute(Context ctx) throws IOException{ final SelectorThread selectorThread = SelectorThread.getSelector(address, port); final SelectionKey key = ctx.getSelectionKey(); if (Boolean.TRUE.equals(ctx.getAttribute(ReadFilter.DELAYED_CLOSE_NOTIFICATION))) { if (selectorThread.isAsyncHttpWriteEnabled()) { ctx.setKeyRegistrationState(Context.KeyRegistrationState.NONE); flushAsyncWriteQueueAndClose(ctx.getSelectorHandler(), key); } else { ctx.setKeyRegistrationState(Context.KeyRegistrationState.CANCEL); ctx.setKeyRegistrationState(Context.KeyRegistrationState.NONE); } catch (Throwable ex) { logger.log(Level.INFO, "Processor exception", ex); ctx.setKeyRegistrationState(Context.KeyRegistrationState.CANCEL); return false;
((HttpWorkerThread)Thread.currentThread()); if (ctx.getProtocol() == Controller.Protocol.TCP){ ctx.getSelectionKey().attach(null); } else { workerThread.getAttachment().setTimeout(null); SelectionKey key = ctx.getSelectionKey(); configureByteBufferInputStream(inputStream, ctx, workerThread); SocketChannel socketChannel = ctx.setKeyRegistrationState( Context.KeyRegistrationState.REGISTER); } else { ctx.setKeyRegistrationState( Context.KeyRegistrationState.CANCEL); byteBuffer.clear(); if (selectorThread.isRcmSupported()){ ctx.removeAttribute(ResourceAllocationFilter.BYTEBUFFER_INPUTSTREAM); ctx.removeAttribute(ResourceAllocationFilter.BYTE_BUFFER); ctx.removeAttribute(ResourceAllocationFilter.INVOKE_NEXT);
Protocol protocol = ctx.getProtocol(); ctx.getAttribute(BYTEBUFFER_INPUTSTREAM); if (inputStream == null){ inputStream = new ByteBufferInputStream(); ctx.setAttribute(BYTEBUFFER_INPUTSTREAM,inputStream); pipeline = filterRequest(token, ctx.getPipeline()); pipelines.put(token,pipeline); ByteBuffer nBuf = (ByteBuffer)ctx.getAttribute(BYTE_BUFFER); if (nBuf != null){ ctx.setAttribute(BYTE_BUFFER,byteBuffer); ctx.setAttribute(INVOKE_NEXT,"true"); ctx.setKeyRegistrationState(Context.KeyRegistrationState.NONE); try{ Context copyContext = Cloner.clone(ctx); copyContext.execute(ProtocolChainContextTask.poll()); copyContext.setPipeline(pipeline); } catch (Throwable t){ ctx.setAttribute(Context.THROWABLE,t); ctx.setKeyRegistrationState( Context.KeyRegistrationState.CANCEL);
/** * Close the connection. */ public void closeConnection(Context ctx){ ctx.setKeyRegistrationState(Context.KeyRegistrationState.CANCEL); }
SelectionKey key = context.getSelectionKey(); GrizzlyServerCall serverCall = new GrizzlyServerCall(this.helper .getHelped(), byteBuffer, key, .setKeyRegistrationState(Context.KeyRegistrationState.REGISTER); } else { context .setKeyRegistrationState(Context.KeyRegistrationState.CANCEL);
SelectionKey key = ctx.getSelectionKey(); KeyHandler kh = suspendedKeys.get(key); sh.setSelectorHandler(ctx.getSelectorHandler()); attachment.setMode(Mode.STORE_ALL); kh.setThreadAttachment(workerThread.detach()); ctx.setKeyRegistrationState(KeyRegistrationState.NONE);
SelectionKey key = context.getSelectionKey(); SelectableChannel channel = key.channel(); (ByteBuffer) context.removeAttribute(TMP_DECODED_BUFFER); context.setAttribute(SSLReadFilter.SSL_PREREAD_DATA, Boolean.TRUE);