|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.pogamut.base.utils.logging.NetworkLogClient
public class NetworkLogClient
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:
NetworkLogClient.LoggingStarted
event and NetworkLogClient.ILoggingStartedListener
- called whenever successful connection to address:port is made and agent id is sentNetworkLogClient.LogRead
event and NetworkLogClient.ILogReadListener
- called whenever a new log entry has been read providing NetworkLogEnvelope
specifying the log detailsNetworkLogClient.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 |
---|
protected LogCategory log
protected cz.cuni.amis.pogamut.base.utils.logging.NetworkLogClient.LogReadingWorker logReadingWorker
protected java.lang.Thread workerThread
Constructor Detail |
---|
public NetworkLogClient(java.lang.String address, int port, java.lang.String agentId)
Method Detail |
---|
public LogCategory getLogger()
public void setImplicitRemoveListeners(boolean state)
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'.
state
- public boolean isImplicitRemoveListeners()
public boolean isException()
public java.lang.Throwable getException()
public java.lang.String getAddress()
public int getPort()
public java.lang.String getAgentId()
public void start()
public void stop()
public Flag<java.lang.Boolean> getRunning()
public Flag<java.lang.Boolean> getConnected()
public void addListener(NetworkLogClient.ILoggingStartedListener listener)
public void removeListener(NetworkLogClient.ILoggingStartedListener listener)
public void addListener(NetworkLogClient.ILoggingStoppedListener listener)
public void removeListener(NetworkLogClient.ILoggingStoppedListener listener)
public void addListener(NetworkLogClient.ILogReadListener listener)
public void removeListener(NetworkLogClient.ILogReadListener listener)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |