JICSCore
Class MessageHandler

java.lang.Object
  extended by java.util.TimerTask
      extended by JICSCore.MessageHandler
All Implemented Interfaces:
java.lang.Runnable

public class MessageHandler
extends java.util.TimerTask

This class wraps up the syslog classes into a standard method of accessing the syslog which is applicable to the way that we use the syslog here at the ING.

The methods provided allow the user to enter messages into the syslog as INFO, ERROR and DEBUG messages. There is also the option to write a message into the syslog such that it will cause an alarm in the talker log. Additional methods exist which allow a blocking time in seconds to be specified for a specific message. If a caller subsequently attempts to insert the same message into the syslog within the block time, the MessageHandler class will not insert the new message into the syslog. An example of the initialisation sequence of the class follows

 
 import com.ice.syslog.*;
 import JICSCore.*;
 
 MessageHandler messageHandler = new MessageHandler();

 messageHandler.HostName = "localhost";
 messageHandler.ProcessName = "PFIPController";
 
 // Log the errors to stderr and include the PID in the messages 
 
 messageHandler.Facility = SyslogDefs.LOG_USER | SyslogDefs.LOG_PERROR | SyslogDefs.LOG_PID; 
 
 // Initialise the syslog classes and request that we include the date in the messages
 
 messageHandler.initialiseMessageHandler(true);
 
 // Enable debug output in the application 
        
 messageHandler.setDebugMode(true);
 
 // This will put an informational message into the syslog
 
 messageHandler.reportInfo("PFIP 4MS Controller Version Starting Up");
 
 // This will put a warning  message into the syslog
 
 messageHandler.reportError("This is a warning message");
 
 // This will put a debug message into the syslog, this will only be put into the syslog
 // if the debug is enabled
 
 messageHandler.reportDebug("This is debug message");
 
 // This will put an alarm message into the syslog
 
 messageHandler.reportAlarm("This is an alarm");
 
 

Version:
$Id$
Author:
Craige Bevil

Field Summary
private  java.util.Timer checkExpireMessageBlocksTimer
           
private  boolean DebugMode
          This indicates whether or not debug messages will be output The default is not to output debug messages, they must be enabled by the instantiator.
(package private)  boolean DisplayDate
          Indicates whether or not the date should be displayed in the output, by default the date is not included in the output to syslog.
private  boolean EngineeringMode
          This indicates whether or not engineering messages will be output The default is not to output engineering messages, they must be enabled by the instantiator.
 int Facility
          This is the default facility which will be used for reporting errors.
 java.lang.String HostName
          This is the name of the host upon which the syslog daemon that we want to connect resides.
private  java.util.HashMap<Severity,java.util.HashMap<java.lang.Integer,java.lang.Long>> MessageExpiryTimes
          Used to store the details of any message postponements.
 int Priority
          This is the default priority that will be used when reporting error.
 java.lang.String ProcessName
          This is the name of the process which will be associated with the message.
 
Constructor Summary
MessageHandler()
          Constructor
 
Method Summary
private  void addMessageBlock(Severity severity, java.lang.String message, int delayInSecs)
          Add a message postponement for a specific message
private  boolean checkForMessageBlock(Severity severity, java.lang.String message)
          Checks to see if a postponement has been specified for this message
 void initialiseMessageHandler(boolean DisplayDate)
          This should be called to initialise the message handler after the configuration of the class has been performed.
 void reportAlarm(java.lang.String Message)
          This method will used for reporting an error message into the syslog such that it will be reported as an alarm by the talker log.
 void reportAlarm(java.lang.String Message, int Blocktime)
          This method will used for reporting a ALARM message into the syslog.
 void reportDebug(java.lang.String Message)
          This method will used for reporting a debug message into the syslog if DebugMode has been enabled.
 void reportDebug(java.lang.String Message, int Blocktime)
          This method will used for reporting a debug message into the syslog if DebugMode has been enabled.
 void reportEngineering(java.lang.String Message)
          This method will used for reporting a debug message into the syslog if DebugMode has been enabled.
 void reportError(java.lang.String Message)
          This method will used for reporting an ERROR message into the syslog.
 void reportError(java.lang.String Message, int Blocktime)
          This method will used for reporting a ERROR message into the syslog.
 void reportInfo(java.lang.String Message)
          This method will used for reporting an INFO message into the syslog.
 void reportInfo(java.lang.String Message, int Blocktime)
          This method will used for reporting a INFO message into the syslog.
 void run()
          Every second we check for expiry of message postponements and remove them when expired.
private  void sendErrorToSyslog(int Level, java.lang.String Message)
          This method will used for reporting a message into the syslog.
 void setDebugMode(boolean EnableDebug)
          Enable or suppress the output of debug messages into the syslog.
 void setEngineeringMode(boolean EnableEngineering)
          Enable or suppress the output of engineering into the syslog.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

checkExpireMessageBlocksTimer

private java.util.Timer checkExpireMessageBlocksTimer

MessageExpiryTimes

private java.util.HashMap<Severity,java.util.HashMap<java.lang.Integer,java.lang.Long>> MessageExpiryTimes
Used to store the details of any message postponements. These are delays which are to be employed when throttling back the sending of the same message to the syslog continously, the caller can specify a delay before which time, the same message will not be sent to the syslog again


DebugMode

private boolean DebugMode
This indicates whether or not debug messages will be output The default is not to output debug messages, they must be enabled by the instantiator.


EngineeringMode

private boolean EngineeringMode
This indicates whether or not engineering messages will be output The default is not to output engineering messages, they must be enabled by the instantiator.


Facility

public int Facility
This is the default facility which will be used for reporting errors. This should be a logical OR of one or more of the constants that are described in the syslog package (SyslogDefs.LOG_USER, SyslogDefs.LOG_PID etc.)

The default facility is SyslogDefs.LOG_USER | SyslogDefs.LOG_PID


Priority

public int Priority
This is the default priority that will be used when reporting error. A logical OR of one or more priorities which are described in the Sysdef class. The default priority is SyslogDefs.LOG_INFO


HostName

public java.lang.String HostName
This is the name of the host upon which the syslog daemon that we want to connect resides. By default messages are sent to the syslog host running on the local machine


ProcessName

public java.lang.String ProcessName
This is the name of the process which will be associated with the message. By default this is set to Unknown


DisplayDate

boolean DisplayDate
Indicates whether or not the date should be displayed in the output, by default the date is not included in the output to syslog.

Constructor Detail

MessageHandler

public MessageHandler()
Constructor

Method Detail

run

public void run()
Every second we check for expiry of message postponements and remove them when expired.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask

initialiseMessageHandler

public void initialiseMessageHandler(boolean DisplayDate)
This should be called to initialise the message handler after the configuration of the class has been performed. e.g.
 
 messageHandler.HostName = "localhost";
 messageHandler.ProcessName = "PFIPController";
 
 // Log the errors to stderr and include the PID in the messages 
 
 messageHandler.Facility = SyslogDefs.LOG_USER | SyslogDefs.LOG_PERROR | SyslogDefs.LOG_PID; 
 
 // Initialise the syslog classes and request that we include the date in the messages
 
 messageHandler.initialiseMessageHandler(true);
      * 

Parameters:
DisplayDate - True if all messages included into the syslog will be prefixed with the current date and time

addMessageBlock

private void addMessageBlock(Severity severity,
                             java.lang.String message,
                             int delayInSecs)
Add a message postponement for a specific message

Parameters:
severity - The severity of the message
message - The message to be blocked
delayInSecs - The number of seconds the message should be blocked for

checkForMessageBlock

private boolean checkForMessageBlock(Severity severity,
                                     java.lang.String message)
Checks to see if a postponement has been specified for this message

Parameters:
severity - The severity of the message
message - The text of the message
Returns:
Boolean True if there is a postponement on this message

reportDebug

public void reportDebug(java.lang.String Message)
This method will used for reporting a debug message into the syslog if DebugMode has been enabled.

Parameters:
Message - The string representation of the message to be put into the log

reportError

public void reportError(java.lang.String Message,
                        int Blocktime)
This method will used for reporting a ERROR message into the syslog.

Parameters:
Message - The string representation of the message to be put into the log
Blocktime - The time to block subsequent identical messages to this from being entered into the syslog in seconds

reportInfo

public void reportInfo(java.lang.String Message,
                       int Blocktime)
This method will used for reporting a INFO message into the syslog.

Parameters:
Message - The string representation of the message to be put into the log
Blocktime - The time to block subsequent identical messages to this from being entered into the syslog in seconds

reportAlarm

public void reportAlarm(java.lang.String Message,
                        int Blocktime)
This method will used for reporting a ALARM message into the syslog.

Parameters:
Message - The string representation of the message to be put into the log
Blocktime - The time to block subsequent identical messages to this from being entered into the syslog in seconds

reportDebug

public void reportDebug(java.lang.String Message,
                        int Blocktime)
This method will used for reporting a debug message into the syslog if DebugMode has been enabled.

Parameters:
Message - The string representation of the message to be put into the log
Blocktime - The time to block subsequent identical messages to this from being entered into the syslog in seconds

reportEngineering

public void reportEngineering(java.lang.String Message)
This method will used for reporting a debug message into the syslog if DebugMode has been enabled.

Parameters:
Message - The string representation of the message to be put into the log

reportInfo

public void reportInfo(java.lang.String Message)
This method will used for reporting an INFO message into the syslog.

Parameters:
Message - The string representation of the message to be put into the log

reportError

public void reportError(java.lang.String Message)
This method will used for reporting an ERROR message into the syslog. In the talker log this message will be highlighted as yellow.

Parameters:
Message - The string representation of the message to be put into the log

reportAlarm

public void reportAlarm(java.lang.String Message)
This method will used for reporting an error message into the syslog such that it will be reported as an alarm by the talker log.

Parameters:
Message - The string representation of the message to be put into the log

sendErrorToSyslog

private void sendErrorToSyslog(int Level,
                               java.lang.String Message)
This method will used for reporting a message into the syslog. The other methods which are public to the outside world wrap up calls to this method.

Parameters:
Level - This is the priority level of the message when put into the syslog
Message - The string representation of the message to be put into the log

setDebugMode

public void setDebugMode(boolean EnableDebug)
Enable or suppress the output of debug messages into the syslog.

Parameters:
EnableDebug - - Set to true in order to indicate that debug should be output

setEngineeringMode

public void setEngineeringMode(boolean EnableEngineering)
Enable or suppress the output of engineering into the syslog.

Parameters:
EnableEngineering - - Set to true in order to indicate that engineering should be output