org.hd.d.pg2k.svrCore.stats
Class StatsLogger

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.stats.StatsLogger

public final class StatsLogger
extends java.lang.Object

Stats-gathering interface. This is not designed for especially sensitive information.

The StatsLogger class is not instantiated.

The simplest interface requires the caller to hand a config object in on every call to specify how to handle the stats.

On each stats-event call, the current event may be dumped immediately and/or, if a stats summary is (over)due then it may be done now.


Nested Class Summary
static class StatsLogger.StatsConfig
          Holds the configuration for one statistics set.
 
Field Summary
private static java.util.Map<StatsLogger.StatsConfig,java.util.concurrent.ConcurrentMap<java.lang.String,java.util.concurrent.atomic.AtomicLong>> dataStore
          Map from StatsConfig item to collected stats.
 
Constructor Summary
private StatsLogger()
          No one may instantiate this class.
 
Method Summary
static void captureDataPoint(StatsLogger.StatsConfig statsSet, java.lang.String ev)
          Capture a data point.
static void dumpSummary(StatsLogger.StatsConfig statsSet)
          Dump summary of specified stats to configured log.
private static void printStats(boolean summary, StatsLogger.StatsConfig config, java.lang.String event, java.lang.Number item, long delta)
          Print stats item to its output sink.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataStore

private static final java.util.Map<StatsLogger.StatsConfig,java.util.concurrent.ConcurrentMap<java.lang.String,java.util.concurrent.atomic.AtomicLong>> dataStore
Map from StatsConfig item to collected stats. The data store outer map is a WeakHashMap so that if no one has a strong reference to a given StatsConfig key object then any stats data keyed from it will be automatically discarded.

This is held statically and all access to it should be performed within a lock on the map object if multiple accesses must be performed atomically.

This table is a synchronized WeakHashMap from StatsConfig to a thread-safe map from some Object key to a thread-safe counter.

We don't perform non-essential operations on the per-set Map inside the dataStore lock so as to maximise concurrency.

Note that entries in a WeakHashMap can disappear even while a lock is held on the map.

Constructor Detail

StatsLogger

private StatsLogger()
No one may instantiate this class.

Method Detail

captureDataPoint

public static void captureDataPoint(StatsLogger.StatsConfig statsSet,
                                    java.lang.String ev)
Capture a data point. Notes, in the statistics set uniquely identified by statsSet, an occurrence of the event named by ev.

Neither statsSet nor ev may be null.

Essentially, instances of ev are counted (in a long counter).

This tries to be moderately efficient and quick, at least on average, but may trigger/drive processing such as printing of the event.


dumpSummary

public static void dumpSummary(StatsLogger.StatsConfig statsSet)
Dump summary of specified stats to configured log.


printStats

private static void printStats(boolean summary,
                               StatsLogger.StatsConfig config,
                               java.lang.String event,
                               java.lang.Number item,
                               long delta)
Print stats item to its output sink. This might be zero or more streams and zero or more other sinks such as files.

This includes a delta time in milliseconds from collection creation.


DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.