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 class
Internal auxiliary class which counts the messages of one particular kind. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Counts the critical errors, that are erros and failures.protected Map
<Message.Kind, MessageCounter.Counter> Collection of counters for the different message kinds.protected int
Memorizes 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.int
getCounts
(Message.Kind kind) Returns the count of messages of the givenMessage.Kind
it has received since its creation or the last call toresetCounters()
int
Returns the count of all critical messages it has received since its creation or the last call toresetCounters()
.int
Returns the number of new critical errors occured after the last call tomarkCriticalErrors()
int
getSum()
Returns the count of all messages it has received since its creation or the last call toresetCounters()
boolean
Returns whether critical messages have received since its creation or the last call toresetCounters()
.int
Stores the number of critical errors for later retrieval bygetMarkedErrors()
.Deliver a simple, English-based text representation, only mentioning non-zero counters.void
Advance one or two counters, depending on the message kind.void
Restart the counter for one particularMessage.Kind
at zero.void
Restart all counters at zero, as if the counter object had just been created.void
Print 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, wait
Methods 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.Kind
it 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.Kind
at 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:
receive
in 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.
-