Ejemplo n.º 1
0
  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    final Channel channel = ctx.getChannel();
    SocketMessage sm = (SocketMessage) e.getMessage();
    if (sm.getKind() == Kind.REQUEST) {
      final Request request = Request.newBuilder().mergeFrom(sm.getBody()).build();
      if (request.getOperate() == Operate.HeartBeat) {
        beHeartBeat.beHeartBeat(context, channel, request);
      }
    } else if (sm.getKind() == Kind.WEB_REUQEST) {
      final WebRequest request = WebRequest.newBuilder().mergeFrom(sm.getBody()).build();
      if (request.getOperate() == WebOperate.ExecuteJob) {
        completionService.submit(
            new Callable<ChannelResponse>() {
              public ChannelResponse call() throws Exception {
                return new ChannelResponse(channel, beWebExecute.beWebExecute(context, request));
              }
            });
      } else if (request.getOperate() == WebOperate.CancelJob) {
        completionService.submit(
            new Callable<ChannelResponse>() {
              public ChannelResponse call() throws Exception {
                return new ChannelResponse(channel, beWebCancel.beWebCancel(context, request));
              }
            });
      } else if (request.getOperate() == WebOperate.UpdateJob) {
        completionService.submit(
            new Callable<ChannelResponse>() {
              public ChannelResponse call() throws Exception {
                return new ChannelResponse(channel, beUpdate.beWebUpdate(context, request));
              }
            });
      } else if (request.getOperate() == WebOperate.ExecuteDebug) {
        completionService.submit(
            new Callable<ChannelResponse>() {
              public ChannelResponse call() throws Exception {
                return new ChannelResponse(channel, beDebug.beWebExecute(context, request));
              }
            });
      }
    } else if (sm.getKind() == Kind.RESPONSE) {
      for (ResponseListener lis : new ArrayList<ResponseListener>(listeners)) {
        lis.onResponse(Response.newBuilder().mergeFrom(sm.getBody()).build());
      }
    } else if (sm.getKind() == Kind.WEB_RESPONSE) {
      for (ResponseListener lis : new ArrayList<ResponseListener>(listeners)) {
        lis.onWebResponse(WebResponse.newBuilder().mergeFrom(sm.getBody()).build());
      }
    }

    super.messageReceived(ctx, e);
  }
Ejemplo n.º 2
0
 private SocketMessage wapper(WebResponse resp) {
   return SocketMessage.newBuilder()
       .setKind(Kind.WEB_RESPONSE)
       .setBody(resp.toByteString())
       .build();
 }