org.echarts.monitor
Class MachineMonitorEvent

java.lang.Object
  extended by org.echarts.monitor.MachineMonitorEvent
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
EChartsSipServletExceptionEvent, ExternalInputEvent, FeatureBoxCreatedEvent, FeatureBoxDestroyedEvent, LogLevelMonitorEvent, MachineDebugEvent, RegressionTestFailureEvent, SipMessageEvent, SipPortBindEvent

public abstract class MachineMonitorEvent
extends java.lang.Object
implements java.io.Externalizable

Abstract superclass representing events to put into a Monitor. An event is timestamped and host-IP-stamped when it is created. In addition, an event maintains a property list with an arbitrary list of String key/value pairs. Property values may include line separators, tab characters etc. Supports efficient (remote) serialization via readRaw and writeRaw, and readExternal and writeExternal methods. Subclasses should include a zero argument constructor if readRaw or readExternal will be used.

See Also:
Serialized Form

Field Summary
 java.lang.String hostIpAddress
          Holds the IP Address of the host on which this JVM is running.
 java.util.Properties properties
          Properties associated with the event.
 long timestamp
          All events are timestamped to indicate their creation times.
 
Constructor Summary
MachineMonitorEvent()
           
 
Method Summary
 java.lang.String getClassString()
          Strip package name from class name.
 java.lang.String getHostAddress()
           
 java.lang.String getPropertiesString()
           
 java.lang.String[] getSortedKeys()
          Acquires the keys from the properties object and returns them in a sorted array.
 void readExternal(java.io.ObjectInput in)
           
static MachineMonitorEvent readRaw(java.io.DataInput in, byte[] inputBuffer)
           
 java.lang.String replaceChar(java.lang.String source, char target, java.lang.String substitute)
          Replaces all occurrences of a single character in a string with a substitute sub-string.
 java.lang.String toString()
          Separate fields with tabs.
 void writeExternal(java.io.ObjectOutput out)
           
 void writeRaw(java.io.DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hostIpAddress

public java.lang.String hostIpAddress
Holds the IP Address of the host on which this JVM is running.


properties

public java.util.Properties properties
Properties associated with the event.


timestamp

public long timestamp
All events are timestamped to indicate their creation times.

Constructor Detail

MachineMonitorEvent

public MachineMonitorEvent()
Method Detail

getHostAddress

public final java.lang.String getHostAddress()
Returns:
The IP Address of the host on which this event was generated.

getSortedKeys

public java.lang.String[] getSortedKeys()
Acquires the keys from the properties object and returns them in a sorted array. To the extent that a given event always has the same set of property keys, this function will always return them in the same sort order. The sorting order is that determined by the String implementation of the Comparable interface.

Returns:
array of sorted property keys. The array will be empty if there are no keys.

writeRaw

public void writeRaw(java.io.DataOutput out)
              throws java.io.IOException
Throws:
java.io.IOException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readRaw

public static MachineMonitorEvent readRaw(java.io.DataInput in,
                                          byte[] inputBuffer)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException

toString

public java.lang.String toString()
Separate fields with tabs. Trim event class name to exclude event class package. Every event is logged as a single record in the event log. The log entries have the following structure:

  formattedTimestamp "\t" timestamp "\t" IPaddressOfEventCreatorHost "\t" eventClassName "\t" propName1={value1} "\t" propName2={value2} "\t" ...
  

Property values are formatted by replacing the certain characters with substrings as follows:


  --------------------------
  Character     Substitution
  --------------------------
  '\n'            
  '\r'            
  '\t'            
  '{'             
  '}'             
  --------------------------

  

Newlines (or '\r\n' pairs) must be replaced because the log entry must be contained within a single record in the file. Tabs are field separators, hence, embedded tab characters must be substituted. Curly braces are used to denote the start and end of a property value, and therefore they must be substituted if they should occur with a property value.

Most property values will not need any reformatting, and for those that do, it will be most likely just '\n' or '\r\n'.

Should the IP Address of the host that created the event not be available, then the placeholder string, "<host unknown>" will appear instead.

Overrides:
toString in class java.lang.Object

getPropertiesString

public java.lang.String getPropertiesString()

replaceChar

public java.lang.String replaceChar(java.lang.String source,
                                    char target,
                                    java.lang.String substitute)
Replaces all occurrences of a single character in a string with a substitute sub-string.

Parameters:
source - The string on which the substitutions are to be made.
target - The character to be substituted.
substitute - The string to replace all instances of target.
Returns:
The source with the indicated substitutions.

getClassString

public java.lang.String getClassString()
Strip package name from class name.