Ejemplo n.º 1
0
 /** Interrupt an automated action. */
 public void interrupt(final AlarmHandler alarmHandler) {
   ScheduledActionTask task = scheduledActions.get(alarmHandler.getID());
   if (task != null) {
     task.cancel();
     remove(task.getAlarmHandler());
   }
 }
Ejemplo n.º 2
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());
   }
 }
Ejemplo n.º 3
0
 // Remove an automated action from the list
 private void remove(final AlarmHandler alarmHandler) {
   if (scheduledActions.remove(alarmHandler.getID()) != null) decrementPendingActions();
 }