|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
stella.util.Alarm
public class Alarm
A class with the functionality of an alarm clock. It is a self-starting thread that waits for specified time. If the alarm was not canceled with the cancel method during the waiting phase the setOff method of the registered alarm handlers are called. Note that all the alarm handlers must be available at the construction phase because of the self-starting nature of this thread.
In principle the functionality of the alarm can be constructed using the java Timer and TimerTask classes but the simplicity of this class may provide a very easy and convenient access.
| Nested Class Summary | |
|---|---|
static class |
Alarm.Test
Test purpos only. |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
protected AlarmHandler |
alarmList
The alarm handlers |
private boolean |
alarmOff
Gets true if the alarm is canceled. |
private static int |
COUNT
An internal counter for automatic naming. |
private long |
mintime
The time-tag that must be reached. |
private long |
starttime
The first time-tag that must be reached. |
private long |
sustime
The time the Thread.suspend() method was called. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
protected |
Alarm()
Constructor chaining, do not use. |
|
Alarm(AlarmHandler ear,
Date when)
Constructs a new alarm with a default name and starts it automatically. |
|
Alarm(AlarmHandler ear,
long timeout)
Constructs a new alarm with a default name and starts it automatically. |
|
Alarm(ThreadGroup group,
String name,
AlarmHandler ear,
Date when)
Constructs a new alarm and starts it automatically. |
|
Alarm(ThreadGroup group,
String name,
AlarmHandler ear,
long timeout)
Constructs a new alarm and starts it automatically. |
| Method Summary | |
|---|---|
void |
cancel()
Cancels this alarm. |
private static int |
nextCount()
Gets the next available number at automatic naming. |
void |
resumeAlarm()
Resumes the alarm-clock ticking after a call to suspendAlarm(). |
void |
run()
The run method of the alarm. |
protected void |
setOffAlarm()
This method sets off all registered alarm listeners by calling their setOff method. |
void |
suspendAlarm()
Temporarily pauses the alarm clock. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private boolean alarmOff
private long mintime
private long starttime
protected AlarmHandler alarmList
private long sustime
Thread.suspend() method was called.
private static int COUNT
| Constructor Detail |
|---|
protected Alarm()
public Alarm(AlarmHandler ear,
Date when)
ear - The alarm handlers to notify.when - The date when the alarm is set off.
public Alarm(AlarmHandler ear,
long timeout)
ear - The alarm handlers to notify.timeout - The time till alarm is set off, in ms.
IllegalArgumentException - If timeout is negative.
public Alarm(ThreadGroup group,
String name,
AlarmHandler ear,
Date when)
group - The thread group this alarm should run in.name - The name for the alarmear - The alarm handlers to notify.when - The date when the alarm is set off.
public Alarm(ThreadGroup group,
String name,
AlarmHandler ear,
long timeout)
group - The thread group this alarm should run in.name - The name for the alarmear - The alarm listeners to notify.timeout - The time till alarm is set off, in ms.
IllegalArgumentException - If timeout is negative.| Method Detail |
|---|
private static int nextCount()
public final void suspendAlarm()
resumeAlarm() method is called.
public final void resumeAlarm()
suspendAlarm().
public final void run()
cancel() method but if this thread is interrupted
the same effect should be obtained.
run in interface Runnablerun in class Threadprotected void setOffAlarm()
public void cancel()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||