EventSchedulerTest.jws Sample

This topic inludes the source code for the EventSchedulerTest.jws Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/ControlDevKit/ControlTest/featuresTests/

Sample Source Code


01 package featuresTests; 
02 
03 import com.bea.control.JwsContext;
04 import java.util.Date;
05 
06 /* 
07  * This web service uses the EventScheduler control to request notification
08  * after a specified interval. This service pass the interval from the client
09  * to the control, which in turn schedules a callback based on the interval.
10  */
11 public class EventSchedulerTest implements com.bea.jws.WebService
12 
13     public Callback callback;
14 
15     /**
16      * @common:control
17      */
18     private controlEvents.EventScheduler scheduleControl;
19 
20     /** @common:context */ 
21     JwsContext context; 
22 
23     /**
24      * The setWakeUpCall method provides a place for clients to specify the time
25      * after which they would like to receive the call.
26      
27      * To test control, run the web service. Enter a value in milliseconds
28      * as the intervalInMilliseconds parameter (eg, 5000 for 5 seconds).
29      * Click the setWakeUpCall button, then click Refresh until a response
30      * is displayed.
31      
32      * @common:operation
33      * @jws:conversation phase="start"
34      */
35     public void setWakeUpCall(long intervalInMilliseconds)
36     {
37         scheduleControl.setAlarm(intervalInMilliseconds);
38     }
39 
40     /*
41      * This callback handler receives the alarm notification from the 
42      * EventScheduler control. It packages the time value received
43      * into a message, then sends the message to its client through
44      * its onTimeToWakeUp callback.
45      */
46     public void scheduleControl_onAlarmRinging(java.lang.String responseMessage, long time)
47     {
48         callback.onTimeToWakeUp(responseMessage + " You scheduled a wake-up call for " +
49             new Date(time).toLocaleString() ". It is now " new Date().toLocaleString());
50     }
51 
52     /**
53      * The cancelWakeUp method provides a way for clients to cancel
54      * the wake up call. This calls an EventScheduler method that
55      * cancels the scheduled callback.
56      
57      * @common:operation
58      * @jws:conversation phase="finish"
59      */
60     public void cancelWakeUp()
61     {
62         scheduleControl.cancelAlarm();
63     }
64 
65     /*
66      * The onTimeToWakeUp callback notifies clients that the interval has
67      * passed.
68      */
69     public interface Callback
70     {
71         /**
72          * @jws:conversation phase="finish"
73          */
74         void onTimeToWakeUp(String response);
75     }
76