com.solab.alarms
Class AbstractAlarmChannel

java.lang.Object
  extended by com.solab.alarms.AbstractAlarmChannel
All Implemented Interfaces:
AlarmChannel
Direct Known Subclasses:
CommandLineChannel, HttpChannel, TestChannel, TwitterChannel

public abstract class AbstractAlarmChannel
extends Object
implements AlarmChannel

An abstract implementation of AlarmChannel, to ease the creation of custom channels. Defines a minResendInterval of 60 seconds. Subclasses only need to implement the createSendTask(String) method, returning a new Runnable in every call; this Runnable will be queued in a thread pool to be executed as soon as possible, but without interrupting normal program flow. This class already handles what is needed to avoid sending repeated messages very often.

Author:
Enrique Zamudio

Field Summary
protected  Logger log
           
 
Constructor Summary
AbstractAlarmChannel()
           
 
Method Summary
protected abstract  Runnable createSendTask(String msg, String source)
          Subclasses need to create and return a new Runnable in each call to this method.
 int getMinResendInterval()
          Returns the minimum amount of time that must elapse before a previously sent alarm message can be sent again.
protected abstract  boolean hasSource(String alarmSource)
          This method is used to determine if a certain alarm channel has a special condition for the specified alarmSource or not.
 void send(String msg, String source)
          Sends an alarm message for the specified source.
 void setMinResendInterval(int millis)
          Sets the minimum amount of time between equal messsages.
 void shutdown()
          Shuts down the thread pool and rejects any more incoming alarms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final Logger log
Constructor Detail

AbstractAlarmChannel

public AbstractAlarmChannel()
Method Detail

setMinResendInterval

public void setMinResendInterval(int millis)
Sets the minimum amount of time between equal messsages. The same message will not be sent through the channel if it was last sent before this interval has elapsed, unless AlarmSender.sendAlways() is used.


getMinResendInterval

public int getMinResendInterval()
Returns the minimum amount of time that must elapse before a previously sent alarm message can be sent again. The interval is in milliseconds.

Specified by:
getMinResendInterval in interface AlarmChannel

send

public void send(String msg,
                 String source)
Sends an alarm message for the specified source. If the concrete subclass returns null from the createSendTask(String, String) method, no alarm is sent, and no record is made of the message's last time being sent.

Specified by:
send in interface AlarmChannel
Parameters:
msg - The alarm message to be sent.
source - The alarm source. A channel can send the alarm to different recipients depending on the source. This parameter can be null, which means that it should be sent to the default recipients for the channel.

shutdown

public void shutdown()
Shuts down the thread pool and rejects any more incoming alarms.

Specified by:
shutdown in interface AlarmChannel

createSendTask

protected abstract Runnable createSendTask(String msg,
                                           String source)
Subclasses need to create and return a new Runnable in each call to this method. The returned Runnable will be queued in a thread pool to avoid latency in the normal program flow. If a subclass decides not to send the alarm message for some reason, it can return null so that nothing is queued.

Parameters:
msg - The message to be sent.
source - The alarm source. A channel can have different recipient lists depending on the alarm source.

hasSource

protected abstract boolean hasSource(String alarmSource)
This method is used to determine if a certain alarm channel has a special condition for the specified alarmSource or not. It's used to determine if the alarm messages should be saved as regular alarms or as messages for that specific source.



Copyright © 2011 Java Mexico. All Rights Reserved.