- All Implemented Interfaces:
MessageAlarm
,Listener
,Transceiver
,Receiver
,Transmitter
,NamedObject
- Direct Known Subclasses:
EmailMessageAlarm
Installing a Message Alarm
A MessageAlarm
is a Listener
which can listen to messages from any Broadcaster
or Repeater
when installed with Listener.listenTo(Broadcaster)
. For example:
public void onRun() { // Send alarm email if this application exceeds 10 errors per minute new EmailAlarm(...).listenTo(this); }
The installed alarm will be triggered when the error rate()
exceeds triggerRate()
, which defaults
to 10 errors per minute. This default value can be overridden with triggerRate(Rate)
. The maximum alarm
trigger frequency defaults to once every 30 minutes. This value can be overridden with maximumTriggerFrequency(Frequency)
.
Implementing an Alarm
To implement an alarm, override onTrigger(Rate)
and implement the alarm action. By default, the alarm will
be triggered when shouldTrigger()
returns true. By default, shouldTrigger()
returns true if the
current error rate()
exceeds triggerRate()
. The current error rate()
is computed with a
RateCalculator
that automatically resets once a minute. Messages are categorized as errors (or not) by isError(Message)
, which returns true if the message status is worse-than-or-equal-to Problem
by default.
- Author:
- jonathanl (shibo)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Returns true if the given message should count towards setting off this alarmmaximumTriggerFrequency
(Frequency maximumTriggerFrequency) Sets the maximum frequency at which this alarm can be triggeredfinal void
Functional interface method called when a message is received by this listenerprotected abstract void
Alarm action implementationprotected Rate
rate()
boolean
Called to determine if this alarm should be triggeredfinal void
Executes the action for this message alarm.triggerRate
(Rate triggerRate) Sets the error rate above which this alarm will be triggeredMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.telenav.kivakit.core.messaging.Listener
isDeaf, listenTo, listenTo, onReceive
Methods inherited from interface com.telenav.kivakit.interfaces.naming.NamedObject
hasSyntheticName, objectName, objectName
Methods inherited from interface com.telenav.kivakit.interfaces.messaging.Receiver
isReceiving, receive
Methods inherited from interface com.telenav.kivakit.core.messaging.Transceiver
announce, debug, debugClassContext, debugCodeContext, debugCodeContext, fatal, fatal, glitch, glitch, glitch, glitch, halted, halted, ifDebug, illegalArgument, illegalState, illegalState, information, isDebugOn, narrate, problem, problem, problem, problem, problemIfNull, quibble, quibble, quibble, quibble, trace, trace, trace, trace, warning, warning, warning, warning
Methods inherited from interface com.telenav.kivakit.interfaces.messaging.Transmitter
isTransmitting, onTransmit, transmit, withoutTransmitting
-
Constructor Details
-
BaseMessageAlarm
public BaseMessageAlarm()
-
-
Method Details
-
shouldTrigger
public boolean shouldTrigger()Called to determine if this alarm should be triggered- Specified by:
shouldTrigger
in interfaceMessageAlarm
- Returns:
- True if this alarm should be triggered
-
triggerRate
- Returns:
- The rate above which this alarm will be triggered
-
rate
- Returns:
- The current rate of error messages