Log a warning and cancel a repeating interval if it attempts to post itself to
a RunQueue that has been shutdown. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2596 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -141,6 +141,10 @@ public abstract class Interval
|
|||||||
/**
|
/**
|
||||||
* Schedule the interval to execute repeatedly with fixed-rate scheduling between repeats,
|
* Schedule the interval to execute repeatedly with fixed-rate scheduling between repeats,
|
||||||
* with the same delay. Supersedes any previous schedule that this Interval may have had.
|
* with the same delay. Supersedes any previous schedule that this Interval may have had.
|
||||||
|
*
|
||||||
|
* <p> Note: if a repeating interval is scheduled to post itself to a RunQueue and the target
|
||||||
|
* RunQueue is shutdown when the interval expires, the interval will cancel itself and log a
|
||||||
|
* warning message. </p>
|
||||||
*/
|
*/
|
||||||
public final void schedule (long delay, boolean repeat)
|
public final void schedule (long delay, boolean repeat)
|
||||||
{
|
{
|
||||||
@@ -149,8 +153,12 @@ public abstract class Interval
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule the interval to execute repeatedly with the specified initial delay and repeat
|
* Schedule the interval to execute repeatedly with the specified initial delay and repeat
|
||||||
* delay with fixed-rate scheduling between repeats. Supersedes any previous schedule that
|
* delay with fixed-rate scheduling between repeats. Supersedes any previous schedule that this
|
||||||
* this Interval may have had.
|
* Interval may have had.
|
||||||
|
*
|
||||||
|
* <p> Note: if a repeating interval is scheduled to post itself to a RunQueue and the target
|
||||||
|
* RunQueue is shutdown when the interval expires, the interval will cancel itself and log a
|
||||||
|
* warning message. </p>
|
||||||
*/
|
*/
|
||||||
public final void schedule (long initialDelay, long repeatDelay)
|
public final void schedule (long initialDelay, long repeatDelay)
|
||||||
{
|
{
|
||||||
@@ -161,6 +169,10 @@ public abstract class Interval
|
|||||||
* Schedule the interval to execute repeatedly with the specified initial delay and repeat
|
* Schedule the interval to execute repeatedly with the specified initial delay and repeat
|
||||||
* delay. Supersedes any previous schedule that this Interval may have had.
|
* delay. Supersedes any previous schedule that this Interval may have had.
|
||||||
*
|
*
|
||||||
|
* <p> Note: if a repeating interval is scheduled to post itself to a RunQueue and the target
|
||||||
|
* RunQueue is shutdown when the interval expires, the interval will cancel itself and log a
|
||||||
|
* warning message. </p>
|
||||||
|
*
|
||||||
* @param fixedRate - if true, this interval schedules repeated expirations using
|
* @param fixedRate - if true, this interval schedules repeated expirations using
|
||||||
* {@link Timer#scheduleAtFixedRate(TimerTask, long, long)} ensuring that the number of
|
* {@link Timer#scheduleAtFixedRate(TimerTask, long, long)} ensuring that the number of
|
||||||
* expired calls will match the amount of time elapsed. If false, it uses
|
* expired calls will match the amount of time elapsed. If false, it uses
|
||||||
@@ -276,36 +288,42 @@ public abstract class Interval
|
|||||||
Interval ival = _interval;
|
Interval ival = _interval;
|
||||||
if (ival == null) {
|
if (ival == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
} else if (ival._runQueue == null) {
|
if (ival._runQueue == null) {
|
||||||
ival.safelyExpire(this);
|
ival.safelyExpire(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
if (_runner == null) { // lazy initialize _runner
|
||||||
if (_runner == null) { // lazy initialize _runner
|
_runner = new RunBuddy() {
|
||||||
_runner = new RunBuddy() {
|
public void run () {
|
||||||
public void run () {
|
Interval ival = _interval;
|
||||||
Interval ival = _interval;
|
if (ival != null) {
|
||||||
if (ival != null) {
|
ival.safelyExpire(IntervalTask.this);
|
||||||
ival.safelyExpire(IntervalTask.this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
public Interval getInterval () {
|
||||||
|
return _interval;
|
||||||
|
}
|
||||||
|
@Override public String toString () {
|
||||||
|
Interval ival = _interval;
|
||||||
|
return (ival != null) ? ival.toString() : "(Interval was cancelled)";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public Interval getInterval () {
|
if (ival._runQueue.isRunning()) {
|
||||||
return _interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String toString () {
|
|
||||||
Interval ival = _interval;
|
|
||||||
return (ival != null) ? ival.toString() : "(Interval was cancelled)";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ival._runQueue.postRunnable(_runner);
|
ival._runQueue.postRunnable(_runner);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warning("Failed to execute interval on run-queue", "queue", ival._runQueue,
|
log.warning("Failed to execute interval on run-queue", "queue", ival._runQueue,
|
||||||
"interval", ival, e);
|
"interval", ival, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
log.warning("Interval posted to shutdown RunQueue. Cancelling.",
|
||||||
|
"queue", ival._runQueue, "interval", ival);
|
||||||
|
ival.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user