com.solab.alarms.channels
Class HttpChannel

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

public class HttpChannel
extends AbstractAlarmChannel

This channel can send an alarm over an HTTP GET or POST request. It does not wait for a response unless specified to do so.

Author:
Enrique Zamudio

Field Summary
 
Fields inherited from class com.solab.alarms.AbstractAlarmChannel
log
 
Constructor Summary
HttpChannel()
           
 
Method Summary
protected  Runnable createSendTask(String msg, String source)
          Subclasses need to create and return a new Runnable in each call to this method.
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 cached URL if the URL value has no alarm or source variables, and validates that there is postData if the URL is going to be cached.
 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 setExpectedResponse(String value)
          If this property is set, the channel waits for a response and scans it for this particular string, warning if not found.
 void setPostData(String value)
          Sets the POST data for the HTTP request.
 void setUrl(String value)
          Sets the URL to send the alarm to.
 
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

HttpChannel

public HttpChannel()
Method Detail

setExpectedResponse

public void setExpectedResponse(String value)
If this property is set, the channel waits for a response and scans it for this particular string, warning if not found.


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.


setUrl

public void setUrl(String value)
            throws MalformedURLException
Sets the URL to send the alarm to. It can contain "${alarm}" and "${source}", in which case they will be replaced by the alarm message and the specified source, when an actual alarm is sent.

Throws:
MalformedURLException

setPostData

public void setPostData(String value)
Sets the POST data for the HTTP request. If set, this means the HTTP POST method will be used; by default, HTTP GET is used. The POST string can contain "${alarm}" and "${source}", which will be replaced with the alarm message and specified source, when an actual alarm is sent.


createSendTask

protected Runnable createSendTask(String msg,
                                  String source)
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.
source - 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

init

@PostConstruct
public void init()
          throws MalformedURLException
Initializes the cached URL if the URL value has no alarm or source variables, and validates that there is postData if the URL is going to be cached.

Throws:
MalformedURLException - if the url is fixed (no ${alarm} or ${source}) and it cannot be converted to a valid URL.


Copyright © 2011 Java Mexico. All Rights Reserved.