![]() |
![]() |
![]() |
![]() |
@Control private TimerControl timerControl1;and the default name of the new control (timerControl1) is highlighted.
When you create a timer control, Workshop also inserts a line at the top of your .java file to import the timer control class, com.bea.control.TimerControl.
Note that you cannot create a new timer control in a page flow or a Java Server Page (JSP file), because the timer control defines a callback, the onTimeout method, but page flow and JSP pages cannot accept callbacks.
Before using a timer control, you must specify when the timer elapses. If you do not specify when the timer elapses, the timer control will time out immediately (i.e., it will default to zero seconds). Elapsed time is specified in an additional annotation @TimerControl.TimerSettings() that is inserted into your code. Typically you will not edit the annotation manually but instead will use the Properties view to set property values.
For relative times, you can specify the timeout or the repeated time interval from the Properties view, which is available in the J2EE perspective. Absolute times must be specified by calling the control's method(s) as described in Setting an Absolute Timer with a Method Call.
To set a relative timeout or recurring time interval:
Note that you should set ONLY ONE of timeout, timeoutSeconds and only ONE of repeatsEvery, or repeatsEverySeconds. If you set both values, the xxxSeconds value will be used.
When entering timeout or recurring time values, you must specify the relative time as a text string--integers followed by case-insensitive time units. These time units can be separated by spaces.
For example,
1 hour 30 min
means one hour and 30 minutes and
30 s
means 30 seconds.
The following time string is a valid duration specification that exercises all the time units, spelled out fully:
99 years 11 months 13 days 23 hours 43 minutes 51 seconds
This example creates a timer control which will elapse in almost 100 years.
Units may also be truncated. For example, valid truncations of "months" are "month", "mont", "mon", "mo", and "m". If both months and minutes are specified, use long enough abbreviations to be unambiguous.
Text strings may also be in ISO 8601 extended format with the string "p" (case insensitive) at the beginning of a text string. If it is present, then single-letter abbreviations and no spaces must be used and parts must appear in the order y m d h m s. (http://www.w3.org/TR/xmlschema-2/#duration)
The following timer control declaration is equivalent to the previous example, but uses the fully truncated form:
P99Y11Mo13D23H43M51S
Durations are computed according to Gregorian calendar rules, so if today is the 17th of the month, 3 months from now is also the 17th of the month. If the target month is shorter and doesn't have a corresponding day (for example, no February 31), then the closest day in the same month is used (for example, February 28 in a normal year, February 29 in a leap year).
The timer control interface has three properties:
![]() |
![]() |
![]() |
||||||||||||||||||||
![]() |
|
![]() |
||||||||||||||||||||
![]() |
![]() |
![]() |
To set a payload that will be supplied to the callback handler during a timeout event, call the
setPayload(Serializable payload)
method before starting the timer. Calling this method after the timer is started will have no effect. Since the payload is serializable, you must be careful that the class that the serializable represents still exists, so that the object can be deserialized.
You can configure a timer control to fire at an absolute time by setting the TimeoutAt property of the TimerControl interface by calling setTimeoutAt().
The setTimeoutAt method configures the timer to fire an event as soon as possible on or after the supplied absolute time. If you supply an absolute time in the past, the timer will fire as soon as possible.
If setTimeoutAt is called while the timer is already running, it will have no effect until the timer is stopped and restarted.
The setTimeoutAt method takes as its argument a java.util.Date object. Please see the documentation for the java.util.Date class to learn how to manipulate Date objects. Other Java classes that are useful when dealing with Date are java.util.GregorianCalendar and java.text.SimpleDateFormat.
The getTimeoutAt method returns the time at which the timer is next scheduled to fire, if the repeats-every attribute is set to a value greater than zero. If the repeats-every attribute is set to zero, then the getTimeoutAt method returns the value set by the setTimeoutAt method or the value set in the timeout attribute. If you call the getTimeoutAt method from within the onTimeout callback handler, the first timeout has already fired, so getTimeoutAt will return either the time of the next timeout or the time of the first timeout if the timer is not set to repeat.
The following code snippet calls the setTimeoutAt method to specify that the first timeout fires at thirty seconds past the current minute, then calls the setRepeatsEvery method to specify that the timer subsequently fires every sixty seconds.
@Control
private TimerControl tTimer;
@WebMethod() @Conversation(value= Conversation.Phase.START) public void StartTimer() { Calendar cd = new GregorianCalendar(); cd.set(cd.SECOND, 30); tTimer.setTimeoutAt(cd.getTime()); tTimer.setRepeatsEvery(60); tTimer.start(); }
You can specify other settings of a timer control in J2EE perspective by setting the control's properties in the Properties view. For example, if you highlight the name of the timer control instance named _timer in the code editor, the Properties view displays the control's properties.
These properties correspond to attributes of the @TimerControl.TimerSettings annotation, which identifies the timer control in your code. The @TimerControl.TimerSettings annotation has the following properties:
When you create a new timer control, its declaration appears in the source file. The following code snippet is an example of what a typical timer control declaration looks like:
import com.bea.control.TimerControl; ... @TimerControl.TimerSettings(repeatsEverySeconds=5) @Control private TimerControl delayTimer;
The actual attributes that are present on the @TimerControl() annotation depend on the values you specify for the properties in the Properties view.
The @Control annotation informs Workshop that the associated declaration is a control. Without this annotation, the control is not properly connected to supporting code and will not function.
The @TimerControl() annotation controls the behavior of the timer control. All of the attributes of the @TimerControl() annotation are optional and have default values.
The timer control, named delayTimer in the example above, is declared as an instance of TimerControl.
![]() ![]() |