Class MessageCounter

java.lang.Object
eu.bandm.tools.message.MessageCounter
All Implemented Interfaces:
MessageReceiver<Message>

public class MessageCounter extends Object implements MessageReceiver<Message>
Counts all received messages, per kind, in total, and per critical/non-critical.
  • Field Details

    • counters

      Evident
    • countCritical

      protected int countCritical
      Counts the critical errors, that are erros and failures.
    • criticalMark

      protected int criticalMark
      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.
    • noErrors

      public static final MessageReceiver<Message> noErrors
      Discards all messages but throws an AssertionError if an error is encountered. 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()
      Evident
  • Method Details

    • getCounts

      public int getCounts(Message.Kind kind)
      Returns the count of messages of the given Message.Kind it has received since its creation or the last call to resetCounters()
    • getSum

      public int getSum()
      Returns the count of all messages it has received since its creation or the last call to resetCounters()
    • markCriticalErrors

      public int markCriticalErrors()
      Stores the number of critical errors for later retrieval by getMarkedErrors(). This is called a the beginnig of a processing phase.
    • getMarkedErrors

      public int getMarkedErrors()
      Returns the number of new critical errors occured after the last call to markCriticalErrors()
    • getCriticalCount

      public int getCriticalCount()
      Returns the count of all critical messages it has received since its creation or the last call to resetCounters().

      Critical messages are those the kind of which is critical, Please cf. Message.isCritical().
    • hasCriticals

      public boolean hasCriticals()
      Returns whether critical messages have received since its creation or the last call to resetCounters().

      Critical messages are those the kind of which is critical, Please cf. Message.isCritical().
    • resetCounter

      public void resetCounter(Message.Kind k)
      Restart the counter for one particular Message.Kind with 0(zero). Also re-adjust critical count.
    • resetCounters

      public void resetCounters()
      Restart all counting with 0(zero), as if the counter object had just been created.
    • receive

      public void receive(Message message)
      Advance one or two counters, depending on the message's kind.
      Specified by:
      receive in interface MessageReceiver<Message>
    • _toString

      protected String _toString(boolean filter)
      Auxiliary method.
      Parameters:
      filter - whether to suppress the counters with value =0
    • toString

      public String toString()
      Deliver a simple, english based text representation of all counters.
      Overrides:
      toString in class Object
    • nonZeroToString

      public String nonZeroToString()
      Deliver a simple, english based text representation, only mentioning non-zero counters.
    • terminateApplicationOnErrors

      public void terminateApplicationOnErrors()
      Print an (English) text to std err and termnate application with result code==1, iff errors or failures have been counted.