cz.cuni.amis.pogamut.base.utils.logging
Class NetworkLogClient

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.utils.logging.NetworkLogClient

public class NetworkLogClient
extends java.lang.Object

Client that may be used to obtain logs from arbitrary number of agents that are publishing their logs via NetworkLogManager.

It needs to be initialized with address:port and "agent id" which specifies where to connect + which agent's logs you want to receive.

The class is specifying 3 callback (aka listeners) / events that you may attach to it:

  1. NetworkLogClient.LoggingStarted event and NetworkLogClient.ILoggingStartedListener - called whenever successful connection to address:port is made and agent id is sent
  2. NetworkLogClient.LogRead event and NetworkLogClient.ILogReadListener - called whenever a new log entry has been read providing NetworkLogEnvelope specifying the log details
  3. NetworkLogClient.LoggingStopped event and NetworkLogClient.ILoggingStoppedListener - called whenever the logging is terminated

Note that there is a problem with object GC() whenever an anonymous listeners are used (for instance for log collecting). Whenever you start a client, receive logs via listener, DROP THE REFERENCE to the client, the client won't be stopped. It will be stopped whenever the remote socket is closed resulting in IOException inside the client's thread. Additionally, if you do not hook a NetworkLogClient.ILoggingStoppedListener detaching your log-reading-callback listener, the client instance will be ignored by the GC().

Therefore, as an implicit behavior, whenever the logging is stopped, all listeners are actually deleted (which is the way you will probably need to use the class). If you do not want this behavior, just call setImplicitRemoveListeners(boolean) with parameter 'false'.

NOTE: the object must be start() manually after the instantiation.

If you want to stop the client prematurely, call stop().


Nested Class Summary
static interface NetworkLogClient.ILoggingStartedListener
           
static interface NetworkLogClient.ILoggingStoppedListener
           
static interface NetworkLogClient.ILogReadListener
           
static class NetworkLogClient.LoggingStarted
          Event that marks that the client has successfully connected to the remote side and is ready to receive logs.
static class NetworkLogClient.LoggingStopped
          Event that marks that client has been disconnected (or stopped).
static class NetworkLogClient.LogRead
          Event/message containing another log-record produced by the remote agent.
 
Field Summary
protected  LogCategory log
           
protected  cz.cuni.amis.pogamut.base.utils.logging.NetworkLogClient.LogReadingWorker logReadingWorker
          Worker instance - it implements Runnable interface and is continuously reading messages from the connection object and passing them to the callbacks.
protected  java.lang.Thread workerThread
          Thread of the worker.
 
Constructor Summary
NetworkLogClient(java.lang.String address, int port, java.lang.String agentId)
           
 
Method Summary
 void addListener(NetworkLogClient.ILoggingStartedListener listener)
           
 void addListener(NetworkLogClient.ILoggingStoppedListener listener)
           
 void addListener(NetworkLogClient.ILogReadListener listener)
           
 java.lang.String getAddress()
           
 java.lang.String getAgentId()
           
 Flag<java.lang.Boolean> getConnected()
           
 java.lang.Throwable getException()
           
 LogCategory getLogger()
           
 int getPort()
           
 Flag<java.lang.Boolean> getRunning()
           
 boolean isException()
          Does exception occured inside the thread that was/is reading logs?
 boolean isImplicitRemoveListeners()
           
 void removeListener(NetworkLogClient.ILoggingStartedListener listener)
           
 void removeListener(NetworkLogClient.ILoggingStoppedListener listener)
           
 void removeListener(NetworkLogClient.ILogReadListener listener)
           
 void setImplicitRemoveListeners(boolean state)
          Note that there is a problem with object GC() whenever an anonymous listeners are used (for instance for log collecting).
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected LogCategory log

logReadingWorker

protected cz.cuni.amis.pogamut.base.utils.logging.NetworkLogClient.LogReadingWorker logReadingWorker
Worker instance - it implements Runnable interface and is continuously reading messages from the connection object and passing them to the callbacks.


workerThread

protected java.lang.Thread workerThread
Thread of the worker.

Constructor Detail

NetworkLogClient

public NetworkLogClient(java.lang.String address,
                        int port,
                        java.lang.String agentId)
Method Detail

getLogger

public LogCategory getLogger()
Returns:
logger used by this instance

setImplicitRemoveListeners

public void setImplicitRemoveListeners(boolean state)
Note that there is a problem with object GC() whenever an anonymous listeners are used (for instance for log collecting). Whenever you start a client, receive logs via listener, DROP THE REFERENCE to the client, the client won't be stopped. It will be stopped whenever the remote socket is closed resulting in IOException inside the client's thread. Additionally, if you do not hook a NetworkLogClient.ILoggingStoppedListener detaching your log-reading-callback listener, the client instance will be ignored by the GC().

Therefore, as an implicit behavior, whenever the logging is stopped, all listeners are actually deleted (which is the way you will probably need to use the class). If you do not want this behavior, just call this method with 'false' as a parameter. 'false'.

Parameters:
state -

isImplicitRemoveListeners

public boolean isImplicitRemoveListeners()

isException

public boolean isException()
Does exception occured inside the thread that was/is reading logs?

Returns:

getException

public java.lang.Throwable getException()
Returns:
exception that has happened inside the thread that was/is reading logs

getAddress

public java.lang.String getAddress()

getPort

public int getPort()

getAgentId

public java.lang.String getAgentId()

start

public void start()

stop

public void stop()

getRunning

public Flag<java.lang.Boolean> getRunning()

getConnected

public Flag<java.lang.Boolean> getConnected()

addListener

public void addListener(NetworkLogClient.ILoggingStartedListener listener)

removeListener

public void removeListener(NetworkLogClient.ILoggingStartedListener listener)

addListener

public void addListener(NetworkLogClient.ILoggingStoppedListener listener)

removeListener

public void removeListener(NetworkLogClient.ILoggingStoppedListener listener)

addListener

public void addListener(NetworkLogClient.ILogReadListener listener)

removeListener

public void removeListener(NetworkLogClient.ILogReadListener listener)