org.ow2.jasmine.monitoring.mbeancmd
Class Outer

java.lang.Object
  extended by org.ow2.jasmine.monitoring.mbeancmd.Outer
All Implemented Interfaces:
java.lang.Runnable

public class Outer
extends java.lang.Object
implements java.lang.Runnable

A pipe consists of a pair of channels: a writable channel (called "sink", where information is written to) and a readable channel (called "source", where information is obtained from). The general idea is that once some bytes are available on the source: 1. The pipe reads those bytes. 2. If required, does some action with some or all of these bytes (for example, write them to a file). 3. If a sink is present, writes the exact same bytes in the exact same order on the sink. An Outer instance can retrieve information from (=use as source) a PrintStream or a File and outputs information to (=uses as sink) a PipedOutputStream. The main difference between an Outer and an Iner is that an Outer can also filter out (@see Outer.setRegexp and Outer.setTimeFilter) information and output it on a target. Note that the sink still keeps on receiving unmodified data from the source.


Field Summary
private  boolean closeTarget
          Whether target needs to be closed.
private  int[] colIndexes
          Column indexes is message.
private static java.lang.String COLSEP
          Default column separator.
private  java.lang.String[] columns
          Message columns (data).
private  long fromTime
          Time from which to start outputting data.
private  java.lang.String[] heading
          Message headers.
private  java.lang.String id
          Outer id.
private  boolean isFilter
          Whether regular expression filtering is enabled.
private  boolean isFormat
          Whether format reading is enabled.
private  boolean isTimeFilter
          Whether time filtering is enabled.
private  java.lang.String regexp
          Regular expression used as filter.
private  java.io.LineNumberReader rsource
          Reader for the source.
private static java.lang.String separator
          Current column separator.
private static java.text.SimpleDateFormat simpleDateFormat
          Used for setting the Outer.fromTime and Outer.toTime parameters.
private  java.io.PipedOutputStream sink
          Sink.
private  java.io.PipedInputStream source
          Source.
private  java.io.PrintWriter target
          Target writer.
private  java.lang.String timeField
          Default column name for the time.
private  java.text.SimpleDateFormat timeFormat
          Time format.
private  int timeIx
          Time filter column index.
private  long toTime
          Time at which to stop outputting data.
private  java.io.PrintWriter wsink
          Writer on the sink.
 
Constructor Summary
Outer(java.io.PipedOutputStream src, java.io.File file)
          Creates an Outer using a PipedOutputStream as source and a File as output.
Outer(java.io.PipedOutputStream src, java.io.PrintStream target)
          Creates an Outer using a PipedOutputStream as source and a PrintStream as output.
 
Method Summary
private  boolean buildIndex()
          Builds the index.
 java.lang.String getId()
           
static java.lang.String getSeparator()
           
 java.io.PipedOutputStream getSink()
           
static void main(java.lang.String[] args)
          Tests the Outer implementation.
private  boolean matches(java.lang.String ln)
           
 void resetTimeFilter()
          Resets the time filter.
 void run()
          Starts the activity on the Outer (as described in the class header).
 void setFormatter(java.lang.String[] columns)
           
private  void setHeading(java.lang.String h)
           
 void setId(java.lang.String id)
           
 void setRegexp(java.lang.String exp)
           
static void setSeparator(java.lang.String s)
           
 void setSink(java.io.PipedOutputStream sink)
           
 void setTimeFilter(java.lang.String field, java.lang.String fieldFormat, java.lang.String from, java.lang.String to)
           
private  boolean timeMatches(java.lang.String ln)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

private java.io.PipedInputStream source
Source.


rsource

private java.io.LineNumberReader rsource
Reader for the source.


sink

private java.io.PipedOutputStream sink
Sink.


wsink

private java.io.PrintWriter wsink
Writer on the sink.


target

private java.io.PrintWriter target
Target writer.


isFormat

private boolean isFormat
Whether format reading is enabled.


heading

private java.lang.String[] heading
Message headers.


columns

private java.lang.String[] columns
Message columns (data).


colIndexes

private int[] colIndexes
Column indexes is message.


isFilter

private boolean isFilter
Whether regular expression filtering is enabled.


regexp

private java.lang.String regexp
Regular expression used as filter.


COLSEP

private static final java.lang.String COLSEP
Default column separator.

See Also:
Constant Field Values

separator

private static java.lang.String separator
Current column separator.


isTimeFilter

private boolean isTimeFilter
Whether time filtering is enabled.


timeField

private java.lang.String timeField
Default column name for the time.


timeFormat

private java.text.SimpleDateFormat timeFormat
Time format. If null, time format is a long (milliseconds from 1/1/1970)


timeIx

private int timeIx
Time filter column index.


fromTime

private long fromTime
Time from which to start outputting data.


toTime

private long toTime
Time at which to stop outputting data.


closeTarget

private boolean closeTarget
Whether target needs to be closed.


id

private java.lang.String id
Outer id.


simpleDateFormat

private static final java.text.SimpleDateFormat simpleDateFormat
Used for setting the Outer.fromTime and Outer.toTime parameters.

Constructor Detail

Outer

public Outer(java.io.PipedOutputStream src,
             java.io.PrintStream target)
      throws java.io.IOException
Creates an Outer using a PipedOutputStream as source and a PrintStream as output. A dummy sink (accessible via getSink() and that can be used an input to any pipe) will be created by default.

Parameters:
src - PipedOutputStream to use as source.
target - PrintStream to use as target (can be null).
Throws:
java.io.IOException - If construction or pipe connection fails.
See Also:
setSink(PipedOutputStream)

Outer

public Outer(java.io.PipedOutputStream src,
             java.io.File file)
      throws java.io.IOException
Creates an Outer using a PipedOutputStream as source and a File as output. A dummy sink (accessible via getSink() and that can be used an input to any pipe) will be created by default.

Parameters:
src - PipedOutputStream to use as source.
file - File to use as output.
Throws:
java.io.IOException - If construction or pipe connection fails.
See Also:
setSink(PipedOutputStream)
Method Detail

setSink

public void setSink(java.io.PipedOutputStream sink)
Parameters:
sink - Sink to set. A dummy sink will be created if null.

getSink

public java.io.PipedOutputStream getSink()
Returns:
The sink currently used.

getId

public java.lang.String getId()
Returns:
The id set.

setId

public void setId(java.lang.String id)
Parameters:
id - The id to set.

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Tests the Outer implementation.

Parameters:
args - Ignored.
Throws:
java.io.IOException - When there's a problem with the source or sink.

run

public void run()
Starts the activity on the Outer (as described in the class header).

Specified by:
run in interface java.lang.Runnable

setHeading

private void setHeading(java.lang.String h)
Parameters:
h - Heading to set. Heading defines the output format and is the first line sent out on any pipe.

setFormatter

public void setFormatter(java.lang.String[] columns)
Parameters:
columns - Name of the columns to set in the formatter.

setRegexp

public void setRegexp(java.lang.String exp)
Parameters:
exp - Regular expression to use as filter for the target.

setTimeFilter

public void setTimeFilter(java.lang.String field,
                          java.lang.String fieldFormat,
                          java.lang.String from,
                          java.lang.String to)
Parameters:
field - Which field to use for time filtering.
fieldFormat - Format of the time field as described in
from - Time from which to start outputting data.
to - Time at which to stop outputting data.
See Also:
resetTimeFilter()

resetTimeFilter

public void resetTimeFilter()
Resets the time filter.

See Also:
setTimeFilter(String, String, String, String)

getSeparator

public static java.lang.String getSeparator()
Returns:
The current field separator.

setSeparator

public static void setSeparator(java.lang.String s)
Parameters:
s - New field separator to use.

matches

private boolean matches(java.lang.String ln)
Parameters:
ln - String to try to match.
Returns:
true if ln matches the regular expression set using Outer.setRegexp, false otherwise.
See Also:
setRegexp(String)

timeMatches

private boolean timeMatches(java.lang.String ln)
Parameters:
ln - String to try to match.
Returns:
true if ln matches the time interval set using Outer.setTimeFilter, false otherwise.
See Also:
setTimeFilter(String, String, String, String)

buildIndex

private boolean buildIndex()
Builds the index.

Returns:
true if successful, false otherwise.