public abstract class PeriodicThread
extends java.lang.Thread
Vona's utils: a periodic thread.
A daemon thread that calls
at period no
greater than update(double, double)
updateTime
.
Copyright (C) 2004 Marsette A. Vona, III
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Modifier and Type | Field and Description |
---|---|
protected Clock |
clock
The timebase.
|
protected boolean |
continueOnInterrupt
Whether this thread should continue looping if it's
interrupt() ed. |
(package private) static java.lang.String |
cvsid
CVS id.
|
protected boolean |
forceOngoing
Whether a
forceUpdate() is ongoing. |
protected boolean |
killOngoing
Whether a
kill() is ongoing. |
protected double |
lastTime
The last time we updated, or when we were constructed if we haven't
updated yet.
|
protected boolean |
running
Whether this PeriodicThread is currently running.
|
protected double |
updateTime
The update time in accelseconds.
|
Constructor and Description |
---|
PeriodicThread(Clock clock,
double updateTime)
Create a new PeriodicThread, not started.
|
Modifier and Type | Method and Description |
---|---|
void |
forceUpdate()
Force an update.
|
double |
getUpdateTime()
Get update time in seconds.
|
void |
interrupt()
Extends default impl to behave even if called while an update is
being forced.
|
boolean |
isContinueOnInterrupt()
Whether to continue if this thread is interrupted.
|
void |
kill()
Kill this thread.
|
void |
run()
Update repeatedly at period no greater than
updateTime . |
void |
setContinueOnInterrupt(boolean continueOnInterrupt)
Set whether to continue if this thread is interrupted.
|
void |
setUpdateTime(double updateTime)
Set update time in seconds.
|
abstract void |
update(double time,
double dt)
Will be called at period no greater than the update
frequency .
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
static final java.lang.String cvsid
CVS id.
protected Clock clock
The timebase.
protected double updateTime
The update time in accelseconds.
protected double lastTime
The last time we updated, or when we were constructed if we haven't updated yet.
protected boolean forceOngoing
Whether a forceUpdate()
is ongoing.
protected boolean killOngoing
Whether a kill()
is ongoing.
protected boolean running
Whether this PeriodicThread is currently running.
protected boolean continueOnInterrupt
Whether this thread should continue looping if it's
interrupt()
ed.
public PeriodicThread(Clock clock, double updateTime)
Create a new PeriodicThread, not started.
clock
- the timebase to useupdateTime
- update time in seconds, non-negativepublic abstract void update(double time, double dt)
Will be called at period no greater than the update frequency .
time
- the time at calldt
- the time since last call (on first call, since construction)public boolean isContinueOnInterrupt()
Whether to continue if this thread is interrupted.
public void setContinueOnInterrupt(boolean continueOnInterrupt)
Set whether to continue if this thread is interrupted.
continueOnInterrupt
- whether this thread should continue if
interruptedpublic void setUpdateTime(double updateTime)
Set update time in seconds.
updateTime
- update time in seconds, non-negativepublic double getUpdateTime()
Get update time in seconds.
public void forceUpdate()
Force an update.
Does nothing if this PeriodicThread is not currently running.
public void interrupt()
Extends default impl to behave even if called while an update is being forced.
interrupt
in class java.lang.Thread
public void kill()
Kill this thread.
Does nothing if this PeriodicThread is not currently running.
public void run()
Update repeatedly at period no greater than updateTime
.
Based entirely on Clock.getCurrentTime()
.
run
in interface java.lang.Runnable
run
in class java.lang.Thread