KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > extensions > wsrm > AckTask


1 package extensions.wsrm;
2
3 import org.apache.axis.client.Call;
4 import org.apache.axis.message.SOAPEnvelope;
5
6 import java.util.List JavaDoc;
7 import java.util.ArrayList JavaDoc;
8
9 /**
10  * Created by IntelliJ IDEA.
11  * User: Glen
12  * Date: Oct 14, 2003
13  * Time: 10:18:53 PM
14  * To change this template use Options | File Templates.
15  */

16 public class AckTask implements Runnable JavaDoc {
17     static AckTask singleton = null;
18     public static synchronized AckTask getSingleton() {
19         if (singleton == null) {
20             singleton = new AckTask();
21             // Start the thread
22
new Thread JavaDoc(singleton).start();
23         }
24         return singleton;
25     }
26
27     List JavaDoc ackQueue = new ArrayList JavaDoc();
28
29     public void scheduleAck(Sequence seq) {
30         System.out.println("Acking to " + seq.endpoint);
31         try {
32             Thread.sleep(10000);
33         } catch (InterruptedException JavaDoc e) {
34             e.printStackTrace(); //To change body of catch statement use Options | File Templates.
35
}
36         synchronized (ackQueue) {
37             ackQueue.add(seq);
38             ackQueue.notifyAll();
39         }
40     }
41
42     public void run() {
43         while (true) {
44             synchronized (ackQueue) {
45                 while (ackQueue.isEmpty()) {
46                     try {
47                         ackQueue.wait();
48                     } catch (InterruptedException JavaDoc e) {
49                         e.printStackTrace(); //To change body of catch statement use Options | File Templates.
50
}
51                 }
52             }
53
54             while (!ackQueue.isEmpty()) {
55                 Sequence seq = (Sequence)ackQueue.get(0);
56                 synchronized (ackQueue) {
57                     ackQueue.remove(0);
58                 }
59
60                 try {
61                     generateAck(seq);
62                 } catch (Exception JavaDoc e) {
63                     System.out.println("Couldn't generate ack!");
64                     e.printStackTrace();
65                 }
66             }
67         }
68     }
69
70     public void generateAck(Sequence seq) throws Exception JavaDoc {
71         Call call = new Call(seq.endpoint);
72         SOAPEnvelope env = new SOAPEnvelope();
73         ReliableMessagingHandler.generateAck(env, seq);
74         call.setProperty("OneWay", Boolean.TRUE);
75         call.invoke(env);
76     }
77 }
78
Popular Tags