com.jfw.status
Class LogViewerObserver

java.lang.Object
  extended by com.jfw.status.LogViewerObserver
All Implemented Interfaces:
java.util.Observer

public class LogViewerObserver
extends java.lang.Object
implements java.util.Observer

Is the observer of class JFWLogger. Every time a log message send at JFWLogger this message is also send at they obervers.
You can use this an instance of the class in two ways:

  1. call the method stayInLoop(): this is the right method if you want to stay in log and get all the log messages.
    Example
      LogViewerObserver logViewerObserver = new LogViewerObserver(outputStream);
      logViewerObserver.stayInLoop();
  2. call the method start() that add the instance as observer of JFWLogger and when you want to stop to get the log messages call the method stop().
    Example
     
      LogViewerObserver logViewerObserver = new LogViewerObserver(outputStream);
      logViewerObserver.start();
      ....
      //we can continue with other thinks since the start method not block the 
      //execution
      ....
      logViewerObserver.stop();
In both cases the log messages are wqrited in the stream passed as parameter at the constructor.


Field Summary
static byte[] endMessage
          The ending message.
static byte[] messageSuffix
          The suffix added ad every single message.
static byte[] startMessage
          The starting message.
 
Constructor Summary
LogViewerObserver(java.io.OutputStream outputStream)
          Create an instance.
 
Method Summary
 void finalize()
          Call the super.finalize() method and the the method stop().
 boolean observationStopped()
          Return the value of attribute stopObservation.
 void start()
          Add this instance as observer of JFWLogger.
 void stayInLoop()
          Create a loop observing the attribute stopObservation.
 void stop()
          Change the value of stopObservation in true and call the method close().
 void update(java.util.Observable observable, java.lang.Object object)
          Is called by the observable instance.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageSuffix

public static final byte[] messageSuffix
The suffix added ad every single message.


startMessage

public static final byte[] startMessage
The starting message. This message is send in the start() method.


endMessage

public static final byte[] endMessage
The ending message. This message is send in the close() method.

Constructor Detail

LogViewerObserver

public LogViewerObserver(java.io.OutputStream outputStream)
Create an instance.

Parameters:
outputStream - the stream where the log messages are written.
Method Detail

stayInLoop

public void stayInLoop()
Create a loop observing the attribute stopObservation. Attribute stopObservation change value in methods write2Stream(byte[]), update(Observable, Object) and stop().


update

public void update(java.util.Observable observable,
                   java.lang.Object object)
Is called by the observable instance.
If an exception occur then the stop() method is called.

Specified by:
update in interface java.util.Observer
Parameters:
observable - the observable instance.
object - the log message.

start

public void start()
Add this instance as observer of JFWLogger.
Also write in the stream outputStream the starting message.


stop

public void stop()
Change the value of stopObservation in true and call the method close().


observationStopped

public boolean observationStopped()
Return the value of attribute stopObservation.

Returns:
the value of attribute stopObservation.

finalize

public void finalize()
              throws java.lang.Throwable
Call the super.finalize() method and the the method stop().

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable