com.solab.alarms.channels.twitter
Class TwitterChannel

java.lang.Object
  extended by com.solab.alarms.AbstractAlarmChannel
      extended by com.solab.alarms.channels.twitter.TwitterChannel
All Implemented Interfaces:
AlarmChannel

public class TwitterChannel
extends AbstractAlarmChannel

A channel that uses Twitter to publish alarms. The way this works is like this: You set up a Twitter account for your application, and follow it from your own account. You must run the TwitterAuth class in this app to generate a Token associating the jAlarms app with the account you'll use for the app (you only need to do this once). Then you set the PIN you get in the twitterPin property of this component and you're ready to go; any alarms published here will be posted as the status of the account you set up for the app, and since you're following it, you'll know when something bad happens. Twitter ignores repeated status updates, which is kinda necessary here... so this channel prepends the time to the alarm messages, which solves the problem for at least a day (but it seems like Twitter allows repeated status updates after a day, so it's OK). The time is displayed as HHmmss, using no separators to save space. Alarm messages longer than 133 chars will be split into several status messages. Since this channel only updates the status of a Twitter account, alarm sources are ignored.

Author:
Enrique Zamudio

Field Summary
 
Fields inherited from class com.solab.alarms.AbstractAlarmChannel
log
 
Constructor Summary
TwitterChannel()
           
 
Method Summary
protected  Runnable createSendTask(String msg, String src)
          Subclasses need to create and return a new Runnable in each call to this method.
 String getApiUrl()
           
protected  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 init()
          Initializes the component.
 void setAccessToken(String value)
          Sets the access token obtained with the TwitterAuth program; this allows jAlarms to post status updates to the twitter account set up for the alarms.
 void setAlarmSource(Set<String> value)
          You can set a list of sources in this property so that only alarm messages matching any of the sources are be posted as status updates.
 void setApiUrl(String value)
          Sets the Twitter API URL to update the user's status.
 void setPrefix(String value)
          This is an optional property; you can set a prefix to be used in all the status updates; this is useful in cases where you need to use the same Twitter account for more than one application, so you can tell which one sent the alarm.
 void setTokenSecret(String value)
          Sets the token secret obtained with the TwitterAuth program; this allows jAlarms to post status updates to the twitter account set up for the alarms.
 
Methods inherited from class com.solab.alarms.AbstractAlarmChannel
getMinResendInterval, send, setMinResendInterval, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwitterChannel

public TwitterChannel()
Method Detail

setApiUrl

public void setApiUrl(String value)
               throws MalformedURLException
Sets the Twitter API URL to update the user's status. The default value is http://api.twitter.com/1/statues/update.xml

Throws:
MalformedURLException

getApiUrl

public String getApiUrl()

setPrefix

public void setPrefix(String value)
This is an optional property; you can set a prefix to be used in all the status updates; this is useful in cases where you need to use the same Twitter account for more than one application, so you can tell which one sent the alarm. If you set a value here, remember to use a short string; it will be placed at the beginning of the status update (after the time), in square brackets.


setAlarmSource

public void setAlarmSource(Set<String> value)
You can set a list of sources in this property so that only alarm messages matching any of the sources are be posted as status updates. If you don't set a value here, all alarm messages are posted, with the usual rules about min time interval. This is useful if you want to use a Twitter account to only post alarm messages from certain sources.


setAccessToken

public void setAccessToken(String value)
Sets the access token obtained with the TwitterAuth program; this allows jAlarms to post status updates to the twitter account set up for the alarms.


setTokenSecret

public void setTokenSecret(String value)
Sets the token secret obtained with the TwitterAuth program; this allows jAlarms to post status updates to the twitter account set up for the alarms.


init

@PostConstruct
public void init()
          throws NoSuchAlgorithmException,
                 MalformedURLException
Initializes the component. Internally it creates a Mac instance with the HmacSHA1 algorithm. If you configure this component with Spring, this method can be called automatically.

Throws:
NoSuchAlgorithmException - if the HmacSHA1 algorithm is not available.
MalformedURLException

createSendTask

protected Runnable createSendTask(String msg,
                                  String src)
Description copied from class: AbstractAlarmChannel
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.

Specified by:
createSendTask in class AbstractAlarmChannel
Parameters:
msg - The message to be sent.
src - The alarm source. A channel can have different recipient lists depending on the alarm source.

hasSource

protected boolean hasSource(String alarmSource)
Description copied from class: AbstractAlarmChannel
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.

Specified by:
hasSource in class AbstractAlarmChannel


Copyright © 2011 Java Mexico. All Rights Reserved.