public class ParallelAlarmSender
extends java.lang.Object
implements java.lang.Runnable
There is upper limit in the number of alarms sent each second in maxNumberOfAlarmsPerSecond
and implemented by a ArrayBlockingQueue bounded to maxNumberOfAlarmsPerSecond.
The alarms are sent by the thread that loops once per second (aprox) and empties the queue.
The ArrayBlockingQueue control the max number of alarms queued and ready
to be sent in the next second. However it does not prevent to add new alarms while
the thread is sending alarms (i.e. the thread gets a alarm out of the queue so
a new room is available and the send pushes a new alarm).
To be sure that the number of alarms sent each second is at most maxNumberOfAlarmsPerSecond,
the thread counts the number of alarms it get out of the queue at each iteration.
| Modifier and Type | Class and Description |
|---|---|
static class |
ParallelAlarmSender.AlarmToSend
An alarm to send.
|
| Constructor and Description |
|---|
ParallelAlarmSender(ContainerServices svcs,
int numOfSenders,
long timeBetweenAlarms)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(AlarmSentListener listener)
Add a listener
|
void |
close()
Close the sender and the threads
|
void |
removeListener(AlarmSentListener listener)
Remove a listener
|
void |
run() |
void |
send(SenderPanelUtils.Triplet triplet,
SenderPanelUtils.AlarmDescriptorType descriptor,
java.util.Properties props)
Send the specified alarm to on of the
AlarmSender to be sent to the service. |
void |
start()
Start the threads.
|
public ParallelAlarmSender(ContainerServices svcs, int numOfSenders, long timeBetweenAlarms) throws ACSASFactoryNotInitedEx, SourceCreationErrorEx
svcs - The ContainerServicesnumOfSenders - The number of AlarmSender to run in paralleltimeBetweenAlarms - The time between 2 send by each AlarmSenderSourceCreationErrorExACSASFactoryNotInitedExpublic void start()
public void close()
public void addListener(AlarmSentListener listener)
listener - The listener to notify when an alarm has been sentpublic void removeListener(AlarmSentListener listener)
listener - The listener to notify when an alarm has been sentpublic void send(SenderPanelUtils.Triplet triplet, SenderPanelUtils.AlarmDescriptorType descriptor, java.util.Properties props) throws java.lang.InterruptedException
AlarmSender to be sent to the service.
This method return immediately: each alarm is queued and sent later on by the thread.
If the queue of alarms contains more then , the caller waits until the thread frees the queue.
triplet - The triplet in the form FF,FM,FCThe - descriptorprops - The user propertiesjava.lang.InterruptedException - If interrupted while awaiting to put the alarm in the queueAlarmSender#send(alma.acs.alarm.gui.senderpanel.SenderPanelUtils.Triplet, alma.acs.alarm.gui.senderpanel.SenderPanelUtils.AlarmDescriptorType, java.util.Properties)public void run()
run in interface java.lang.Runnable