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

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


public class WorkerWebExecute {
 
  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);
        context.getHandler().addListener(new ResponseListener() {
          public void onWebResponse(WebResponse resp) {
            if(resp.getRid()==req.getRid()){
              context.getHandler().removeListener(this);
              response=resp;
              latch.countDown();
            }
          }
          public void onResponse(Response resp) {}
        });
        latch.await();
        return response;
      }
    });
    context.getServerChannel().write(sm);
    SocketLog.info("send web execute request,rid="+req.getRid()+",kind="+kind+",id="+id);
    return f;
   
  }
View Full Code Here


import com.taobao.zeus.socket.worker.WorkerHandler.ResponseListener;

public class WorkerWebUpdate {

  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);
        context.getHandler().addListener(new ResponseListener() {
          public void onWebResponse(WebResponse resp) {
            if(resp.getRid()==req.getRid()){
              context.getHandler().removeListener(this);
              response=resp;
              latch.countDown();
            }
          }
          public void onResponse(Response resp) {}
        });
        latch.await();
        return response;
      }
    });
    context.getServerChannel().write(sm);
    SocketLog.info("send web update to master,rid="+req.getRid()+",jobId="+jobId);
    return f;
  }
View Full Code Here

      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

public class WorkerWebCancel {

 
  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() {
          public void onWebResponse(WebResponse resp) {
            if(resp.getRid()==req.getRid()){
              context.getHandler().removeListener(this);
              response=resp;
              latch.countDown();
            }
          }
          public void onResponse(Response resp) {}
        });
        latch.await();
        return response;
      }
    });
    context.getServerChannel().write(sm);
    SocketLog.info("send web cancel request,rid="+req.getRid()+",id="+id);
    return f;
  }
View Full Code Here

TOP

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

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.