LegacySystem.jws Sample

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

Sample Location

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

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/timer/

Sample Source Code


01 package timer; 
02 
03 import java.util.Date;
04 import com.bea.control.TimerControl; 
05 
06 /**
07  <p>This web service is used by the AdvancedTimer sample.  It a mock
08  * version of a legacy system that lacks the ability to call you back when its
09  * operation is complete.  To get around this limitation, AdvancedTimer has to
10  * "poll" this service to determine when it's complete.</p>
11  
12  <p>This service has only a single operation that it can perform.  To start this
13  * operation running, call <b>start</b>.  Once <b>start</b> has been called, you can call
14  <b>isDone</b> to determine if the operation has completed.</p>
15  *
16  <p>We implement this operation by using a timer.  The timer will fire between
17  * 10 and 20 seconds after the operation is started.  Once the timer goes off,
18  * we will report the operation as completed.</p>
19  
20  * @common:target-namespace namespace="http://workshop.bea.com/LegacySystem"
21  */
22 public class LegacySystem implements com.bea.jws.WebService
23 
24     /**
25      <p>This variable stores whether the operation has completed yet.
26      * It is made persistent by the presence of a "<b>@common:conversation start</b>" tag.</p>
27      */
28     private boolean complete;
29     
30     /**
31      * @jc:timer
32      * @common:control
33      */
34     private com.bea.control.TimerControl timer;
35 
36     /**
37      <p>Starts a new instance of the operation running.  This operation will
38      * complete in between 10 and 15 seconds.</p>
39      *
40      @throws Exception  As thrown by TimerControl.start or TimerControl.setTimeoutIn.
41      *
42      * @common:operation
43      * @jws:conversation phase="start"
44      */
45     public void start() throws Exception
46     {
47         int delay = 10 (int)(11.0 * Math.random());
48 
49         // This will set the timeout to occur in between 10 and 20 seconds.
50         timer.setTimeout((long)delay);
51 
52         // This will tell the timer to call us back in the amount of time that
53         // we set above.  Don't forget this part!
54         timer.start();
55 
56         // We will not complete until the timer calls us back.
57         complete = false;
58     }
59 
60     /**
61      <p>Call this to determine if the operation has completed.</p>
62      *
63      * @returns Whether the operation has completed when called. 
64      *
65      * @common:operation
66      * @jws:conversation phase="continue"
67      */
68     public boolean isDone()
69     {
70         return complete;
71     }
72 
73     /** <p>When the timer calls us back, we have completed the operation.</p> */
74     private void timer_onTimeout(long time)
75     {
76         complete = true;
77     }
78 
79     /**
80      * @common:operation
81      * @jws:conversation phase="finish"
82      */
83     public void finish()
84     {
85     }
86   
87