/**
  * 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 channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   // as seen in http://www.jboss.org/netty/community.html#nabble-td2423020
   super.channelOpen(ctx, e);
   if (group != null) {
     group.add(ctx.getChannel());
   }
 }
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
   if (e.getCause() instanceof JsonParseException) {
     BaseTransport.respond(
         e.getChannel(), HttpResponseStatus.INTERNAL_SERVER_ERROR, "Broken JSON encoding.");
   } else if (e.getCause() instanceof SessionHandler.NotFoundException) {
     BaseTransport.respond(
         e.getChannel(),
         HttpResponseStatus.NOT_FOUND,
         "Session not found. Cannot send data to non-existing session.");
   } else {
     super.exceptionCaught(ctx, e);
   }
 }
 public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   myAllOpenChannels.add(e.getChannel());
   super.channelOpen(ctx, e);
 }
 @Override
 public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) throws Exception {
   transportServiceAdapter.sent(e.getWrittenAmount());
   super.writeComplete(ctx, e);
 }
 /**
  * Overriden superclass method. Adds the newly created Channel to the default channel group and
  * calls the super class {@link #channelOpen(ChannelHandlerContext, ChannelStateEvent)} method
  *
  * @see
  *     org.jboss.netty.channel.SimpleChannelUpstreamHandler#channelOpen(org.jboss.netty.channel.ChannelHandlerContext,
  *     org.jboss.netty.channel.ChannelStateEvent)
  */
 public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent event) throws Exception {
   super.channelOpen(ctx, event);
 }
 /**
  * Overriden superclass method. Adds the newly created Channel to the default channel group and
  * calls the super class {@link #channelOpen(ChannelHandlerContext, ChannelStateEvent)} method
  *
  * @see
  *     org.jboss.netty.channel.SimpleChannelUpstreamHandler#channelOpen(org.jboss.netty.channel.ChannelHandlerContext,
  *     org.jboss.netty.channel.ChannelStateEvent)
  */
 public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent event) throws Exception {
   super.channelOpen(ctx, event);
   this.defaultChannelGroup.add(event.getChannel());
 }