示例#1
0
 /** Add an automated action to the work queue and schedule it. */
 public void schedule(final AlarmHandler alarmHandler, boolean noDelay) {
   final Class<?> actionClass = alarmHandler.getScheduledAction().getClass();
   final OverflowManager overflowManager = getOverflowManager(actionClass);
   overflowManager.refreshOverflow();
   if (overflowManager.isOverflowed()) {
     boolean lockAcquired = false;
     try {
       if (getCleaned(actionClass) == false && getLock(actionClass).tryLock()) {
         lockAcquired = true;
         Activator.getLogger()
             .log(
                 Level.WARNING,
                 "Work queue OVERFLOWED, start cleaning: " + actionClass.getSimpleName() + " !");
         flushClass(alarmHandler.getScheduledAction().getClass());
         Activator.getLogger()
             .log(Level.WARNING, "Work queue CLEANED: " + actionClass.getSimpleName() + " !");
         setCleaned(actionClass, true);
       }
     } finally {
       if (lockAcquired) getLock(actionClass).unlock();
     }
   } else {
     setCleaned(actionClass, false);
   }
   if ((overflowManager.isOverflowed() && isAllowed(alarmHandler))
       || !overflowManager.isOverflowed()) {
     ActionID actionId = alarmHandler.getID();
     ScheduledActionTask newTask = new ScheduledActionTask(alarmHandler);
     // TODO: action already scheduled ? => remove
     if (scheduledActions.get(actionId) != null) { // replace
       ScheduledActionTask oldTask = scheduledActions.get(actionId);
       oldTask.cancel();
       scheduledActions.put(actionId, newTask);
     } else {
       scheduledActions.put(actionId, newTask);
       incrementPendingActions();
     }
     int delay = noDelay ? 0 : (alarmHandler.getDelay() * 1000);
     timer.schedule(newTask, delay);
     Activator.getLogger()
         .log(
             Level.INFO,
             "SUBMISSION "
                 + alarmHandler.getInfos()
                 + " scheduled in "
                 + (delay / 1000)
                 + " seconds on "
                 + alarmHandler.getItem().getName());
   }
 }
示例#2
0
 /** Execute an automated action. */
 public void execute(final AlarmHandler alarmHandler) {
   new ExecuteActionThread(
           alarmHandler.getScheduledAction(),
           alarmHandler.getInfos(),
           alarmHandler.getCurrentSnapshots())
       .start();
   if (debug) AlarmNotifierHistory.getInstance().addAction(alarmHandler);
 }