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

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


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


    // 响应失败,返回失败退出码
    JobHistory history=context.getJobHistoryManager().findJobHistory(id);
    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() {
          public void onWebResponse(WebResponse resp) {}
          public void onResponse(Response resp) {
            if(resp.getRid()==req.getRid()){
              context.getHandler().removeListener(this);
              response=resp;
              latch.countDown();
            }
          }
        });
        try {
          latch.await();
        } finally{
          holder.getRunnings().remove(jobId);
        }
        return response;
      }
    });
    holder.getChannel().write(sm);
    SocketLog.info("master send execute command to worker,rid="+req.getRid()+",jobId="+jobId);
    return f;
  }
View Full Code Here

    // 等待worker响应
    // 响应OK 则添加监听器,继续等待任务完成的消息
    // 响应失败,返回失败退出码
    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() {
          public void onWebResponse(WebResponse resp) {}
          public void onResponse(Response resp) {
            if(resp.getRid()==req.getRid()){
              context.getHandler().removeListener(this);
              response=resp;
              latch.countDown();
            }
          }
        });
        try {
          latch.await();
        } finally{
          holder.getManualRunnings().remove(historyId);
        }
        return response;
      }
    });
    holder.getChannel().write(sm);
    SocketLog.info("master send manual command to worker,rid="+req.getRid()+",historyId="+historyId);
    return f;
  }
View Full Code Here

    // 等待worker响应
    // 响应OK 则添加监听器,继续等待任务完成的消息
    // 响应失败,返回失败退出码
    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() {
          public void onWebResponse(WebResponse resp) {}
          public void onResponse(Response resp) {
            if(resp.getRid()==req.getRid()){
              context.getHandler().removeListener(this);
              response=resp;
              latch.countDown();
            }
          }
        });
        try {
          latch.await();
        } finally{
          holder.getDebugRunnings().remove(id);
        }
        return response;
      }
    });
    holder.getChannel().write(sm);
    SocketLog.info("master send debug command to worker,rid="+req.getRid()+",debugId="+id);
    return f;
  }
View Full Code Here

  public Future<Response> cancel(final MasterContext context,Channel channel,ExecuteKind ek,String id){
    // 如果在运行中 从worker列表中查询正在运行该job的woker,发出取消命令
    // 如果在等待队列,从等待队列删除
    // 如果都不在,抛出异常
    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() {
          public void onWebResponse(WebResponse resp) {}
          public void onResponse(Response resp) {
            if(req.getRid()==resp.getRid()){
              context.getHandler().removeListener(this);
              response=resp;
              latch.countDown();
            }
          }
View Full Code Here

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

    HeartBeatMessage hbm=HeartBeatMessage.newBuilder().setMemRate(((Double)jobContext.getData("mem")).floatValue())
      .addAllDebugRunnings(context.getDebugRunnings().keySet())
      .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

TOP

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

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.