public class PSTimer extends ComObject implements java.lang.Runnable, FWDTimer, Deletable
PSTimer
object can be scheduled to run
repetitive tasks at fixed intervals. This is not fully compatible with ABL standard language,
it is an extension to 4GL specific to FWD.
To create a timer use the following syntax:
CREATE TIMER handle [ASSIGN [INTERVAL = n-millis] [CALLBACK = procedure] [ENABLED = auto-start]].Where:
yes
the timer is started automatically
at the moment it is created, otherwise a call to start()
or setting the
enabled
property to true
is needed to arm it.interval
when the timer is armed will force the timer to restart, he next event will
be fired after the timeout of the newly set interval. There are a few ways to stop the timer,
with small differences among them:
interval
to 0. It remain enabled, setting the interval
to a new
value will automatically arm it;enabled
to false
. The timer will stop until it is restarted by
setting the value back to yes
or calling start
;cease
, has the same effect like above;callback
to unknown will make the timer unable to call an event
procedure, but it will continue to tick.DELETE OBJECT th.
The PSTimer
object extends the ComObject
class. This means that the programmer
can use a comhandle
interface to access any properties and/or methods annotated as such
of the object, even they are known at compile time. The COM mode of operation is somewhat
compatible with legacy ActiveX objects from ABL.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
callback
The callback procedure in non-COM mode (legacy name).
|
private boolean |
enabled
Flags if this timer is enabled.
|
private int |
interval
The ticking interval, in milliseconds.
|
private boolean |
invalid
Flags if this object has been yet destroyed and is no longer valid.
|
private boolean |
isCom
Flags the operation mode.
|
private static java.util.logging.Logger |
LOG
The logger used for tracing internal events.
|
private long |
t0
A t0 timestamp used to relate all events in LOG.
|
private AssociatedThread |
timer
The background thread that does the power-horse work.
|
private boolean |
timerReset
Flags indicating whether this timer was reset while armed (
interval changed to
another valid value while timer was sleeping). |
Constructor and Description |
---|
PSTimer()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
AboutBox()
The emulation of the ActiveX
AboutBox legacy method. |
void |
cease()
Force the timer to cease firing events.
|
static void |
create(handle h)
Static factory method for initialization of a fresh new TIMER as an extension object.
|
void |
delete()
Perform actual delete of all resources.
|
private void |
fireEvent()
Calls the callback or the event procedure asynchronously.
|
character |
getCallback()
Gets the legacy name of the callback procedure to be called at fixed interval when running
in FWD extension mode (not as a COM).
|
integer |
getInterval()
Obtain the current
interval between two consecutive events. |
java.lang.String |
getName()
Obtain the name of the COM Object.
|
logical |
isEnabled()
Check whether this timer is armed.
|
private void |
log(java.lang.String s)
Logs information mostly for debugging purposes.
|
void |
release()
Perform actual delete of all resources.
|
void |
run()
The background worker thread.
|
void |
setCallback(character callback)
Sets the legacy name of the callback procedure to be called at fixed interval when running
in FWD extension mode (ignored when in COM mode).
|
void |
setCallback(java.lang.String callback)
Sets the legacy name of the callback procedure to be called at fixed interval when running
in FWD extension mode (ignored when in COM mode).
|
void |
setEnabled(boolean setOn)
Sets the value of the
Enabled property/attribute. |
void |
setEnabled(logical setOn)
Sets the value of the
Enabled property/attribute. |
void |
setInterval(long interval)
Sets the current
interval between two consecutive events. |
void |
setInterval(NumberType interval)
Sets the current
interval between two consecutive events. |
void |
start()
Starts the timer.
|
private void |
startWorker()
Worker method.
|
boolean |
valid()
Checks whether this object is valid.
|
getParentControlFrame, id, id, init, setParentControlFrame, unknown
private AssociatedThread timer
null
if this timer has
not been started yet, or if the object ws released/deleted.private volatile int interval
INTERVAL
property/attribute.
If it is zero, the timer is not enabled (does not fire). It is illegal to set it to a
negative value.private volatile boolean enabled
tick
event.private volatile boolean timerReset
interval
changed to
another valid value while timer was sleeping). In this case it must be re-initiated with
the new interval.private java.lang.String callback
unknown
/ null
if you want some ticks to be skipped. The
difference from setting the enabled to NO
is that in this case the timer is not
restarted.private boolean isCom
PSTimer
ActiveX object. There are two differences:
yes
in COM mode
and false
in extension mode. This means that in COM mode, setting the
INTERVAL
will automatically arm the timer, while in extension mode, one
need to explicitly set enabled
to yes
or invoke the start
method;callback
property is ignored and ABL compatible algorithm is used
to identify the proper event procedure to call. The legacy name of the procedure is
computed using <ControlFrame-name>.<ActiveX-name>.<Event-name>
.private boolean invalid
private static final java.util.logging.Logger LOG
private long t0
public PSTimer()
ComObject.init()
, after all the fields were correctly initialized.public static void create(handle h)
h
- The handle
to store the newly created object.public java.lang.String getName()
public void AboutBox()
AboutBox
legacy method. In ABL it will open a modal
dialog with the name of the ActiveX and its version. The emulated method is a NO-OP, except
for the optional log of the call.public logical isEnabled()
interval
is
also set to a strictly positive value.public void setEnabled(boolean setOn)
Enabled
property/attribute. If interval
property is
already set, the timer gets armed.setEnabled
in interface FWDTimer
setOn
- new value of the Enabled
property/attribute.public void setEnabled(logical setOn)
Enabled
property/attribute. If interval
property is
already set, the timer gets armed.setEnabled
in interface FWDTimer
setOn
- new value of the Enabled
property/attribute.public integer getInterval()
interval
between two consecutive events.getInterval
in interface FWDTimer
interval
property.public void setInterval(long interval) throws PropertyAccessException
interval
between two consecutive events. If the timer is already
enabled
, it will be automatically armed and will fire after interval
millis
elapses. Setting it to 0, will stop the timer. Setting to a negative value will lead to
an error message to be displayed.setInterval
in interface FWDTimer
interval
- The new interval between two timer events, in milliseconds.PropertyAccessException
public void setInterval(NumberType interval) throws PropertyAccessException
interval
between two consecutive events. If the timer is already
enabled
, it will be automatically armed and will fire after interval
millis
elapses. Setting it to 0, will stop the timer. Setting to a negative value will lead to
an error message to be displayed.setInterval
in interface FWDTimer
interval
- The new interval between two timer events, in milliseconds.PropertyAccessException
public character getCallback()
getCallback
in interface FWDTimer
public void setCallback(character callback)
unknown
the timer will
continue 'ticking' but since there is no known peer to call, nothing will happen. This
property can be set while the timer is active, without resetting it.setCallback
in interface FWDTimer
callback
- the new legacy name of the callback procedure.public void setCallback(java.lang.String callback)
unknown
the timer will
continue 'ticking' but since there is no known peer to call, nothing will happen. This
property can be set while the timer is active, without resetting it.setCallback
in interface FWDTimer
callback
- the new legacy name of the callback procedure.public void cease()
enabled
property to false
.
The name of the method was selected intentionally for the FWD extension since STOP
would create some syntactic incompatibility with standard ABL attributes.
public void start()
enabled
property to
true
. Note that timer will not be activated unless the interval
property
was set to a strictly positive value.public void release()
This is called from a com-handle when working as COM object.
public void delete()
This is called from a handle when working as FWD extension object.
public boolean valid()
valid
in interface WrappedResource
true
if this object is valid.private void startWorker()
AssociatedThread
is created and started. If already armed, calling this
will cause the current interval to be dropped, and a new schedule is performed for the
current interval
.public void run()
interval
milliseconds
and, if not interrupted, will trigger the event. In case of interruption, it will analyze
the internal state and rearm or wait for the timer to be re-enabled.run
in interface java.lang.Runnable
private void fireEvent()
ServerEvent
will be posted with LogicalTerminal.postServerEvent(com.goldencode.p2j.ui.client.event.ServerEvent)
. When
running as FWD extension, the callback
procedure is invoked, if set. When running as
a COM/ActiveX, a new ComEvent
event is dispatched through ComServer
, which
will use the ControlFrame
container, the name of this ComObject
and the
declared event name to compute the legacy name of teh procedure to call.private void log(java.lang.String s)
s
- The message to be logged.