Package org.yamcs.alarms
Class AlarmServer<S,T>
- java.lang.Object
-
- com.google.common.util.concurrent.AbstractService
-
- org.yamcs.alarms.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.AbstractServiceMaintains 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
ParameterAlarmCheckerorEventAlarmServer.
-
-
Constructor Summary
Constructors Constructor Description AlarmServer(String yamcsInstance, ScheduledThreadPoolExecutor timer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ActiveAlarm<T>acknowledge(ActiveAlarm<T> alarm, String username, long ackTime, String message)Acknowledges an active alarm instance.Map<S,ActiveAlarm<T>>addAlarmListener(AlarmListener<T> listener)Register for alarm noticesActiveAlarm<T>clear(ActiveAlarm<T> alarm, String username, long clearTime, String message)Acknowledges an active alarm instance.voidclearAll()Removes all active alarms without acknowledgement !voiddoStart()voiddoStop()ActiveAlarm<T>getActiveAlarm(S subject)Returns the active alarm for the specified subject.ActiveAlarm<T>getActiveAlarm(S subject, int id)Returns the active alarm for the specified subject if it also matches the specified id.Map<S,ActiveAlarm<T>>getActiveAlarms()Returns the current set of active alarmsprotected static booleanmoreSevere(Object newValue, Object oldValue)protected static booleanmoreSevere(org.yamcs.protobuf.Pvalue.MonitoringResult mr1, org.yamcs.protobuf.Pvalue.MonitoringResult mr2)protected static booleanmoreSevere(org.yamcs.protobuf.Yamcs.Event.EventSeverity es1, org.yamcs.protobuf.Yamcs.Event.EventSeverity es2)voidremoveAlarmListener(AlarmListener<T> listener)ActiveAlarm<T>reset(ActiveAlarm<T> alarm, String username, long resetTime, String message)Reset a latched alarmActiveAlarm<T>shelve(ActiveAlarm<T> alarm, String username, String message, long shelveDuration)Shelve an alarmActiveAlarm<T>unshelve(ActiveAlarm<T> alarm, String username)Un-shelve an alarmvoidupdate(T pv, int minViolations)voidupdate(T value, int minViolations, boolean autoAck, boolean latching)
-
-
-
Constructor Detail
-
AlarmServer
public AlarmServer(String yamcsInstance, ScheduledThreadPoolExecutor timer)
-
-
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 acknowledgeusername- the acknowledging userackTime- the time associated with the acknowledgmentmessage- reason message. Leavenullwhen no reason is given.- Returns:
- the updated alarm instance or null if the alarm was not found
-
reset
public ActiveAlarm<T> reset(ActiveAlarm<T> alarm, String username, long resetTime, String message) throws CouldNotAcknowledgeAlarmException
Reset a latched alarm- Parameters:
alarm-username-resetTime-message-- Returns:
- the updated alarm instance or null if the alarm was not found
- Throws:
CouldNotAcknowledgeAlarmException
-
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 clearusername- the user that cleared the alarmmessage- reason message. Leavenullwhen 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:
doStartin classcom.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(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:
doStopin classcom.google.common.util.concurrent.AbstractService
-
clearAll
public void clearAll()
Removes all active alarms without acknowledgement !use only for unit tests!
-
-