SlowService.jws Sample

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

Sample Location

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

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/controlFactory/

Sample Source Code


01 package controlFactory; 
02 
03 /**
04  <p>A dummy service that represents a back end service
05  * that takes an psuedo-random amount of time to do its
06  * work.</p>
07  * @common:target-namespace namespace="http://workshop.bea.com/SlowService"
08  */
09 
10 public class SlowService implements com.bea.jws.WebService
11 
12     /**
13      * @jc:timer timeout="5 seconds"
14      * @common:control
15      */
16     private com.bea.control.TimerControl delayTimer;
17 
18     String m_sName;
19 
20     public Callback callback;
21 
22     public interface Callback
23     {
24         /**
25          * Callback that is sent to the client when this
26          * service is done doing its work.
27          
28          * @jws:conversation phase="finish"
29          */
30         public void infoReady(String name);
31     }
32 
33     
34     /**
35      <p>The request from the client to do some work. After some
36      * amount of time, the infoReady callback will be sent to the
37      * client.</p>
38      
39      * @common:operation
40      * @jws:conversation phase="start"
41      */
42     public long requestInfo(String name)
43     {
44         m_sName = name;
45         
46         // compute a random delay between 5 and 15 seconds
47         long delay = (long)(Math.random() 10.0);
48         
49         // set the timeout on the timer control.
50         // this overrides the value set with the @jc:timer tag.
51         delayTimer.setTimeout(delay);
52         
53         // start the timer
54         delayTimer.start();
55         
56         // return the time it will take for this service to do its work
57         return delay;
58     }
59 
60     /**
61      * Callback handler for the timer control's onTimeout
62      * callback.  This indicates that the work this service
63      * does is complete and the client should be notified
64      * via the infoReady callback.
65      */
66     private void delayTimer_onTimeout(long time)
67     {
68         // send the infoReady callback to the client
69         callback.infoReady(m_sName);
70     }
71   
72