|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nl.justobjects.toolkit.sys.Alarm
Alarm timer service.
AlarmListener
object.
This callback is performed once after a specified amount of time (ms) has
elapsed. After creation, a client may:
reschedule()
the alarm call for the same period of time (does
not matter if the original period had expired or not)reschedule(long)
the alarm call for another period of time (does
not matter if the original period had expired or not)cancel()
the alarm call
A client of Alarm has to instantiate an Alarm object with a specified amount
of time and a callback AlarmListener
object. Optionally an argument
to be passed on the callback can be specified.
Alarm alarm = new Alarm(5000, new AlarmListener() { public void alarm(Alarm anAlarm) { // do something here } }); // reschedule the alarm on the previously specified time. alarm.reschedule(); // reschedule the alarm on another time alarm.reschedule(3000); // cancel the callback before it is executed alarm.cancel();
Special effort has been made to enable cancellations or rescheduling of alarm calls by clients within a alarm callback.
Inner Class Summary | |
private static class |
Alarm.AlarmThread
Alarm timer thread. |
Field Summary | |
private static java.util.SortedSet |
alarms
map of scheduled alarms |
private static Alarm.AlarmThread |
alarmThread
the schedule thread |
private java.lang.Object |
arg
optional call-back argument |
private long |
deltaTimeMillis
delta between the moment of scheduling and expiration |
private static java.lang.String |
endLastExecute
contains the system time of the end of the execution of the last alarm |
private long |
expireTimeMillis
absolute system time of expiration |
private AlarmListener |
listener
alarm call-back listener |
private static java.lang.String |
startLastExecute
contains the system time of the begining of the execution of the last alarm |
Constructor Summary | |
Alarm(long aTimeMillis,
AlarmListener aListener)
Create an alarm call at a specified time from now. |
|
Alarm(long aTimeMillis,
AlarmListener aListener,
java.lang.Object anArgument)
Create an alarm call at a specified time from now. |
Method Summary | |
(package private) static void |
|
void |
cancel()
Cancel a scheduled alarm call. |
int |
compareTo(java.lang.Object anObject)
Compare the expiry time to that of another Alarm. |
private void |
execute()
Execute the alarm callback. |
static int |
getAlarmSize()
Retutn the number of currently pending Alarms. |
java.lang.Object |
getArgument()
Get the optional call-back argument. |
static java.lang.String |
getEndLastExecute()
Return the string representing the time the execution of the last invoked Alarm started. |
long |
getIntervalMillis()
Return the interval for the Alarm. |
private long |
getRemainingMillis()
Get the remaining millis before expiration. |
static java.lang.String |
getStartLastExecute()
Return the string representing the time the execution of the last invoked Alarm ended. |
private boolean |
isExpired()
Is this alarm call expired? |
void |
reschedule()
Reschedule an alarm call for the same time period as the previous schedule. |
void |
reschedule(long aTimeMillis)
Reschedule an alarm call for a given time period. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
Field Detail |
private static Alarm.AlarmThread alarmThread
private static java.util.SortedSet alarms
private static java.lang.String startLastExecute
private static java.lang.String endLastExecute
private java.lang.Object arg
private long deltaTimeMillis
private long expireTimeMillis
private AlarmListener listener
Constructor Detail |
public Alarm(long aTimeMillis, AlarmListener aListener)
aTimeMillis
- time in milliseconds from now of the alarm callaListener
- alarm call listenerpublic Alarm(long aTimeMillis, AlarmListener aListener, java.lang.Object anArgument)
aTimeMillis
- time in milliseconds from now of the alarm callaListener
- alarm call listeneranArgument
- argument that gets passed back to the listener during
the alarm call (might be null
)Method Detail |
public static int getAlarmSize()
public static java.lang.String getEndLastExecute()
public static java.lang.String getStartLastExecute()
public long getIntervalMillis()
public void cancel()
public int compareTo(java.lang.Object anObject)
compareTo
in interface java.lang.Comparable
anObject
- an alarm instancepublic java.lang.Object getArgument()
public void reschedule()
public void reschedule(long aTimeMillis)
aTimeMillis
- time in milliseconds from now of the alarm callprivate void execute()
private long getRemainingMillis()
private boolean isExpired()
static void()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |