Timer controls are used within conversational, stateful web services. Conversational web services have three phases: start, continue, and finish.
To use a timer in a conversational web service, after declaring the timer control as described in Setting up a Timer Control, you must implement a conversational web service to access the timer control. The minimum requirements to access a timer control are:
Conversational web services must implement the java.io.Serializable interface. To set this in your web service, on the class definition line for your web service, insert implements Serializable so that the class definition looks something like this:
public class TimerService implements Serializable {
This will cause an error marker to appear in the marker bar on the class declaration line. Right click on the error marker and choose Quick Fix.
Right click on the error marker and choose Quick Fix. The Quick Fix pull-down will appear:
Click Import Serializable and press Enter and a new import line will be generated to resolve the error.
A conversational web service differs from a regular web service in only one way: the Conversation property is set to START, CONTINUE or FINISH. A web service typically has three operations:
To define a conversational web method, right click on the code editor window and click Insert > Web Method. With the name of the new web method highlighted, click on the Conversation setting in the Properties view. Use the pulldown to set the conversational state for the method.
Once you have declared and configured a timer control, you can invoke its methods from within your application to start and stop the timer and to change its configuration. For complete information on each method, see TimerControl Interface.
The following list contains the methods of the TimerControl interface that you can use to start and stop the timer:
In addition to the web methods that start/stop the timer, the web service must provide for callbacks when the timer elapses.
The timer control defines one callback: onTimeout. You can add code to the callback event handler to run when the timer fires. The callback event handler for the onTimout event is named timerName_onTimeout, where timerName is the name of the timer control instance.
The callback event handler takes two parameters: the time in seconds since the timer was started and the payload. Note that this is not the same as the time at which the callback handler executes. A delay may occur between timer control expiration and callback handler invocation, depending on the system load.
To create the callback event handler for a timer control's onTimeout callback, right click on the code window and choose Insert > Control Event Handler. Workshop creates a callback event handler and places the cursor in the callback event handler.