Class AlarmServer<S,​T>

  • All Implemented Interfaces:
    com.google.common.util.concurrent.Service
    Direct Known Subclasses:
    EventAlarmServer

    public class AlarmServer<S,​T>
    extends com.google.common.util.concurrent.AbstractService
    Maintains a list of active alarms.

    (S,T) can be one of: (Parameter,ParamerValue) or (EventId, Event)

    This class implements functionality common for parameter alarms and event alarms.

    Specific functionality for each alarm type (e.g. disabling alarms) should be implemented in the respective ParameterAlarmChecker or EventAlarmServer.

    • Method Detail

      • addAlarmListener

        public Map<S,​ActiveAlarm<T>> addAlarmListener​(AlarmListener<T> listener)
        Register for alarm notices
        Returns:
        the current set of active alarms
      • removeAlarmListener

        public void removeAlarmListener​(AlarmListener<T> listener)
      • getActiveAlarms

        public Map<S,​ActiveAlarm<T>> getActiveAlarms()
        Returns the current set of active alarms
      • getActiveAlarm

        public ActiveAlarm<T> getActiveAlarm​(S subject,
                                             int id)
                                      throws AlarmSequenceException
        Returns the active alarm for the specified subject if it also matches the specified id.
        Parameters:
        subject - the subject to look for.
        id - the expected id of the active alarm.
        Returns:
        the active alarm, or null if no alarm was found
        Throws:
        AlarmSequenceException - when the specified id does not match the id of the active alarm
      • getActiveAlarm

        public ActiveAlarm<T> getActiveAlarm​(S subject)
        Returns the active alarm for the specified subject.
        Parameters:
        subject - the subject to look for.
        Returns:
        the active alarm, or null if no alarm was found
      • acknowledge

        public ActiveAlarm<T> acknowledge​(ActiveAlarm<T> alarm,
                                          String username,
                                          long ackTime,
                                          String message)
        Acknowledges an active alarm instance. If the alarm state is no longer applicable, the alarm is also cleared, otherwise the alarm will remain active.
        Parameters:
        alarm - the alarm to acknowledge
        username - the acknowledging user
        ackTime - the time associated with the acknowledgment
        message - reason message. Leave null when no reason is given.
        Returns:
        the updated alarm instance or null if the alarm was not found
      • clear

        public ActiveAlarm<T> clear​(ActiveAlarm<T> alarm,
                                    String username,
                                    long clearTime,
                                    String message)
        Acknowledges an active alarm instance. If the alarm state is no longer applicable, the alarm is also cleared, otherwise the alarm will remain active.
        Parameters:
        alarm - the alarm to clear
        username - the user that cleared the alarm
        message - reason message. Leave null when no reason is given.
        Returns:
        the updated alarm instance or null if the alarm was not found
      • shelve

        public ActiveAlarm<T> shelve​(ActiveAlarm<T> alarm,
                                     String username,
                                     String message,
                                     long shelveDuration)
        Shelve an alarm
        Parameters:
        alarm -
        username -
        message -
        shelveDuration - shelve duration in milliseconds
        Returns:
        the updated alarm instance or null if the alarm was not found
      • unshelve

        public ActiveAlarm<T> unshelve​(ActiveAlarm<T> alarm,
                                       String username)
        Un-shelve an alarm
        Parameters:
        alarm -
        username -
        Returns:
        the updated alarm instance or null if the alarm was not found
      • doStart

        public void doStart()
        Specified by:
        doStart in class com.google.common.util.concurrent.AbstractService
      • update

        public void update​(T pv,
                           int minViolations)
      • update

        public void update​(T value,
                           int minViolations,
                           boolean autoAck,
                           boolean latching)
      • moreSevere

        protected static boolean moreSevere​(Object newValue,
                                            Object oldValue)
      • moreSevere

        protected static boolean moreSevere​(org.yamcs.protobuf.Pvalue.MonitoringResult mr1,
                                            org.yamcs.protobuf.Pvalue.MonitoringResult mr2)
      • moreSevere

        protected static boolean moreSevere​(org.yamcs.protobuf.Yamcs.Event.EventSeverity es1,
                                            org.yamcs.protobuf.Yamcs.Event.EventSeverity es2)
      • doStop

        public void doStop()
        Specified by:
        doStop in class com.google.common.util.concurrent.AbstractService
      • clearAll

        public void clearAll()
        Removes all active alarms without acknowledgement !use only for unit tests!