|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object biz.chitec.quarterback.util.Logger
Basic logging object. Gets objects to "log" and handles them in a separate Thread. Main idea is simple: Objects to log are delivered through logObject(), and handled within handleLogObject(), which is executed in a seperate thread. Thread management and object locking is handled by the Logger object.
Implementation notes: This object uses some infrastructure which reminds to the ThreadInterface object. It doesn't use ThreadInterface internally only for historic reasons: In fact, Logger has been developed (shortly) before ThreadInterface.
Logger is fed through the logObject() methods. It knows three different working modes concerning how the object is sent to its origin. Of course, this makes only a difference if the origin actually is among the registered receivers:
emergencyRemoveReceiver(LoggingReceiver)
can
be used which removes the given receiver completely and regardsless of conditional or unconditional addition.
ThreadInterface
Nested Class Summary | |
protected class |
Logger.ChainElem
Simple subclass: element of a simple linked list. |
Field Summary | |
protected Logger.ChainElem |
first
leading element of the list. |
protected java.lang.Thread |
handleloophandler
internally managed Thread for the handler |
protected java.util.List |
receiverexpr
Logic expression to decide whether messages should be really passed to receiver at same index. |
protected java.util.List |
receivers
All receivers of the messages |
protected boolean |
sleeping
Description of the Field |
protected Logger.ChainElem |
worked
actually handled element of the list. |
Constructor Summary | |
Logger()
Only constructor of the simple logger. |
Method Summary | |
boolean |
addReceiver(LoggingReceiver lr)
Add a receiver unconditionally to this logger. |
boolean |
addReceiver(LoggingReceiver lr,
java.lang.Object reference,
LogicExpr sexpr)
Add a receiver with a condition to this logger. |
boolean |
containsReceiver(LoggingReceiver lr)
Returns whether a certain logging receiver has actually been added. |
protected void |
continueHandleLogObject(java.lang.Object o,
LoggingReceiver sender,
long ts,
int seqnr,
boolean tosenderonly)
Generic logging event handler. |
protected void |
doSendInHandleLoop(java.lang.Object o,
LoggingReceiver receiver,
long ts,
int seqnr)
Send data to one receiver, Handle loop part. |
protected void |
doSendToReceiver(java.lang.Object o,
LoggingReceiver receiver,
long ts,
int seqnr)
Actually send data to one receiver. |
void |
emergencyRemoveReceiver(LoggingReceiver lr)
Remove a logging receiver without taking care on logic expressions or unconditional checking. |
private boolean |
evaluateExpressions(int idx,
java.lang.Object o)
Evaluate the logical expression for a logging receiver. |
protected void |
handleLogObject(java.lang.Object o,
LoggingReceiver sender,
long ts,
boolean tosenderonly)
Top-level internal log object handling method. |
void |
handleloop()
Main handling loop. |
void |
logObject(LoggingReceiver lr,
java.lang.Object o)
Delivers a new message object that has to be logged to all receivers except of the one given as parameter. |
void |
logObject(LoggingReceiver lr,
java.lang.Object o,
boolean tosenderonly)
Deliveres a new message object either to all but the given receiver or to the given receiver only. |
void |
logObject(java.lang.Object o)
Delivers a new message object that has to be logged to all receivers. |
void |
logObjectToSenderOnly(LoggingReceiver lr,
java.lang.Object o)
Convenience method for {@link #logObject(LoggingReceiver, Object, boolean) with third parameter set to true. |
boolean |
nothingToHandle()
Checks whether the logger has something in the queue to log |
boolean |
removeReceiver(LoggingReceiver lr)
Remove an unconditionally added receiver. |
boolean |
removeReceiver(LoggingReceiver lr,
java.lang.Object reference)
Remove a receiver which has been added with a logical expression as condition. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Logger.ChainElem first
protected Logger.ChainElem worked
protected java.lang.Thread handleloophandler
protected java.util.List receivers
protected java.util.List receiverexpr
protected boolean sleeping
Constructor Detail |
public Logger()
Method Detail |
public boolean addReceiver(LoggingReceiver lr)
addReceiver(LoggingReceiver, Object, LogicExpr)
on the same receiver. This will simply
throw an exception.
lr
- LoggingReceiver to receive the messages
public boolean addReceiver(LoggingReceiver lr, java.lang.Object reference, LogicExpr sexpr)
LoggerCenter
) to the logger and later removes it. It passes itself as
reference so that multiple executors can perform this addition without knowing from each other.
lr
- LoggingReceiver to receive the messagesreference
- Reference object which allows removal of this receiver lateronsexpr
- Logical expression which evaluates the message
public boolean removeReceiver(LoggingReceiver lr)
removeReceiver(LoggingReceiver, Object)
, this method will not check whether
the receiver has been added multiple times. Instead, it will simply be removed. If there are multiple adding instances for
one receiver using this unconditional scheme, each has to evaluate the return value of addReceiver(LoggingReceiver)
and only remove the receiver when it's time if that method returned true on addition.
lr
- Receiver to remove.
public boolean removeReceiver(LoggingReceiver lr, java.lang.Object reference)
lr
- reference
-
public void emergencyRemoveReceiver(LoggingReceiver lr)
ServerThreadBase
handling
a GJSA client which just closes the connection).
This method never fails.
lr
- Logging receiver to remove from the receiver listpublic boolean containsReceiver(LoggingReceiver lr)
lr
- Logging receiver to check
public void handleloop()
protected void handleLogObject(java.lang.Object o, LoggingReceiver sender, long ts, boolean tosenderonly)
continueHandleLogObject(Object, LoggingReceiver, long, int, boolean)
to allow subclasses to hook into the process.
DO NOT USE THIS METHOD TO DELIVER SOMETHING TO LOG TO THE LOGGER!!! This is the internal handling method of the
logger. For passing messages from a sender, use logObject(Object)
and friends!
o
- Message object to logsender
- Source for the logging, may be null.ts
- timestamp for UpdateableLoggertosenderonly
- Flag to force sending to sender itself onlyprotected void continueHandleLogObject(java.lang.Object o, LoggingReceiver sender, long ts, int seqnr, boolean tosenderonly)
handleLogObject(Object, LoggingReceiver, long, boolean)
method is needed due to
all the different logger types (TransactionLogger
/UpdateableLogger
).
o
- Object to logsender
- Source for the logging object, may be null.ts
- Timestamp for UpdateableLoggerseqnr
- Sequence counter for TransactionLoggertosenderonly
- Flag to force sending to sender itself onlyprivate boolean evaluateExpressions(int idx, java.lang.Object o)
idx
- Index of the receiver (and therefore the logical expression container) in the receiver listo
- Message to evaluate
protected void doSendInHandleLoop(java.lang.Object o, LoggingReceiver receiver, long ts, int seqnr)
doSendToReceiver(Object, LoggingReceiver, long, int)
. This can, however, be overwritten
by the subclasses.
o
- Message object to logts
- timestamp for UpdateableLoggerseqnr
- Sequence counter for TransactionLoggerprotected void doSendToReceiver(java.lang.Object o, LoggingReceiver receiver, long ts, int seqnr)
o
- Message object to logts
- timestamp for UpdateableLoggerseqnr
- Sequence counter for TransactionLoggerpublic boolean nothingToHandle()
public void logObject(java.lang.Object o)
o
- Message object to handlepublic void logObject(LoggingReceiver lr, java.lang.Object o)
logObject(Object)
.
lr
- Receiver not to receive the message even if it is among the receivers and regardsless of its logical expression.o
- Message object to handlepublic void logObject(LoggingReceiver lr, java.lang.Object o, boolean tosenderonly)
logObject(Object)
. If tosenderonly is set to false, this method is the same as
logObject(LoggingReceiver, Object)
.
lr
- Receiver not to receive the message even if it is among the receivers and regardsless of its logical expression.o
- Message object to handletosenderonly
- If true, send object only to given receiver. If false, send object to all but the given receiver.public void logObjectToSenderOnly(LoggingReceiver lr, java.lang.Object o)
lr
- Receiver to receive the message only if it is among the receivers and its logical expression matches.o
- Message object to handle
|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |