From 2e35d2d8f19c3b032efa5133dcced39071cdeb53 Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 6 Sep 2005 18:18:17 +0000 Subject: [PATCH] Restructure things so that we can get our hands on the actual Interval derivation that is being posted to a RunQueue for profiling and reporting purposes. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1709 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/Interval.java | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/Interval.java b/projects/samskivert/src/java/com/samskivert/util/Interval.java index 9b11dfdd..f1297e45 100644 --- a/projects/samskivert/src/java/com/samskivert/util/Interval.java +++ b/projects/samskivert/src/java/com/samskivert/util/Interval.java @@ -32,6 +32,34 @@ import com.samskivert.Log; */ public abstract class Interval { + /** This is used to post our interval to a run queue and provides + * methods for getting access to the Interval derivation that is + * actually going to do the work for profiling and reporting. */ + public static class RunQueueRunnable implements Runnable + { + public RunQueueRunnable (IntervalTask task, Interval interval) { + _task = task; + _interval = interval; + } + + public Interval getInterval () { + return _interval; + } + + public void run () { + _interval.safelyExpire(_task); + } + + public String toString () { + // to aid in debugging, this run unit reports its name as that + // of the interval + return _interval.toString(); + } + + protected IntervalTask _task; + protected Interval _interval; + }; + /** * Create a simple interval that does not use a RunQueue to run * the expired() method. @@ -149,17 +177,8 @@ public abstract class Interval safelyExpire(this); } else { if (_runner == null) { // lazy initialize _runner - _runner = new Runnable() { - public void run () { - safelyExpire(IntervalTask.this); - } - - // to aid in debugging, this run unit reports its - // name as that of the interval. - public String toString () { - return Interval.this.toString(); - } - }; + _runner = new RunQueueRunnable( + IntervalTask.this, Interval.this); } _runQueue.postRunnable(_runner); }