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

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


    IInputAdaptor httpInputAdaptor = new HttpInputAdaptor();
   
    defaultAnalysisEngine.addInputAdaptor(fileInputAdaptor);
    defaultAnalysisEngine.addInputAdaptor(httpInputAdaptor);
   
    SendResultsRequestEvent jobResponseEvent = new SendResultsRequestEvent("1234");
 
    JobTask task = jobManager.getJobs().values().iterator().next().getJobTasks().get(0);
   
    JobTaskResult jobTaskResult = defaultAnalysisEngine.doAnalysis(task)
 
    jobResponseEvent.setJobTaskResult(jobTaskResult);
   
    jobManager.addTaskResultToQueue(jobResponseEvent);
   
   
    JobTaskResult jobTaskResult2 = jobManager.getJobTaskResultsQueuePool().get(task.getJobName()).poll();
View Full Code Here


 
  @Override
  public String sendJobTaskResults(final SendResultsRequestEvent jobResponseEvent, final String master) {
      try
        {
            final SendResultsRequestEvent event = jobResponseEvent;
           
            // 简单的用这种模式模拟阻塞请求
            responseQueue.put(jobResponseEvent.getSequence(), jobResponseEvent);
//            slaveEventTimeQueue.add(jobResponseEvent);
           
            Channel channel = getChannel(master);
            jobResponseEvent.setChannel(channel);
            final long start = System.currentTimeMillis();
            ChannelFuture channelFuture = channel.write(jobResponseEvent);
//            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 send task result to master. tasks:"
                                + event.getJobTaskResult().toString() + ",use:" + (System.currentTimeMillis() - start),
                            future.getCause());
                        future.getChannel().close();
                    } else {
                        if (logger.isWarnEnabled()) {
                            logger.warn("send task success " + jobResponseEvent.getJobTaskResult().toString()
View Full Code Here

                }
            }
      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

                    try {
                        // 这里应该是这样的吧:
                        String masterAddr = entrySet.getKey();
                        // String masterAddr =
                        // entrySet.getKey().substring(entrySet.getKey().indexOf(":")+1);
                        SendResultsRequestEvent event = generateSendResultsRequestEvent(tResult);
                        String result = slaveConnector.sendJobTaskResults(event, entrySet.getKey());
                        if (result == null) {
                            Thread.sleep(100);
                            logger.warn("try to send result to master : " + masterAddr + " again.");
                            result = slaveConnector.sendJobTaskResults(event, masterAddr);

                            // 开始写入本地文件
                            if (result == null) {
                                logger.error(new StringBuilder("send result to master : ").append(entrySet.getKey())
                                    .append(" fail again! now to write file to local,jobName : ")
                                    .append(jobTask.getJobName()).toString());

                                String destFile = getTempStoreDataFile(entrySet.getKey(), jobTask.getJobName());

                                if (destFile != null) {
                                    JobDataOperation.export(event.getJobTaskResult().getResults(), destFile, false,
                                        false, (new HashMap<String, Long>()));
                                }
                            }
                        }

                        logger.info("send piece result to master :" + entrySet.getKey() + ", size:"
                                + entrySet.getValue().size() + ", result:" + result);
                    }
                    catch (Throwable e1) {
                        logger.error(e1, e1);
                    }
                }
                else {

                    analysisWorkerThreadPool.execute(new Runnable() {
                        public void run() {
                            try {
                                // 这里应该是这样的吧:
                                String masterAddr = entrySet.getKey();
                                // String masterAddr =
                                // entrySet.getKey().substring(entrySet.getKey().indexOf(":")+1);
                                SendResultsRequestEvent event = generateSendResultsRequestEvent(tResult);
                                String result = slaveConnector.sendJobTaskResults(event, entrySet.getKey());

                                // 做一次重试
                                if (result == null) {
                                    Thread.sleep(100);
                                    logger.warn("try to send result to master : " + masterAddr + " again.");
                                    result = slaveConnector.sendJobTaskResults(event, masterAddr);

                                    // 开始写入本地文件
                                    if (result == null) {
                                        logger.error(new StringBuilder("send result to master : ")
                                            .append(entrySet.getKey())
                                            .append(" fail again! now to write file to local,jobName : ")
                                            .append(jobTask.getJobName()).toString());

                                        String destFile = getTempStoreDataFile(entrySet.getKey(), jobTask.getJobName());

                                        if (destFile != null) {
                                            JobDataOperation.export(event.getJobTaskResult().getResults(), destFile,
                                                false, false, (new HashMap<String, Long>()));
                                        }
                                    }
                                }

                                logger.info("send piece result to master :" + entrySet.getKey() + ", size:"
                                        + entrySet.getValue().size() + ", result:" + result);
                            }
                            catch (Exception e) {
                                logger.error(e, e);
                            }
                            finally {
                                taskCountDownLatch.countDown();
                            }
                        }
                    });
                }
            }
            if (config.getMultiSendResult()) {
                try {
                    if (!taskCountDownLatch.await(this.config.getMaxSendResultTime(), TimeUnit.SECONDS))
                        logger.error("send piece result to master timeout !");
                }
                catch (InterruptedException e2) {
                    // do nothing
                }
            }
     
      //暂时采用策略,将所有结果向所有其他master投递一个空的结果集,以确保所有master都有收到
            //任务结束的通知,这里代码很丑陋啊~~
      final CountDownLatch taskCountDown = new CountDownLatch((masters.size() - _masterEntryResults.size()));
      for(final String master : masters) {
                if(_masterEntryResults.get(master) != null)
                    continue;
                final JobTaskResult tResult = jobTaskResult.cloneWithOutResults();
                tResult.setJobName(jobTask.getJobName());
                analysisWorkerThreadPool.execute(
                    new Runnable()
                    {
                        public void run()
                        {
                            try
                            {
                              // 这里应该是这样的吧:
                String masterAddr = master;
                                // String masterAddr = master.substring(master.indexOf(":")+1);
                                SendResultsRequestEvent event = generateSendResultsRequestEvent(tResult);
                                String result = slaveConnector.sendJobTaskResults(event,masterAddr);
                               
                                //做一次重试
                                if (result == null)
                                {
                                    Thread.sleep(100);
                                    logger.warn("try to send result to master : " + masterAddr + " again.");
                                    result = slaveConnector.sendJobTaskResults(event,masterAddr);
                                   
                                    //开始写入本地文件
                                    if (result == null)
                                    {
                                        logger.error( new StringBuilder("send result to master : ")
                                            .append(master).append(" fail again! now to write file to local,jobName : ")
                                            .append(jobTask.getJobName()).toString());
                                       
                                        String destFile = getTempStoreDataFile(master,jobTask.getJobName());
                                       
                                        if (destFile != null)
                                        {
                                            JobDataOperation.export(event.getJobTaskResult().getResults(), destFile,false,false, (new HashMap<String, Long>()));
                                        }
                                    }
                                }
                               
                                logger.info("send empty result to master :" + master + ", result:" + result);
View Full Code Here

   
  }
 
  public SendResultsRequestEvent generateSendResultsRequestEvent(JobTaskResult jobTaskResult)
  {
    SendResultsRequestEvent responseEvent = new SendResultsRequestEvent(new StringBuilder()
        .append(System.currentTimeMillis()).append("-").append(sequenceGen.incrementAndGet()).toString());

    responseEvent.setJobTaskResult(jobTaskResult);
    responseEvent.setMaxEventHoldTime(slaveConnector.getConfig().getMaxClientEventWaitTime());

    return responseEvent;
  }
View Full Code Here

TOP

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

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.