com.solab.alarms.channels
Class CommandLineChannel

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

public class CommandLineChannel
extends AbstractAlarmChannel

This alarm channel executes a command-line program, either passing the alarm message as a parameter to it as an argument of ${alarm}, or feeding the alarm message to its STDIN.

Author:
Enrique Zamudio

Field Summary
 
Fields inherited from class com.solab.alarms.AbstractAlarmChannel
log
 
Constructor Summary
CommandLineChannel()
           
 
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 setCommand(String value)
          Sets the command to execute, as a single statement to be execute.
 void setCommandsBySource(Map<String,String> value)
          Sets a map with different commands to be executed depending on the alarm source.
 void setCommandsWithArgsBySource(Map<String,String[]> value)
          Sets a map with different commands to be executed depending on the alarm source.
 void setCommandWithArgs(List<String> value)
          Sets the command to execute, with each argument as a separate element.
 
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

CommandLineChannel

public CommandLineChannel()
Method Detail

setCommand

public void setCommand(String value)
Sets the command to execute, as a single statement to be execute. The alarm message is simply appended as an argument.


setCommandWithArgs

public void setCommandWithArgs(List<String> value)
Sets the command to execute, with each argument as a separate element. One of the elements can be a ${alarm} variable which will be replaced with the alarm message; if the first elements starts with "STDIN:" then that prefix is removed and the alarm message is fed to the program's STDIN.


setCommandsWithArgsBySource

public void setCommandsWithArgsBySource(Map<String,String[]> value)
Sets a map with different commands to be executed depending on the alarm source. Each value must be a list of strings, the first being the command to execute and the others the arguments.


setCommandsBySource

public void setCommandsBySource(Map<String,String> value)
Sets a map with different commands to be executed depending on the alarm source. Each value will be interpreted as a single command and when executed, the alarm message will be passed as a single argument.


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


Copyright © 2011 Java Mexico. All Rights Reserved.