|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgizmoball.JavaUtilTimerClock
public final class JavaUtilTimerClock
An implementation of the Clock
interface using Timer
. Each JavaUtilTimerClock
object wraps a
java.util.Timer
object and uses that to dispatch the
tasks that it is in charge of running.
JavaUtilTimerClock
also has the extra bonus that it is a
thread-safe class. Multiple threads may share a
JavaUtilTimerClock
object without requiring external
synchronization.
Note that all the specification fields are inherited from
Clock
. For a canonical list of them, see the
specifications for Clock
.
Field Summary | |
---|---|
static String |
rcsid
Class revision identifier. |
Constructor Summary | |
---|---|
JavaUtilTimerClock(Board board,
int interval)
Constructs a new stopped Clock with the given
Board and interval. |
Method Summary | |
---|---|
void |
addBoardView(BoardView view)
Adds a BoardView to the set of
BoardView s to be redrawn by this Clock . |
boolean |
isRunning()
Returns whether this Clock is running. |
void |
removeBoardView(BoardView view)
Removes a BoardView from the set of
BoardView s to be redrawn by this Clock . |
void |
start()
Starts a Clock that is not currently running. |
void |
stop()
Stops a Clock that is currently running. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String rcsid
rcsid
contains an RCS Id
keyword string that may be used to identify which revision of
JavaUtilTimerClock.java
was used to generate an
instance of JavaUtilTimerClock.class
. To identify
the revision of a JavaUtilTimerClock.class
file, run
"ident JavaUtilTimerClock.class
" (ident
is part of the RCS
software package).
Constructor Detail |
---|
public JavaUtilTimerClock(Board board, int interval)
Clock
with the given
Board
and interval.
board
- Board
to be steppedinterval
- length of this Clock
's interval in
millisecondsboard != null
and
interval
> 0this.interval = interval
this.board = board
this.boardViews
= the empty set
this.isRunning = false
Method Detail |
---|
public void start()
Clock
that is not currently running.
Note that this implementation relaxes the requires clause
specified by Clock
by allowing this method to be
called even on already started JavaUtilTimerClock
s.
Such a call will be effectively a no-op.
start
in interface Clock
this.isRunning = true
public void stop()
Clock
that is currently running.
Note that this implementation relaxes the requires clause
specified by Clock
by allowing this method to be
called even on already stopped JavaUtilTimerClock
s.
Such a call will be effectively a no-op.
Beware that this method synchronously stops this
Clock
; it will wait for the last step and redraw
cycle to finish before returning. Do not call this method from a
thread that is holding locks on resources that might be needed to
complete a Board
step or the BoardView
redraws.
stop
in interface Clock
this.isRunning = false
public boolean isRunning()
Clock
is running. If this
Clock
is currently stepping its Board
at its configured regular interval, then returns
true
; otherwise, if this Clock
is
stopped, returns false
.
isRunning
in interface Clock
this.isRunning
public void addBoardView(BoardView view)
BoardView
to the set of
BoardView
s to be redrawn by this Clock
.
Note that this implementation of addBoardView
has a
less strict requires clause than specified by Clock
.
In particular, it is okay for this method to be called when this
JavaUtilTimerClock
is running; the addition of the
BoardView
will just be effective "soon," most likely
during the next iteration of the step and redraw cycle. Also, it
is okay for view
to already have been previously
added; in such a case, this method will be essentially a no-op.
addBoardView
in interface Clock
view
- BoardView
to be addedview != null
this.boardViewspost
=
this.boardViewspre
+
{ view
}public void removeBoardView(BoardView view)
BoardView
from the set of
BoardView
s to be redrawn by this Clock
.
Note that this implementation of removeBoardView
has
a less strict requires clause than specified by
Clock
. In particular, it is okay for this method to
be called when this JavaUtilTimerClock
is running;
the removal of the BoardView
will just be effective
"soon," most likely during the next iteration of the step and
redraw cycle. Also, it is okay for view
not to
currently be in this.boardViews
; in such a case,
this method will be essentially a no-op.
removeBoardView
in interface Clock
view
- BoardView
to be removedview != null
this.boardViewspost
=
this.boardViewspre
-
{ view
}
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |