Package com.taobao.top.analysis.node.event

Examples of com.taobao.top.analysis.node.event.GetTaskRequestEvent


  @Test
  public void testGetUnDoJobTasks() throws AnalysisException, InterruptedException {
   
   
    GetTaskRequestEvent event = new GetTaskRequestEvent("1234567");
    event.setRequestJobCount(2);
   
    jobManager.getUnDoJobTasks(event);
   
    GetTaskResponseEvent eventresp = (GetTaskResponseEvent)tunnel.getSlaveSide().poll();
   
    Assert.assertEquals(event.getSequence(), eventresp.getSequence());
    Assert.assertEquals(2, eventresp.getJobTasks().size());
   
    event = new GetTaskRequestEvent("1234567");
    event.setRequestJobCount(2);
    event.setJobName("job2");
   
    jobManager.getUnDoJobTasks(event);
   
    eventresp = (GetTaskResponseEvent)tunnel.getSlaveSide().poll();
   
    Assert.assertEquals(event.getSequence(), eventresp.getSequence());
    Assert.assertEquals(1, eventresp.getJobTasks().size());
   
  }
View Full Code Here


   
    Assert.assertEquals("success", sendResultsResponseEvent.getResponse());
   
   
    //验证少了一个任务
    GetTaskRequestEvent event = new GetTaskRequestEvent("1234567");
    event.setRequestJobCount(3);
   
    jobManager.getUnDoJobTasks(event);
   
   
    GetTaskResponseEvent eventresp = (GetTaskResponseEvent)tunnel.getSlaveSide().poll();
   
    Assert.assertEquals(event.getSequence(), eventresp.getSequence());
    Assert.assertEquals(2, eventresp.getJobTasks().size());
   
    defaultAnalysisEngine.releaseResource();
  }
View Full Code Here

  }

  @Test
  public void testCheckJobStatus() throws InterruptedException, AnalysisException {
    //验证一共3个任务
    GetTaskRequestEvent event = new GetTaskRequestEvent("1234567");
    event.setRequestJobCount(3);
   
    jobManager.getUnDoJobTasks(event);
   
    GetTaskResponseEvent eventresp = (GetTaskResponseEvent)tunnel.getSlaveSide().poll();
   
    Assert.assertEquals(event.getSequence(), eventresp.getSequence());
    Assert.assertEquals(3, eventresp.getJobTasks().size());
   
    //验证没有任务
    event = new GetTaskRequestEvent("12345678");
    event.setRequestJobCount(3);
   
    jobManager.getUnDoJobTasks(event);
   
    eventresp = (GetTaskResponseEvent)tunnel.getSlaveSide().poll();
   
    Assert.assertEquals(event.getSequence(), eventresp.getSequence());
    Assert.assertEquals(0, eventresp.getJobTasks().size());
   
    //任务被回收
    Thread.sleep(21 * 1000);
   
    //验证一共3个任务
    jobManager.checkJobStatus();
   
    event = new GetTaskRequestEvent("12345679");
    event.setRequestJobCount(3);
   
    jobManager.getUnDoJobTasks(event);
   
    eventresp = (GetTaskResponseEvent)tunnel.getSlaveSide().poll();
   
    Assert.assertEquals(event.getSequence(), eventresp.getSequence());
    Assert.assertEquals(3, eventresp.getJobTasks().size());
   
    Assert.assertEquals(1,eventresp.getJobTasks().get(0).getRecycleCounter().get());
       
  }
View Full Code Here

  @Override
  public JobTask[] getJobTasks(GetTaskRequestEvent requestEvent) {
    JobTask[] tasks = null;

    try {
      final GetTaskRequestEvent event = requestEvent;
      // 简单的用这种模式模拟阻塞请求
      if(logger.isInfoEnabled())
          logger.info("trying to get tasks from master " + requestEvent.getRequestJobCount());
      responseQueue.put(requestEvent.getSequence(), requestEvent);
//      slaveEventTimeQueue.add(requestEvent);
     
      Channel channel = getChannel(leaderChannel);
     
      requestEvent.setChannel(channel);
     
      ChannelFuture channelFuture = channel.write(requestEvent);

      // why ??, 这里不必等待
      //channelFuture.await(10, TimeUnit.SECONDS);

      channelFuture.addListener(new ChannelFutureListener() {
        public void operationComplete(ChannelFuture future) {
          if (!future.isSuccess()) {
            responseQueue.remove(event.getSequence());
//            slaveEventTimeQueue.remove(event);
           
            logger.error("Slavesocket write error when trying to get tasks from master.",
                future.getCause());
            future.getChannel().close();
View Full Code Here

      }
     
            if (nodeEvent.getEventCode().equals(MasterEventCode.GET_TASK)) {
                //INFO信息记录M/S通信内容
                if (logger.isInfoEnabled()) {
                    GetTaskRequestEvent requestEvent = (GetTaskRequestEvent) nodeEvent;
                    String jobName = requestEvent.getJobName();
                    int jobCount = requestEvent.getRequestJobCount();
                    StringBuffer stringBuffer = new StringBuffer("receive get_task event, jobName:");
                    if (jobName != null)
                        stringBuffer.append("jobName:").append(jobName).append(",");
                    stringBuffer.append("jobCount:").append(jobCount).append(",from:")
                        .append(channel.getRemoteAddress()).append(",squence:").append(nodeEvent.getSequence());
                    logger.info(stringBuffer.toString());
                }
            }
      if(nodeEvent.getEventCode().equals(MasterEventCode.SEND_RESULT)) {
          //INFO信息记录M/S通信内容
          if(logger.isInfoEnabled()) {
              SendResultsRequestEvent requestEvent = (SendResultsRequestEvent)nodeEvent;
                  StringBuffer stringBuffer = new StringBuffer("receive send_result event, result:{");
                  stringBuffer.append(requestEvent.getJobTaskResult().toString()).append("}");
                  stringBuffer.append("from slave:").append(channel.getRemoteAddress()).append(",squence:").append(nodeEvent.getSequence());
              logger.info(stringBuffer.toString());
          }
      }
      if(nodeEvent.getEventCode().equals(MasterEventCode.SEND_MONITOR_INFO)) {
         //INFO信息记录M/S通信内容
          if(logger.isInfoEnabled()) {
              SendMonitorInfoEvent requestEvent = (SendMonitorInfoEvent)nodeEvent;
                  StringBuffer stringBuffer = new StringBuffer("receive send_monitor_info event, result:{");
                  stringBuffer.append(requestEvent.getSlaveMonitorInfo().toString()).append("}");
                  stringBuffer.append("from slave:").append(channel.getRemoteAddress()).append(",squence:").append(nodeEvent.getSequence());
              logger.info(stringBuffer.toString());
          }
      }
    }
View Full Code Here

      //状态处于关闭状态时,不再向master请求新的任务
      if(stopped)
          return;
   
    //尝试获取任务
    GetTaskRequestEvent event = new GetTaskRequestEvent(new StringBuilder()
      .append(System.currentTimeMillis()).append("-").append(sequenceGen.incrementAndGet()).toString());
    event.setRequestJobCount(config.getMaxTransJobCount());
    event.setMaxEventHoldTime(config.getMaxClientEventWaitTime());
   
    if (config.getJobName() != null)
      event.setJobName(config.getJobName());
   
    // 拉任务开始时间
    long start = System.currentTimeMillis();
    JobTask[] jobTasks = slaveConnector.getJobTasks(event);
    // 统计平均拉取任情况
View Full Code Here

TOP

Related Classes of com.taobao.top.analysis.node.event.GetTaskRequestEvent

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.