Rather than define a whole public class, publish an interface:
Interval.Runnable, that can be used to retrieve the Interval from the java.lang.Runnable posted on a RunQueue. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1717 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -32,33 +32,14 @@ import com.samskivert.Log;
|
|||||||
*/
|
*/
|
||||||
public abstract class Interval
|
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
|
* An interface that will be implemented by the runnable posted
|
||||||
* actually going to do the work for profiling and reporting. */
|
* to a RunQueue that can be used to retrieve the original Interval.
|
||||||
public static class RunQueueRunnable implements Runnable
|
*/
|
||||||
|
public static interface Runnable extends java.lang.Runnable
|
||||||
{
|
{
|
||||||
public RunQueueRunnable (IntervalTask task, Interval interval) {
|
public Interval getInterval ();
|
||||||
_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
|
* Create a simple interval that does not use a RunQueue to run
|
||||||
@@ -175,10 +156,22 @@ public abstract class Interval
|
|||||||
public void run () {
|
public void run () {
|
||||||
if (_runQueue == null) {
|
if (_runQueue == null) {
|
||||||
safelyExpire(this);
|
safelyExpire(this);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (_runner == null) { // lazy initialize _runner
|
if (_runner == null) { // lazy initialize _runner
|
||||||
_runner = new RunQueueRunnable(
|
_runner = new Runnable() {
|
||||||
IntervalTask.this, Interval.this);
|
public void run () {
|
||||||
|
safelyExpire(IntervalTask.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Interval getInterval () {
|
||||||
|
return Interval.this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString () {
|
||||||
|
return Interval.this.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
_runQueue.postRunnable(_runner);
|
_runQueue.postRunnable(_runner);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user