@Override
 public IApprovalProcess checkProcess(IApprovalData data) {
   if (data == null) {
     return null;
   }
   if (!data.isNew()) {
     // 不是新建查看是否存在审批
     IApprovalProcess aProcess = this.loadApprovalProcess(data.getIdentifiers());
     if (aProcess != null) {
       return aProcess;
     }
   }
   // 创建审批流程并尝试开始
   if (this.checkDataStatus(data)) {
     Iterator<IApprovalProcess> process = this.createApprovalProcess(data.getObjectCode());
     while (process != null && process.hasNext()) {
       IApprovalProcess aProcess = process.next();
       if (aProcess.start(data)) {
         RuntimeLog.log(RuntimeLog.MSG_APPROVAL_PROCESS_STARTED, data, aProcess.getName());
         return aProcess; // 审批流程开始
       }
     }
   }
   return null;
 }
示例#2
0
 @Override
 public long add(IDaemonTask task) throws InvalidDaemonTask {
   if (task != null && task.getName() != null && !task.getName().isEmpty()) {
     synchronized (this.getWrappings()) {
       DaemonTaskWrapping wrapping = new DaemonTaskWrapping(task);
       wrapping.setId(Math.abs(UUID.randomUUID().getLeastSignificantBits()));
       this.getWrappings().add(wrapping);
       RuntimeLog.log(RuntimeLog.MSG_DAEMON_REGISTER_TASK, wrapping.getId(), wrapping.getName());
       return wrapping.getId();
     }
   } else {
     throw new InvalidDaemonTask();
   }
 }
示例#3
0
 @Override
 public boolean remove(long taskId) {
   if (taskId < 0) {
     return false;
   }
   synchronized (this.getWrappings()) {
     for (int i = this.getWrappings().size() - 1; i >= 0; i--) {
       DaemonTaskWrapping wrapping = this.getWrappings().get(i);
       if (wrapping == null) {
         continue;
       }
       if (wrapping.getId() == taskId) {
         this.getWrappings().remove(i);
       }
       RuntimeLog.log(RuntimeLog.MSG_DAEMON_REMOVE_TASK, wrapping.getId(), wrapping.getName());
     }
   }
   return false;
 }
示例#4
0
  @Override
  public void checkRun() {
    long time = System.currentTimeMillis();
    for (DaemonTaskWrapping wrapping : this.getWrappings()) {
      if (wrapping == null) {
        continue;
      }
      if (wrapping.isRunning()) {
        // 同时仅启动一个任务
        continue;
      }
      if (!wrapping.isActivated()) {
        continue;
      }
      boolean done = wrapping.tryRun(time);
      if (done) {
        // 可以运行
        RuntimeLog.log(
            MessageLevel.DEBUG,
            RuntimeLog.MSG_DAEMON_RUN_TASK,
            wrapping.getId(),
            wrapping.getName(),
            wrapping.getRunTimes());
        // 从线程池中调用新的线程运行此任务
        this.getThreadPool()
            .execute(
                new Runnable() {

                  @Override
                  public void run() {
                    wrapping.run();
                  }
                });
      }
    }
  }