Example #1
0
 private void flushClass(final Class<?> actionClass) {
   Map<ActionID, ScheduledActionTask> scheduledActionsToFlush = null;
   synchronized (scheduledActions) {
     scheduledActionsToFlush = new ConcurrentHashMap<ActionID, ScheduledActionTask>();
     Iterator<Entry<ActionID, ScheduledActionTask>> it = scheduledActions.entrySet().iterator();
     while (it.hasNext()) {
       final Entry<ActionID, ScheduledActionTask> entry = it.next();
       if (entry
           .getValue()
           .getAlarmHandler()
           .getScheduledAction()
           .getClass()
           .equals(actionClass)) {
         scheduledActionsToFlush.put(entry.getKey(), entry.getValue());
         it.remove();
       }
     }
     this.count_pending -= scheduledActionsToFlush.size();
   }
   for (ScheduledActionTask task : scheduledActionsToFlush.values()) {
     task.cancel();
     AlarmHandler alarmHandler = task.getAlarmHandler();
     if (isAllowed(alarmHandler)) {
       alarmHandler.setStatus(EActionStatus.FORCED);
       execute(alarmHandler);
     }
   }
 }
Example #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);
 }
 private void reinitializeAlarms(Context context) {
   try {
     for (Timer timer : DatabaseHandler.getAllTimers(true)) {
       AlarmHandler.cancelAlarm(context, timer);
       AlarmHandler.createAlarm(context, timer);
     }
   } catch (Exception e) {
     StatusMessageHandler.showErrorMessage(context, e);
   }
 }
Example #4
0
 @Override
 public boolean cancel() {
   String reason =
       alarmHandler.getReason().isEmpty()
           ? "the timer has been canceled"
           : alarmHandler.getReason();
   Activator.getLogger()
       .log(Level.INFO, "CANCEL " + alarmHandler.getInfos() + " because " + reason);
   alarmHandler.setStatus(EActionStatus.CANCELED);
   return super.cancel();
 }
Example #5
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());
   }
 }
Example #6
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());
   }
 }
Example #7
0
 @Override
 public void run() {
   if (alarmHandler.getStatus().equals(EActionStatus.PENDING)
       || alarmHandler.getStatus().equals(EActionStatus.FORCED)) {
     if (alarmHandler.getStatus().equals(EActionStatus.PENDING))
       alarmHandler.setStatus(EActionStatus.EXECUTED);
     execute(alarmHandler);
   } else {
     if (debug) AlarmNotifierHistory.getInstance().addAction(alarmHandler);
     Activator.getLogger()
         .log(
             Level.INFO,
             "CANCEL " + alarmHandler.getInfos() + " because " + alarmHandler.getReason());
   }
   remove(this.alarmHandler);
 }
Example #8
0
 // If overflow => schedule only Systems actions or PV with a severity
 // level higher or equal to the one defined as preference.
 private boolean isAllowed(final AlarmHandler alarmHandler) {
   if (!alarmHandler.getItem().isPV()
       || (alarmHandler.getItem().isPV()
           && alarmHandler.getPriority().compareTo(overflow_level) >= 0)) return true;
   return false;
 }
Example #9
0
 // Remove an automated action from the list
 private void remove(final AlarmHandler alarmHandler) {
   if (scheduledActions.remove(alarmHandler.getID()) != null) decrementPendingActions();
 }