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);