Package eu.bandm.tools.message
Class MessageCounter
java.lang.Object
eu.bandm.tools.message.MessageCounter
- All Implemented Interfaces:
MessageReceiver<Message>
Counts all received messages, per kind, in total, and per
critical/non-critical.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classInternal auxiliary class which counts the messages of one particular kind. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intCounts the critical errors, that are erros and failures.protected Map<Message.Kind, MessageCounter.Counter> Collection of counters for the different message kinds.protected intMemorizes the number of critical errors at the beginning of one processing phase, to compare it with the number at the end of that phase.static final MessageReceiver<Message> Discards all messages but throws an AssertionError if an error is received. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String_toString(boolean filter) Auxiliary method.intgetCounts(Message.Kind kind) Returns the count of messages of the givenMessage.Kindit has received since its creation or the last call toresetCounters()intReturns the count of all critical messages it has received since its creation or the last call toresetCounters().intReturns the number of new critical errors occured after the last call tomarkCriticalErrors()intgetSum()Returns the count of all messages it has received since its creation or the last call toresetCounters()booleanReturns whether critical messages have received since its creation or the last call toresetCounters().intStores the number of critical errors for later retrieval bygetMarkedErrors().Deliver a simple, English-based text representation, only mentioning non-zero counters.voidAdvance one or two counters, depending on the message kind.voidRestart the counter for one particularMessage.Kindat zero.voidRestart all counters at zero, as if the counter object had just been created.voidPrint an (English) text to std err and terminate application with result code {code ==1}, iff errors or failures have been counted.toString()Deliver a simple, English-based text representation of all counters.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface eu.bandm.tools.message.MessageReceiver
ifSubcriticalThen, ifSubcriticalThen, ifSubcriticalThenElse
-
Field Details
-
counters
Collection of counters for the different message kinds. -
countCritical
protected int countCriticalCounts the critical errors, that are erros and failures. -
criticalMark
protected int criticalMarkMemorizes the number of critical errors at the beginning of one processing phase, to compare it with the number at the end of that phase. -
noErrors
Discards all messages but throws an AssertionError if an error is received. Used for initialization code on constant input data which is asserted to run without errors and for which no message output is needed/requested. Throws AssertionError if an Error or a Failure is received.
-
-
Constructor Details
-
MessageCounter
public MessageCounter()Only constructor.
-
-
Method Details
-
getCounts
Returns the count of messages of the givenMessage.Kindit has received since its creation or the last call toresetCounters()- Parameters:
kind- the kind for which the messages shall be counted- Returns:
- the number of received messages with the given kind.
-
getSum
public int getSum()Returns the count of all messages it has received since its creation or the last call toresetCounters()- Returns:
- count of all messages received.
-
markCriticalErrors
public int markCriticalErrors()Stores the number of critical errors for later retrieval bygetMarkedErrors(). This is usually called at the beginnig of a particular processing phase.- Returns:
- the current total number of received critical errors.
-
getMarkedErrors
public int getMarkedErrors()Returns the number of new critical errors occured after the last call tomarkCriticalErrors()- Returns:
- the number of critical errors received after calling
markCriticalErrors().
-
getCriticalCount
public int getCriticalCount()Returns the count of all critical messages it has received since its creation or the last call toresetCounters(). Critical messages are those the kind of which is critical.- Returns:
- total number of critical errors.
- See Also:
-
hasCriticals
public boolean hasCriticals()Returns whether critical messages have received since its creation or the last call toresetCounters(). Critical messages are those the kind of which is critical.- Returns:
- if critical errors have been received.
- See Also:
-
resetCounter
Restart the counter for one particularMessage.Kindat zero. Also re-adjust critical count.- Parameters:
k- the kind for which the counter shall be resetted.
-
resetCounters
public void resetCounters()Restart all counters at zero, as if the counter object had just been created. -
receive
Advance one or two counters, depending on the message kind.- Specified by:
receivein interfaceMessageReceiver<Message>- Parameters:
message- the message to receive.
-
_toString
Auxiliary method.- Parameters:
filter- whether to suppress the counters with value =0- Returns:
- text representation of all (or filtered) counter values.
-
toString
Deliver a simple, English-based text representation of all counters. -
nonZeroToString
Deliver a simple, English-based text representation, only mentioning non-zero counters.- Returns:
- text representation of all non-zero counter values.
-
terminateApplicationOnErrors
public void terminateApplicationOnErrors()Print an (English) text to std err and terminate application with result code {code ==1}, iff errors or failures have been counted.
-