Bootstrap

双链路集成多任务执行程序

通过redis来实现,每样操作都赋予一个key,执行操作时,给key赋值,执行完成后,将key移除。

 

1.先进行redis注册服务。每隔一分钟对服务名称进行注册。

2.分配任务

 判断有没有人进行任务分配,如果没有,当前服务进行任务分配。

如果有人分配任务,判断他是不是宕机了,如果宕机了,重新分配。

分配至要判断有没有未完成的服务操作,如果有,判断服务器是否宕机,如果宕机,把操作移交给其他存活的服务。

没有未完成的服务,则可以直接分配任务
3.根据分配的数据,执行

/*     */ package nsw.task.serivce.impl;
/*     */
/*     */ import java.io.PrintStream;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import nsw.task.redis.RedisConfig;
/*     */ import nsw.task.redis.RedisService;
/*     */ import nsw.task.serivce.BaseBusinessDealService;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Value;
/*     */ import org.springframework.data.redis.connection.RedisConnection;
/*     */ import org.springframework.data.redis.connection.RedisConnectionFactory;
/*     */ import org.springframework.data.redis.core.RedisTemplate;
/*     */ import org.springframework.data.redis.serializer.RedisSerializer;
/*     */ import org.springframework.scheduling.Trigger;
/*     */ import org.springframework.scheduling.TriggerContext;
/*     */ import org.springframework.scheduling.annotation.SchedulingConfigurer;
/*     */ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
/*     */ import org.springframework.scheduling.support.CronTrigger;
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */ public abstract class BaseBusinessDealServiceImpl
/*     */   implements BaseBusinessDealService, SchedulingConfigurer
/*     */ {
/*     */   @Value("${spring.redis.host}")
/*     */   public String host;
/*     */   @Value("${spring.redis.port}")
/*     */   public int port;
/*     */   @Value("${spring.redis.timeout}")
/*     */   public int timeOut;
/*     */   @Value("${spring.redis.jedis.pool.max-active}")
/*     */   public int maxActive;
/*     */   @Value("${spring.redis.jedis.pool.max-idle}")
/*     */   public int maxIdle;
/*     */   @Value("${spring.redis.jedis.pool.max-wait}")
/*     */   public long maxWait;
/*  47 */   public String password = null;
/*     */  
/*     */   public RedisService redisService;
/*  50 */   public Integer singleServer = Integer.valueOf(1);
/*  51 */   public Integer randomServer = Integer.valueOf(2);
/*  52 */   public Integer assignNum = Integer.valueOf(3);
/*  53 */   public Integer defaultAssignTaskNum = Integer.valueOf(100);
/*     */   List<Map<String, String>> taskAssignResultList;
/*     */  
/*     */   public BaseBusinessDealServiceImpl() {}
/*     */  
/*  58 */   public List<Map<String, String>> getTaskAssignResultList() { return this.taskAssignResultList; }
/*     */  
/*     */   public void setTaskAssignResultList(List<Map<String, String>> taskAssignResultList)
/*     */   {
/*  62 */     this.taskAssignResultList = taskAssignResultList;
/*     */   }
/*     */  
/*     */   public RedisService getRedisService() {
/*  66 */     if (this.redisService != null) {
/*  67 */       return this.redisService;
/*     */     }
/*  69 */     System.out.println("BaseBusinessDealServiceImpl##############################");
/*     */    
/*     */
/*  72 */     RedisConfig config = new RedisConfig();
/*  73 */     config.setHost(this.host);
/*  74 */     System.out.println("host##############################" + this.host);
/*  75 */     config.setMaxActive(this.maxActive);
/*  76 */     config.setMaxIdle(this.maxIdle);
/*  77 */     config.setMaxWait(this.maxWait);
/*  78 */     config.setPort(this.port);
/*  79 */     config.setTimeOut(this.timeOut);
/*  80 */     config.setPassword(this.password);
/*  81 */     this.redisService = new RedisService(config);
/*  82 */     return this.redisService;
/*     */   }
/*     */  
/*  85 */   Logger log = LoggerFactory.getLogger(BaseBusinessDealServiceImpl.class);
/*     */  
/*  87 */   private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/*     */  
/*     */
/*     */   @Value("${spring.nsw.task.manage.serverName}")
/*     */   public String serverName;
/*     */  
/*     */
/*     */   public String registCron;
/*     */  
/*     */   public String assignCron;
/*     */  
/*     */   public String pendingCron;
/*     */  
/* 100 */   public String registServerKey = getClass().getSimpleName() + "RegistServerKey";
/*     */  
/* 102 */   public String assignServerKey = getClass().getSimpleName() + "AssignServerKey";
/*     */  
/* 104 */   public String pendingServerKey = getClass().getSimpleName() + "PendingServerKey";
/*     */  
/*     */
/*     */   @Value("${spring.nsw.task.manage.aliveTime}")
/*     */   public int aliveTime;
/*     */  
/*     */
/*     */   public String registCron()
/*     */   {
/* 113 */     return "0/30 * * * * ?";
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */   public String assignCron()
/*     */   {
/* 121 */     return "0 0/2 * * * ?";
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */   public String pendingCron()
/*     */   {
/* 129 */     return "0 0/3 * * * ?";
/*     */   }
/*     */  
/*     */
/*     */
/*     */   public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar)
/*     */   {
/* 136 */     scheduledTaskRegistrar.addTriggerTask(new Runnable()
/*     */    
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/* 162 */       new Trigger
/*     */       {
/*     */         public void run() {
/*     */           try {
/* 140 */             BaseBusinessDealServiceImpl.this.registCron = BaseBusinessDealServiceImpl.this.registCron();
/*     */            
/* 142 */             BaseBusinessDealServiceImpl.this.log.info("---------------start-------------------");
/* 143 */             BaseBusinessDealServiceImpl.this.log.info("注册服务定时任务参数,时间表达式registCron为:" + BaseBusinessDealServiceImpl.this.registCron);
/* 144 */             BaseBusinessDealServiceImpl.this.log.info("当前时间为:" + BaseBusinessDealServiceImpl.this.sdf.format(new Date()));
/* 145 */             BaseBusinessDealServiceImpl.this.log.info("----------------end--------------------");
/*     */            
/* 147 */             if (StringUtils.isEmpty(BaseBusinessDealServiceImpl.this.serverName)) {
/* 148 */               BaseBusinessDealServiceImpl.this.log.info("serverName is not allow null");
/* 149 */               throw new Exception("serverName is not allow null");
/*     */             }
/* 151 */             boolean registerMonitor = BaseBusinessDealServiceImpl.this.registMethod(BaseBusinessDealServiceImpl.this.registServerKey, BaseBusinessDealServiceImpl.this.serverName);
/*     */            
/* 153 */             if (registerMonitor) {
/* 154 */               BaseBusinessDealServiceImpl.this.log.info(BaseBusinessDealServiceImpl.this.serverName + "向redis注册成功");
/*     */             } else {
/* 156 */               BaseBusinessDealServiceImpl.this.log.info(BaseBusinessDealServiceImpl.this.serverName + "向redis注册失败");
/* 157 */               throw new Exception("serverName regist fail");
/*     */             }
/*     */           }
/*     */           catch (Exception e)
/*     */           {
/* 162 */             e.printStackTrace(); } } }, new Trigger()
/*     */       {
/*     */
/*     */
/*     */         public Date nextExecutionTime(TriggerContext triggerContext)
/*     */         {
/*     */
/* 169 */           BaseBusinessDealServiceImpl.this.registCron = BaseBusinessDealServiceImpl.this.registCron();
/* 170 */           if (StringUtils.isNotEmpty(BaseBusinessDealServiceImpl.this.registCron)) {
/* 171 */             CronTrigger cronTrigger = new CronTrigger(BaseBusinessDealServiceImpl.this.registCron);
/* 172 */             Date nextExecDate = cronTrigger.nextExecutionTime(triggerContext);
/*     */            
/* 174 */             return nextExecDate;
/*     */           }
/* 176 */           return null;
/*     */
/*     */         }
/*     */        
/*     */
/* 181 */       });
/* 182 */     scheduledTaskRegistrar.addTriggerTask(new Runnable()
/*     */    
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/* 202 */       new Trigger
/*     */       {
/*     */         public void run()
/*     */         {
/*     */           try {
/* 187 */             BaseBusinessDealServiceImpl.this.assignCron = BaseBusinessDealServiceImpl.this.assignCron();
/* 188 */             if (StringUtils.isEmpty(BaseBusinessDealServiceImpl.this.assignCron)) {
/* 189 */               BaseBusinessDealServiceImpl.this.log.info("assignCron is not allow null");
/* 190 */               throw new Exception("assignCron is not allow null");
/*     */             }
/*     */            
/* 193 */             BaseBusinessDealServiceImpl.this.log.info("---------------start-------------------");
/* 194 */             BaseBusinessDealServiceImpl.this.log.info("分配服务定时任务参数,时间表达式assignCron为:" + BaseBusinessDealServiceImpl.this.assignCron);
/* 195 */             BaseBusinessDealServiceImpl.this.log.info("当前时间为:" + BaseBusinessDealServiceImpl.this.sdf.format(new Date()));
/* 196 */             BaseBusinessDealServiceImpl.this.log.info("----------------end--------------------");
/* 197 */             List<String> allTaskList = BaseBusinessDealServiceImpl.this.assignAllTaskList();
/* 198 */             List<Map<String, String>> result = BaseBusinessDealServiceImpl.this.assignMethod(allTaskList);
/* 199 */             BaseBusinessDealServiceImpl.this.doTaskAssignResult(result);
/*     */           }
/*     */           catch (Exception e) {
/* 202 */             e.printStackTrace(); } } }, new Trigger()
/*     */       {
/*     */
/*     */
/*     */         public Date nextExecutionTime(TriggerContext triggerContext)
/*     */         {
/*     */
/* 209 */           BaseBusinessDealServiceImpl.this.assignCron = BaseBusinessDealServiceImpl.this.assignCron();
/* 210 */           if (StringUtils.isNotEmpty(BaseBusinessDealServiceImpl.this.assignCron)) {
/* 211 */             CronTrigger cronTrigger = new CronTrigger(BaseBusinessDealServiceImpl.this.assignCron);
/* 212 */             Date nextExecDate = cronTrigger.nextExecutionTime(triggerContext);
/*     */            
/* 214 */             return nextExecDate;
/*     */           }
/* 216 */           return null;
/*     */
/*     */         }
/*     */        
/*     */
/*     */
/* 222 */       });
/* 223 */     scheduledTaskRegistrar.addTriggerTask(new Runnable()
/*     */    
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/* 241 */       new Trigger
/*     */       {
/*     */         public void run() {
/* 226 */           BaseBusinessDealServiceImpl.this.pendingCron = BaseBusinessDealServiceImpl.this.pendingCron();
/*     */           try {
/* 228 */             if (StringUtils.isEmpty(BaseBusinessDealServiceImpl.this.pendingCron)) {
/* 229 */               BaseBusinessDealServiceImpl.this.log.info("pendingCron is not allow null");
/* 230 */               throw new Exception("pendingCron is not allow null");
/*     */             }
/*     */            
/* 233 */             BaseBusinessDealServiceImpl.this.log.info("---------------start-------------------");
/* 234 */             BaseBusinessDealServiceImpl.this.log.info("执行任务定时任务参数,时间表达式pendingCron为:" + BaseBusinessDealServiceImpl.this.pendingCron);
/* 235 */             BaseBusinessDealServiceImpl.this.log.info("当前时间为:" + BaseBusinessDealServiceImpl.this.sdf.format(new Date()));
/* 236 */             BaseBusinessDealServiceImpl.this.log.info("----------------end--------------------");
/*     */            
/* 238 */             BaseBusinessDealServiceImpl.this.myTaskList();
/*     */           }
/*     */           catch (Exception e) {
/* 241 */             e.printStackTrace(); } } }, new Trigger()
/*     */       {
/*     */
/*     */
/*     */         public Date nextExecutionTime(TriggerContext triggerContext)
/*     */         {
/*     */
/* 248 */           BaseBusinessDealServiceImpl.this.pendingCron = BaseBusinessDealServiceImpl.this.pendingCron();
/* 249 */           if (StringUtils.isNotEmpty(BaseBusinessDealServiceImpl.this.pendingCron)) {
/* 250 */             CronTrigger cronTrigger = new CronTrigger(BaseBusinessDealServiceImpl.this.pendingCron);
/* 251 */             Date nextExecDate = cronTrigger.nextExecutionTime(triggerContext);
/*     */            
/* 253 */             return nextExecDate;
/*     */           }
/* 255 */           return null;
/*     */         }
/*     */       });
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */   public boolean registMethod(String serverKey, String serverName)
/*     */   {
/* 269 */     this.log.info("服务器名称:" + serverName + "注册服务到redis");
/* 270 */     if (this.log.isDebugEnabled()) {
/* 271 */       this.log.debug("服务器名称:" + serverName + "注册服务到redis");
/*     */     }
/* 273 */     this.redisService = getRedisService();
/* 274 */     Long time = this.redisService.getTime();
/* 275 */     return this.redisService.hmSet(serverKey, serverName, String.valueOf(time)).booleanValue();
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */   public Map<String, String> aliveServer()
/*     */   {
/* 287 */     this.redisService = getRedisService();
/* 288 */     Map<String, String> hgetAll = this.redisService.hgetAll(this.registServerKey);
/*     */     long time;
/* 290 */     if ((hgetAll != null) && (hgetAll.size() > 0)) {
/* 291 */       if (this.log.isDebugEnabled()) {
/* 292 */         this.log.debug("服务列表!" + hgetAll.toString());
/*     */       }
/* 294 */       this.log.info("服务列表!" + hgetAll.toString());
/* 295 */       Set<String> keySet = hgetAll.keySet();
/* 296 */       time = this.redisService.getTime().longValue();
/* 297 */       for (String currentServerName : keySet) {
/* 298 */         if (this.redisService == null) {
/* 299 */           this.redisService = getRedisService();
/*     */         }
/* 301 */         String timeStr = (String)hgetAll.get(currentServerName);
/* 302 */         long currentServerTime = Long.parseLong(timeStr);
/* 303 */         long interval = (time - currentServerTime) / 1000L;
/* 304 */         if (interval > this.aliveTime) {
/* 305 */           if (this.log.isDebugEnabled()) {
/* 306 */             this.log.debug("服务器名称:" + currentServerName + "服务过期!");
/*     */           }
/* 308 */           this.log.info("服务器名称:" + currentServerName + "服务过期!");
/* 309 */           this.redisService.hdel(this.registServerKey, currentServerName);
/* 310 */           if (this.log.isDebugEnabled()) {
/* 311 */             this.log.debug("服务器名称:" + currentServerName + "过期服务删除成功!");
/*     */           }
/* 313 */           this.log.info("服务器名称:" + currentServerName + "过期服务删除成功!");
/*     */         }
/*     */       }
/*     */     }
/* 317 */     return this.redisService.hgetAll(this.registServerKey);
/*     */   }
/*     */  
/*     */   public List<Map<String, String>> assignMethod(List<String> allTaskList) throws Exception {
/* 321 */     this.redisService = getRedisService();
/* 322 */     RedisConnection connection = null;
/* 323 */     this.log.info("服务器名称:" + this.serverName + "进入到指定一个分配任务方法");
/* 324 */     if (this.log.isDebugEnabled()) {
/* 325 */       this.log.debug("服务器名称:" + this.serverName + "进入到指定一个分配任务方法");
/*     */     }
/* 327 */     RedisTemplate<String, Object> template = this.redisService.getTemplate();
/*     */    
/* 329 */     RedisSerializer<String> stringSerializer = template.getStringSerializer();
/*     */    
/*     */
/* 332 */     connection = template.getConnectionFactory().getConnection();
/* 333 */     connection.watch(new byte[][] { stringSerializer.serialize(this.assignServerKey) });
/* 334 */     byte[] bs = connection.get(stringSerializer.serialize(this.assignServerKey));
/*     */    
/* 336 */     String currentServer = (String)stringSerializer.deserialize(bs);
/* 337 */     if ((allTaskList != null) && (allTaskList.size() > 0)) {
/* 338 */       if ((currentServer == null) || ("".equals(currentServer))) {
/* 339 */         fileAllocation(connection, stringSerializer, allTaskList);
/* 340 */       } else if (!currentServerState(currentServer)) {
/* 341 */         this.log.info("服务器名称:" + currentServer + "宕机");
/* 342 */         if (this.log.isDebugEnabled()) {
/* 343 */           this.log.debug("服务器名称:" + currentServer + "宕机");
/*     */         }
/* 345 */         fileAllocation(connection, stringSerializer, allTaskList);
/* 346 */       } else if (this.serverName.equals(currentServer)) {
/* 347 */         fileAllocation(connection, stringSerializer, allTaskList);
/*     */       }
/*     */     }
/* 350 */     this.redisService.close(connection);
/* 351 */     List<Map<String, String>> result = new ArrayList();
/* 352 */     return result;
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */   public void fileAllocation(RedisConnection connection, RedisSerializer<String> stringSerializer, List<String> allTaskList)
/*     */     throws Exception
/*     */   {
/* 364 */     if (this.redisService == null) {
/* 365 */       this.redisService = getRedisService();
/*     */     }
/* 367 */     connection.multi();
/*     */    
/* 369 */     connection.set(stringSerializer.serialize(this.assignServerKey), stringSerializer.serialize(this.serverName));
/*     */    
/* 371 */     List<Object> exec = connection.exec();
/* 372 */     connection.unwatch();
/* 373 */     if (exec == null) {
/* 374 */       this.log.info("服务器名称:" + this.serverName + "没有任务分配");
/* 375 */       if (this.log.isDebugEnabled()) {
/* 376 */         this.log.debug("服务器名称:" + this.serverName + "没有任务分配");
/*     */       }
/* 378 */       return;
/*     */     }
/*     */    
/* 381 */     Map<String, String> hgetAll = this.redisService.hgetAll(this.pendingServerKey);
/* 382 */     if ((hgetAll != null) && (hgetAll.size() > 0))
/*     */     {
/* 384 */       survivalCheck(hgetAll);
/*     */     } else {
/* 386 */       fileAssign(allTaskList);
/*     */     }
/* 388 */     this.redisService.remove(this.assignServerKey);
/* 389 */     this.log.info("服务器名称:" + this.serverName + "完成任务分配");
/* 390 */     if (this.log.isDebugEnabled()) {
/* 391 */       this.log.debug("服务器名称:" + this.serverName + "完成任务分配");
/*     */     }
/*     */   }
/*     */  
/*     */
/*     */
/*     */   public boolean currentServerState(String currentServer)
/*     */   {
/* 399 */     if (this.redisService == null) {
/* 400 */       this.redisService = getRedisService();
/*     */     }
/* 402 */     String hget = (String)this.redisService.hmGet(this.registServerKey, currentServer);
/*     */    
/* 404 */     if ((hget == null) || ("".equals(hget))) {
/* 405 */       return false;
/*     */     }
/* 407 */     long currentServerTime = Long.parseLong(hget);
/* 408 */     long time = this.redisService.getTime().longValue();
/* 409 */     long interval = (time - currentServerTime) / 1000L;
/* 410 */     if (interval > this.aliveTime) {
/* 411 */       if (this.log.isDebugEnabled()) {
/* 412 */         this.log.debug("服务器名称:" + currentServer + "服务过期!");
/*     */       }
/* 414 */       this.log.info("服务器名称:" + currentServer + "服务过期!");
/* 415 */       this.redisService.hdel(this.registServerKey, currentServer);
/* 416 */       if (this.log.isDebugEnabled()) {
/* 417 */         this.log.debug("服务器名称:" + currentServer + "过期服务删除成功!");
/*     */       }
/* 419 */       this.log.info("服务器名称:" + currentServer + "过期服务删除成功!");
/* 420 */       return false;
/*     */     }
/* 422 */     return true;
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */   public void survivalCheck(Map<String, String> hgetAll)
/*     */     throws Exception
/*     */   {
/* 431 */     List<String> fileList = new ArrayList();
/* 432 */     Set<String> keySet = hgetAll.keySet();
/* 433 */     for (String key : keySet) {
/* 434 */       String currentServer = (String)hgetAll.get(key);
/* 435 */       boolean currentServerState = currentServerState(currentServer);
/* 436 */       if (!currentServerState) {
/* 437 */         fileList.add(key);
/*     */       }
/*     */     }
/*     */    
/* 441 */     if ((fileList != null) && (fileList.size() > 0)) {
/* 442 */       fileAssign(fileList);
/*     */     }
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */
/*     */   public void fileAssign(List<String> fileList)
/*     */     throws Exception
/*     */   {
/* 453 */     if (this.redisService == null) {
/* 454 */       this.redisService = getRedisService();
/*     */     }
/* 456 */     Map<String, String> aliveServer = aliveServer();
/* 457 */     Integer taskType = taskType();
/* 458 */     if (this.singleServer.equals(taskType)) {
/* 459 */       if ((aliveServer != null) && (aliveServer.size() > 0)) {
/* 460 */         for (int i = 0; i < fileList.size(); i++) {
/* 461 */           if (this.redisService == null) {
/* 462 */             this.redisService = getRedisService();
/*     */           }
/* 464 */           this.redisService.hmSet(this.pendingServerKey, (String)fileList.get(i), this.serverName);
/*     */         }
/*     */       }
/*     */     }
/* 468 */     else if ((this.randomServer.equals(taskType)) || (taskType == null)) {
/* 469 */       randomAssign(aliveServer, fileList);
/* 470 */     } else if ((this.assignNum.equals(taskType)) &&
/* 471 */       (aliveServer != null) && (aliveServer.size() > 0)) {
/* 472 */       Integer assignTaskNum = assignTaskNum();
/* 473 */       if ((assignTaskNum == null) || (assignTaskNum.intValue() == 0)) {
/* 474 */         assignTaskNum = this.defaultAssignTaskNum;
/*     */       }
/* 476 */       Set<String> keySet = aliveServer.keySet();
/* 477 */       List<String> serList = new ArrayList();
/* 478 */       for (String string : keySet) {
/* 479 */         serList.add(string);
/*     */       }
/*     */      
/* 482 */       int size = fileList.size();
/* 483 */       int count = (size + assignTaskNum.intValue() - 1) / assignTaskNum.intValue();
/*     */      
/* 485 */       for (int i = 0; i < count; i++) {
/* 486 */         if (serList.size() < i + 1) {
/*     */           break;
/*     */         }
/* 489 */         List<String> subList = fileList.subList(i * assignTaskNum.intValue(), (i + 1) * assignTaskNum.intValue() > size ? size : assignTaskNum.intValue() * (i + 1));
/*     */        
/*     */
/*     */
/* 493 */         for (String myTask : subList) {
/* 494 */           if (this.redisService == null) {
/* 495 */             this.redisService = getRedisService();
/*     */           }
/* 497 */           this.redisService.hmSet(this.pendingServerKey, myTask, (String)serList.get(i % serList.size()));
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */   public void myTaskList()
/*     */   {
/* 510 */     this.redisService = getRedisService();
/*     */    
/* 512 */     List<String> myTaskList = new ArrayList();
/* 513 */     Map<String, String> hgetAll = this.redisService.hgetAll(this.pendingServerKey);
/* 514 */     Set<String> keySet = hgetAll.keySet();
/* 515 */     for (String fileName : keySet) {
/* 516 */       String currentServerName = (String)hgetAll.get(fileName);
/* 517 */       if (this.serverName.equals(currentServerName)) {
/* 518 */         myTaskList.add(fileName);
/*     */       }
/*     */     }
/* 521 */     for (String myTask : myTaskList) {
/* 522 */       if (this.redisService == null) {
/* 523 */         this.redisService = getRedisService();
/*     */       }
/* 525 */       boolean doMyTask = doMyTask(myTask);
/* 526 */       if (doMyTask) {
/* 527 */         this.redisService.hdel(this.pendingServerKey, myTask);
/*     */       }
/*     */     }
/*     */   }
/*     */  
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */   public void randomAssign(Map<String, String> aliveServer, List<String> fileList)
/*     */   {
/* 544 */     if ((aliveServer != null) && (aliveServer.size() > 0)) {
/* 545 */       Set<String> keySet = aliveServer.keySet();
/* 546 */       List<String> serList = new ArrayList();
/* 547 */       for (String string : keySet) {
/* 548 */         serList.add(string);
/*     */       }
/*     */      
/*     */
/*     */
/* 553 */       if ((serList != null) && (serList.size() > 0) && (fileList != null) && (fileList.size() > 0))
/*     */       {
/* 555 */         for (int i = 0; i < fileList.size(); i++) {
/* 556 */           if (this.redisService == null) {
/* 557 */             this.redisService = getRedisService();
/*     */           }
/* 559 */           this.redisService.hmSet(this.pendingServerKey, (String)fileList.get(i), (String)serList.get(i % serList.size()));
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */  
/*     */   public void doTaskAssignResult(List<Map<String, String>> result) {}
/*     */ }
/* Location:           C:\Users\fanlili\.m2\repository\nsw-task-manage\nsw-task-manage\0.0.1-SNAPSHOT\nsw-task-manage-0.0.1-SNAPSHOT.jar
 * Qualified Name:     nsw.task.serivce.impl.BaseBusinessDealServiceImpl
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.0.1
 */

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;