public class FabricTimer
extends com.streamscape.sdo.AbstractNamedObject
Title: Framework Support Library
Description: Defines a Timer object which acts a Chronometer.
When a Timer is started it begins a countdown based on its specified time interval. The timer is managed by a
FabricTimerManager
that allows users to create, use and destroy timers.
Timers accept a FabricTimerTask
implementation as a parameter. The methods
of the task are called in response to a timer's changing states, allowing applications to react to timer events.
Timer can execute a task once or periodically several times.
Several timers are united to the Timer Group. Each group has own thread.
Timer contains a Map<String,Object>
which can be filled by user.
This map is available for timer's task during an execution.
Timer can be in the following states:
Copyright: Copyright (c) 2012
Company: StreamScape Technologies
DEFAULT_SERIAL_VERSION_ID
Modifier and Type | Method and Description |
---|---|
void |
addValue(java.lang.String key,
java.lang.Object value)
Adds the specified value with the specified key.
|
void |
cancel()
Cancels the timer.
|
void |
clearValues()
Removes all values.
|
java.lang.Object |
existsValue(java.lang.String key)
Checks if a value corresponding to the specified key exists.
|
long |
getDuration()
Returns the time elapsed after a starting of the timer.
|
java.lang.String |
getGroup()
Returns a name of the timer's group.
|
long |
getInterval()
Returns a time interval (in milliseconds) after which the timer executes its task.
|
java.lang.String |
getName()
Returns a name of the timer.
|
int |
getRemainingRepeatCount()
Returns the count of the task's executions remaining till a finishing of the timer.
|
long |
getRemainingTime()
Returns the time remaining till a next execution of the task.
|
int |
getRepeatCount()
Returns a count of periodical executions of the timer's task.
|
FabricTimerState |
getState()
Returns the current state of the timer.
|
java.lang.Object |
getValue(java.lang.String key)
Returns a value corresponding to the specified key.
|
java.util.List |
getValues()
Returns a list of all values with their keys.
|
void |
removeValue(java.lang.String key)
Removes a value corresponding to the specified key.
|
void |
reset()
Resets the timer.
|
void |
resume()
Resumes the suspended timer.
|
void |
start()
Starts the timer.
|
void |
start(java.util.Date startTime)
Starts the timer at the specified time.
|
void |
start(long delay)
Starts the timer after the specified delay (in milliseconds).
|
void |
stop()
Stops the timer.
|
void |
suspend()
Suspends the timer.
|
clone, getSerialVersionUID
public java.lang.String getGroup()
public java.lang.String getName()
getName
in interface NamedObject
getName
in class com.streamscape.sdo.AbstractNamedObject
public long getInterval()
public int getRepeatCount()
getInterval()
milliseconds after the previous execution.
Value -1
means that the task will be executed infinitely until a canceling.
public FabricTimerState getState()
public void start() throws FabricTimerException
First execution of the task will be performed in getInterval()
milliseconds after a starting.
FabricTimerException
- if the timer is already stopped.public void start(java.util.Date startTime) throws FabricTimerException
First execution of the task will be performed at the specified time. If the time is in the past the task will be executed immediately.
startTime
- the time at which the task will be executed first time.FabricTimerException
- if the timer is already stopped.public void start(long delay) throws FabricTimerException
First execution of the task will be performed after the specified delay.
delay
- the time period (in milliseconds) after which the task will be executed first time.FabricTimerException
- if the timer is already stopped or
if the delay is negative.public void stop()
public void cancel() throws FabricTimerException
getRemainingRepeatCount() == 1
), the timer will stop execution
and will switch to CANCELLED
state. After that it can be started again.
FabricTimerException
- if the timer is already stopped.public void reset() throws FabricTimerException
First execution of the task will be performed in getInterval()
milliseconds after a resetting.
FabricTimerException
- if the timer is already stopped.public void suspend() throws FabricTimerException
FabricTimerException
- if the timer is already stopped.public void resume() throws FabricTimerException
FabricTimerException
- if the timer is already stopped.public long getRemainingTime()
-1
.public int getRemainingRepeatCount()
-1
.public long getDuration()
-1
.public void addValue(java.lang.String key, java.lang.Object value)
key
- the key to be added.value
- the value to be added.public void removeValue(java.lang.String key)
key
- the key whose corresponding value is to be returned.public void clearValues()
public java.lang.Object existsValue(java.lang.String key)
key
- the key to be checked.true
if the corresponding value exists, false
otherwise.public java.lang.Object getValue(java.lang.String key)
key
- the key whose corresponding value is to be returned.null
if the value is not found.public java.util.List getValues()
Copyright © 2015-2024 StreamScape Technologies. All rights reserved.