From 98428507ad5612e9a63081b5caac363c408e66a9 Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 13 Aug 2003 21:04:12 +0000 Subject: [PATCH] Track and report the number of intervals fired in a period as well as the total number of registered intervals. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1197 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/util/IntervalManager.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/IntervalManager.java b/projects/samskivert/src/java/com/samskivert/util/IntervalManager.java index 374e73a9..d044e389 100644 --- a/projects/samskivert/src/java/com/samskivert/util/IntervalManager.java +++ b/projects/samskivert/src/java/com/samskivert/util/IntervalManager.java @@ -1,5 +1,5 @@ // -// $Id: IntervalManager.java,v 1.9 2003/07/27 17:29:26 ray Exp $ +// $Id: IntervalManager.java,v 1.10 2003/08/13 21:04:12 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -103,6 +103,28 @@ public class IntervalManager _logging = log; } + /** + * Returns the total number of intervals registered. + */ + public static int registeredIntervalCount () + { + return _hash.size(); + } + + /** + * Returns the number of intervals fired since the last call to this + * method. + */ + public static int getAndClearFiredIntervals () + { + int fired; + synchronized (_hash) { + fired = _firedIntervals; + _firedIntervals = 0; + } + return fired; + } + /** The timer we use to schedule everything. */ protected static Timer _timer = new Timer(true); @@ -113,6 +135,9 @@ public class IntervalManager /** Whether or not we're logging interval fires. */ protected static boolean _logging = false; + /** Used by {@link #getAndClearFiredIntervals}. */ + protected static int _firedIntervals; + /** * A class to adapt {@link TimerTask} to the smooth action of {@link * Interval}. @@ -149,6 +174,11 @@ public class IntervalManager System.err.println("Interval fired [source=" + _source + "]"); } + // note that we fired another interval + synchronized (_hash) { + _firedIntervals++; + } + // protect our ass. try { _i.intervalExpired(id, _arg);