@Override public boolean execute(final Context context) throws IOException { if (context.getCurrentOpType() == Context.OpType.OP_WRITE) { return false; } return super.execute(context); }
@Override public boolean postExecute(final Context context) throws IOException { if (context.getCurrentOpType() == Context.OpType.OP_WRITE) { return false; } final GrizzlyMessageProtocolParser parser = (GrizzlyMessageProtocolParser) context.getAttribute(ProtocolParser.PARSER); if (parser == null) { return true; } if (parser.isError()) { parser.releaseBuffer(); context.setKeyRegistrationState(Context.KeyRegistrationState.CANCEL); return false; } return super.postExecute(context); }
protected Object doCall() throws Exception { IOEvent ioEvent = context.getIOEvent(); OpType currentOpType = context.getCurrentOpType(); try { if (currentOpType == OpType.OP_READ) { callBackHandler.onRead(ioEvent); } else if (currentOpType == OpType.OP_WRITE) { callBackHandler.onWrite(ioEvent); } else if (currentOpType == OpType.OP_CONNECT) { callBackHandler.onConnect(ioEvent); } } finally { if (ioEvent != null) { // Prevent the CallbackHandler to re-use the context. // TODO: This is still dangerous as the Context might have been // cached by the CallbackHandler. ioEvent.attach(null); ioEvent = null; } } return null; }
/** * Invoke a CallbackHandler via a Context instance. * @param context {@link Context} * @throws java.io.IOException */ protected void invokeCallbackHandler(CallbackHandler callbackHandler, Context context) throws IOException { IOEvent<Context>ioEvent = new IOEvent.DefaultIOEvent<Context>(context); context.setIOEvent(ioEvent); // Added because of incompatibility with Grizzly 1.6.0 context.setSelectorHandler(this); try { CallbackHandlerContextTask task = CallbackHandlerContextTask.poll(); task.setCallBackHandler(callbackHandler); boolean isRunInSeparateThread = true; if (callbackHandler instanceof CallbackHandlerDescriptor) { isRunInSeparateThread = ((CallbackHandlerDescriptor) callbackHandler). isRunInSeparateThread(context.getCurrentOpType()); } context.execute(task, isRunInSeparateThread); } catch (PipelineFullException ex) { throw new IOException(ex.getMessage()); } }
if (ctx.getCurrentOpType() == Context.OpType.OP_WRITE){ if (Controller.logger().isLoggable(Level.FINE)){ Controller.logger().fine("ReadFilter cannont handle OP_WRITE");