Atavism Version 2018.1AGIS API

atavism.server.util
Class CountLogger

java.lang.Object
  extended by atavism.server.util.CountLogger
All Implemented Interfaces:
java.lang.Runnable

public class CountLogger
extends java.lang.Object
implements java.lang.Runnable

This class provides APIs to register and unregister objects which derive from the internal static Counter class. It runs every n milliseconds, as determined by a constructor argument, and when it runs, it interrogates the registered objects, using methods defined on the Counter class, getting the current count and a string. It logs a single line every time it runs. That line contains, for each registered object, the string description of the counter, and the difference between the current count and count during the previous iteration.


Nested Class Summary
static class CountLogger.Counter
          The counter class, managed by the CountLogger instance
 
Field Summary
protected  java.util.List<CountLogger.Counter> counters
           
protected  java.lang.Thread countLoggerThread
           
protected  boolean logging
           
protected  int logLevel
           
protected  java.lang.String name
           
protected  int runInterval
           
protected  boolean running
           
protected  boolean showAllNonzeroCounters
           
 
Constructor Summary
CountLogger(java.lang.String name, int runInterval, int logLevel)
          The constructor args determine how often the CountLogger instance runs, and at the log level the log lines
CountLogger(java.lang.String name, int runInterval, int logLevel, boolean showAllNonzeroCounters)
          The constructor args determine how often the CountLogger instance runs, and at the log level the log lines
 
Method Summary
 void addCounter(CountLogger.Counter counter)
          Add a counter created by calling the Counter constructor to the list of counters
 CountLogger.Counter addCounter(java.lang.String name)
          Create a counter with the given name and add it to the list of counters
 CountLogger.Counter addCounter(java.lang.String name, long count)
          Create a counter with the given name and initial count and add it to the list of counters
 void removeCounter(CountLogger.Counter counter)
          Remove the Counter arg from the list of counters
 void run()
          The run method loops sleeping for the run interval, then logs a line containing for each counter the counter name and the count delta since the last time it ran.
 void setLogging(boolean enable)
          Control generation of log messages.
 void start()
          Start counter logging thread.
 void stop()
          Stop counter logging thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

counters

protected java.util.List<CountLogger.Counter> counters

countLoggerThread

protected java.lang.Thread countLoggerThread

running

protected boolean running

name

protected java.lang.String name

runInterval

protected int runInterval

logLevel

protected int logLevel

logging

protected boolean logging

showAllNonzeroCounters

protected boolean showAllNonzeroCounters
Constructor Detail

CountLogger

public CountLogger(java.lang.String name,
                   int runInterval,
                   int logLevel)
The constructor args determine how often the CountLogger instance runs, and at the log level the log lines

Parameters:
runInterval - The number of milliseconds between runs
logLevel - The level at which the information is logged.

CountLogger

public CountLogger(java.lang.String name,
                   int runInterval,
                   int logLevel,
                   boolean showAllNonzeroCounters)
The constructor args determine how often the CountLogger instance runs, and at the log level the log lines

Parameters:
name - Logger name.
runInterval - Milliseconds between runs.
logLevel - The level at which the information is logged.
showAllNonzeroCounters -
Method Detail

addCounter

public CountLogger.Counter addCounter(java.lang.String name)
Create a counter with the given name and add it to the list of counters


addCounter

public CountLogger.Counter addCounter(java.lang.String name,
                                      long count)
Create a counter with the given name and initial count and add it to the list of counters


addCounter

public void addCounter(CountLogger.Counter counter)
Add a counter created by calling the Counter constructor to the list of counters


removeCounter

public void removeCounter(CountLogger.Counter counter)
Remove the Counter arg from the list of counters


start

public void start()
Start counter logging thread.


stop

public void stop()
Stop counter logging thread.


setLogging

public void setLogging(boolean enable)
Control generation of log messages.


run

public void run()
The run method loops sleeping for the run interval, then logs a line containing for each counter the counter name and the count delta since the last time it ran.

Specified by:
run in interface java.lang.Runnable


Copyright © 2018 Dragonsan Studios Sp. z o.o.