/** * Interface method implementation. Reads and processes commands sent to the service proxy. * Expects data in the command protocol defined in the class summary. Discards commands that do * not have a {@link TaskHandler} mapping. * * @see * org.jboss.netty.channel.SimpleChannelUpstreamHandler#handleUpstream(org.jboss.netty.channel.ChannelHandlerContext, * org.jboss.netty.channel.ChannelEvent) */ public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception { if (MessageEvent.class.isAssignableFrom(event.getClass())) { CommandInterpreter commandInterpreter = new CommandInterpreter(); CommandInterpreter.ProxyCommand readCommand = commandInterpreter.readCommand((MessageEvent) event); LOGGER.debug("Read Command : " + readCommand); String pool = readCommand.getCommandParams().get("pool"); TaskHandlerExecutor executor; // Try to execute command using ThreadPool, if "pool" is found in the command, else the // command name if (pool != null) { executor = this.repository.get(readCommand.getCommand(), pool); } else { executor = this.repository.get(readCommand.getCommand(), readCommand.getCommand()); } executor.setParams(readCommand.getCommandParams()); executor.setData(readCommand.getCommandData()); try { TaskResult result = executor.execute(); LOGGER.debug("The output is: " + result); // write the results to the channel output commandInterpreter.writeCommandExecutionResponse(ctx, event, result); } catch (Exception e) { LOGGER.error("Error in executing command/fallBack : " + readCommand, e); throw new RuntimeException("Error in executing command : " + readCommand, e); } } super.handleUpstream(ctx, event); }
@Override public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { if (e instanceof ChannelStateEvent) { logger.info(e.toString()); } super.handleUpstream(ctx, e); }