protected String handleRequest(
      Channel channel, StreamInput buffer, long requestId, Version version) throws IOException {
    final String action = buffer.readString();

    final NettyTransportChannel transportChannel =
        new NettyTransportChannel(transport, action, channel, requestId, version);
    try {
      final TransportRequestHandler handler = transportServiceAdapter.handler(action);
      if (handler == null) {
        throw new ActionNotFoundTransportException(action);
      }
      final TransportRequest request = handler.newInstance();
      request.remoteAddress(
          new InetSocketTransportAddress((InetSocketAddress) channel.getRemoteAddress()));
      request.readFrom(buffer);
      if (handler.executor() == ThreadPool.Names.SAME) {
        //noinspection unchecked
        handler.messageReceived(request, transportChannel);
      } else {
        threadPool
            .executor(handler.executor())
            .execute(new RequestHandler(handler, request, transportChannel, action));
      }
    } catch (Throwable e) {
      try {
        transportChannel.sendResponse(e);
      } catch (IOException e1) {
        logger.warn("Failed to send error message back to client for action [" + action + "]", e);
        logger.warn("Actual Exception", e1);
      }
    }
    return action;
  }
 @SuppressWarnings({"unchecked"})
 @Override
 public void run() {
   try {
     handler.messageReceived(request, transportChannel);
   } catch (Throwable e) {
     if (transport.lifecycleState() == Lifecycle.State.STARTED) {
       // we can only send a response transport is started....
       try {
         transportChannel.sendResponse(e);
       } catch (Throwable e1) {
         logger.warn(
             "Failed to send error message back to client for action [" + action + "]", e1);
         logger.warn("Actual Exception", e);
       }
     }
   }
 }
 @Override
 public boolean isForceExecution() {
   return handler.isForceExecution();
 }
Exemplo n.º 4
0
 @SuppressWarnings({"unchecked"})
 @Override
 protected void doRun() throws Exception {
   handler.messageReceived(request, transportChannel);
 }