public class AlarmsMap
extends java.lang.Object
Alarms that are not updated after ALARM_ACTIVITY_TIME are removed
from the map so that they will be sent again to the alarm service.
The class is thread safe i.e. the methods can be called without any further locking.
Implementation note:
All the methods add new entries or update existing pairs in the alarms
map with the exception of the periodic thread AlarmsMap.AlarmsMapRunnable.run()
that remove elements that are in the map unchanged since more the ALARM_ACTIVITY_TIME.
AlarmsMap does not need any locking because the map contains immutable
AlarmsMap.AlarmInfo objects and the map itself is implemented by a ConcurrentHashMap.
| Modifier and Type | Class and Description |
|---|---|
static class |
AlarmsMap.AlarmInfo
The data stored for each alarm in the map.
|
class |
AlarmsMap.AlarmsMapRunnable
The thread to delete the alarms older than the time interval.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
ALARM_ACTIVITY_TIME
The alarms that have no activity after the following time interval
are removed from the map.
|
| Constructor and Description |
|---|
AlarmsMap(java.util.concurrent.ThreadFactory threadFactory,
java.util.logging.Logger logger)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
clear(java.lang.String alarmID)
An alarm has been cleared and must be added to the map.
|
boolean |
containsKey(java.lang.Object key) |
AlarmsMap.AlarmInfo |
get(java.lang.Object key) |
java.util.Collection<java.lang.String> |
getActiveAlarms()
Return the active alarms in the map
|
java.util.Set<java.lang.String> |
keySet()
This method returns a set of the keys in the map at the moment when the
method has been called.
|
boolean |
raise(java.lang.String alarmID)
An alarms has been raised and must be added to the map.
|
void |
shutdown()
Shutdown the thread a frees the resources
|
int |
size()
The size of the map
|
void |
start()
Start the thread to delete the oldest alarms
|
public static final int ALARM_ACTIVITY_TIME
In practice, it means that an alarm with the same state will be sent again
if it arrives after ALARM_ACTIVITY_TIME seconds.
public AlarmsMap(java.util.concurrent.ThreadFactory threadFactory,
java.util.logging.Logger logger)
threadFactory - The thread factory to schedule the timer looplogger - The loggerpublic java.util.Collection<java.lang.String> getActiveAlarms()
public boolean raise(java.lang.String alarmID)
alarmID - The ID of the alarmtrue if the alarm with the give ID was already present
in the list and it was active; false otherwise.public boolean clear(java.lang.String alarmID)
alarmID - The ID of the alarmtrue if the alarm with the give ID was already present
in the list and it was terminated; false otherwise.public void start()
public void shutdown()
public int size()
ConcurrentHashMap.size()public boolean containsKey(java.lang.Object key)
key - The key to look for in the maptrue if the map contains an item with the given ketpublic AlarmsMap.AlarmInfo get(java.lang.Object key)
key - The key to look forpublic java.util.Set<java.lang.String> keySet()
null values
if ssuch a value has been removed by the thread.