Package com.taobao.zeus.socket.protocol.Protocol

Examples of com.taobao.zeus.socket.protocol.Protocol.SocketMessage


    return SocketMessage.newBuilder().setKind(Kind.RESPONSE).setBody(resp.toByteString()).build();
  }
  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
      throws Exception {
    SocketMessage sm=(SocketMessage) e.getMessage();
    if(sm.getKind()==Kind.REQUEST){
      final Request request=Request.newBuilder().mergeFrom(sm.getBody()).build();
      Operate op=request.getOperate();
      if(op==Operate.Schedule || op==Operate.Manual || op==Operate.Debug){
        completionService.submit(new Callable<Response>() {
          private WorkerBeExecute execute=new WorkerBeExecute();
          public Response call() throws Exception {
            return execute.execute(context, request).get();
          }
        });
      }else if(request.getOperate()==Operate.Cancel){
        completionService.submit(new Callable<Response>() {
          private WorkerBeCancel cancel=new WorkerBeCancel();
          public Response call() throws Exception {
            return cancel.execute(context, request).get();
          }
        });
      }
    }else if(sm.getKind()==Kind.RESPONSE){
      final Response resp=Response.newBuilder().mergeFrom(sm.getBody()).build();
      for(ResponseListener lis:listeners){
        lis.onResponse(resp);
      }
    }else if(sm.getKind()==Kind.WEB_RESPONSE){
      final WebResponse resp=WebResponse.newBuilder().mergeFrom(sm.getBody()).build();
      for(ResponseListener lis:listeners){
        lis.onWebResponse(resp);
      }
    }
    super.messageReceived(ctx, e);
View Full Code Here


    final String jobId=history.getJobId();
    holder.getRunnings().put(jobId,false);
    ExecuteMessage em=ExecuteMessage.newBuilder().setJobId(jobId).build();
    final Request req=Request.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(Operate.Schedule)
      .setBody(em.toByteString()).build();
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.REQUEST).setBody(req.toByteString()).build();
    Future<Response> f=context.getThreadPool().submit(new Callable<Response>() {
      private Response response;
      public Response call() throws Exception {
        final CountDownLatch latch=new CountDownLatch(1);
        context.getHandler().addListener(new ResponseListener() {
View Full Code Here

    // 响应失败,返回失败退出码
    holder.getManualRunnings().put(historyId,false);
    ManualMessage mm=ManualMessage.newBuilder().setHistoryId(historyId).build();
    final Request req=Request.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(Operate.Manual)
      .setBody(mm.toByteString()).build();
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.REQUEST).setBody(req.toByteString()).build();
    Future<Response> f=context.getThreadPool().submit(new Callable<Response>() {
      private Response response;
      public Response call() throws Exception {
        final CountDownLatch latch=new CountDownLatch(1);
        context.getHandler().addListener(new ResponseListener() {
View Full Code Here

    // 响应失败,返回失败退出码
    holder.getDebugRunnings().put(id,false);
    DebugMessage dm=DebugMessage.newBuilder().setDebugId(id).build();
    final Request req=Request.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(Operate.Debug)
      .setBody(dm.toByteString()).build();
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.REQUEST).setBody(req.toByteString()).build();
    Future<Response> f=context.getThreadPool().submit(new Callable<Response>() {
      private Response response;
      public Response call() throws Exception {
        final CountDownLatch latch=new CountDownLatch(1);
        context.getHandler().addListener(new ResponseListener() {
View Full Code Here

    // 如果在等待队列,从等待队列删除
    // 如果都不在,抛出异常
    CancelMessage cm=CancelMessage.newBuilder().setEk(ek).setId(id).build();
    final Request req=Request.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(Operate.Cancel)
      .setBody(cm.toByteString()).build();
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.REQUEST).setBody(req.toByteString()).build();
    Future<Response> f=context.getThreadPool().submit((new Callable<Response>() {
      private Response response;
      public Response call() throws Exception {
        final CountDownLatch latch=new CountDownLatch(1);
        context.getHandler().addListener(new ResponseListener() {
View Full Code Here

 
  public Future<WebResponse> send(final WorkerContext context,ExecuteKind kind,String id){
   
    final WebRequest req=WebRequest.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(WebOperate.ExecuteJob)
      .setEk(kind).setId(id).build();
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.WEB_REUQEST).setBody(req.toByteString()).build();
   
    Future<WebResponse> f=context.getThreadPool().submit(new Callable<WebResponse>() {
      private WebResponse response;
      public WebResponse call() throws Exception {
        final CountDownLatch latch=new CountDownLatch(1);
View Full Code Here

  public Future<WebResponse> execute(final WorkerContext context,String jobId){
    final WebRequest req=WebRequest.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(WebOperate.UpdateJob)
      .setEk(ExecuteKind.ManualKind)//此次无用,随便设置一个
      .setId(jobId).build();
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.WEB_REUQEST).setBody(req.toByteString()).build();
   
    Future<WebResponse> f=context.getThreadPool().submit(new Callable<WebResponse>() {
      private WebResponse response;
      public WebResponse call() throws Exception {
        final CountDownLatch latch=new CountDownLatch(1);
View Full Code Here

 
  @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);
  }
View Full Code Here

      .addAllManualRunnings(context.getManualRunnings().keySet())
      .addAllRunnings(context.getRunnings().keySet())
      .setTimestamp(new Date().getTime()).build();
    Request req=Request.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(Operate.HeartBeat).setBody(hbm.toByteString()).build();
   
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.REQUEST).setBody(req.toByteString()).build();
    return context.getServerChannel().write(sm);
  }
View Full Code Here

 
  public Future<WebResponse> cancel(final WorkerContext context,ExecuteKind kind,String id,String operater){
    final WebRequest req=WebRequest.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(WebOperate.CancelJob)
      .setExecutor(operater).setEk(kind).setId(id).build();
   
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.WEB_REUQEST).setBody(req.toByteString()).build();
    Future<WebResponse> f=context.getThreadPool().submit(new Callable<WebResponse>() {
      private WebResponse response;
      public WebResponse call() throws Exception {
        final CountDownLatch latch=new CountDownLatch(1);
        context.getHandler().addListener(new ResponseListener() {
View Full Code Here

TOP

Related Classes of com.taobao.zeus.socket.protocol.Protocol.SocketMessage

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.