Package com.flipkart.phantom.runtime.impl.server.netty.handler.command

Examples of com.flipkart.phantom.runtime.impl.server.netty.handler.command.CommandInterpreter


   * @see org.jboss.netty.handler.codec.frame.FrameDecoder#decode(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel, org.jboss.netty.buffer.ChannelBuffer)
   */
  protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    int beginIndex = buffer.readerIndex();
    buffer.markReaderIndex();
    CommandInterpreter.ProxyCommand proxyCommand = new CommandInterpreter().interpretCommand(buffer);
    if (proxyCommand.getReadFailure() != null && proxyCommand.getReadFailure() == ReadFailure.INSUFFICIENT_DATA) {
      LOGGER.debug("Frame decode failed due to insufficient data. Message is : " + proxyCommand.getReadFailureDescription());
            buffer.resetReaderIndex();
      return null; // we return null here and Netty will call this decoder again when more data is available
    }
View Full Code Here


        public void run() {
            long receiveTime = System.currentTimeMillis();
            TaskHandlerExecutor executor = null;
            CommandInterpreter.ProxyCommand readCommand = null;
            try {
                CommandInterpreter commandInterpreter = new CommandInterpreter();
                readCommand = commandInterpreter.readCommand(client.getInputStream());
                LOGGER.debug("Read Command : " + readCommand);
                String pool = readCommand.getCommandParams().get("pool");

                // Prepare the request Wrapper
                TaskRequestWrapper taskRequestWrapper = new TaskRequestWrapper();
                taskRequestWrapper.setData(readCommand.getCommandData());
                taskRequestWrapper.setParams(readCommand.getCommandParams());

                /*Try to execute command using ThreadPool, if "pool" is found in the command, else the command name */
                if (pool != null) {
                    executor = (TaskHandlerExecutor) repository.getExecutor(readCommand.getCommand(), pool, taskRequestWrapper);
                } else {
                    executor = (TaskHandlerExecutor) repository.getExecutor(readCommand.getCommand(), readCommand.getCommand(), taskRequestWrapper);
                }
                TaskResult result;
                /* execute */
                if (executor.getCallInvocationType() == TaskHandler.SYNC_CALL) {
                    result = executor.execute();
                } else {
                    /* dont wait for the result. send back a response that the call has been dispatched for async execution */
                    executor.queue();
                    result = new TaskResult(true, TaskHandlerExecutor.ASYNC_QUEUED);
                }
                LOGGER.debug("The output is: " + result);

                // write the results to the socket output
                commandInterpreter.writeCommandExecutionResponse(client.getOutputStream(), result);
            } catch (Exception e) {
                throw new RuntimeException("Error in processing command : " + e.getMessage(), e);
            } finally {
                if (eventProducer != null) {
                    // Publishes event both in case of success and failure.
View Full Code Here

TOP

Related Classes of com.flipkart.phantom.runtime.impl.server.netty.handler.command.CommandInterpreter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.