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 ; 7 import java.util.ArrayList ; 8 9 16 public class AckTask implements Runnable { 17 static AckTask singleton = null; 18 public static synchronized AckTask getSingleton() { 19 if (singleton == null) { 20 singleton = new AckTask(); 21 new Thread (singleton).start(); 23 } 24 return singleton; 25 } 26 27 List ackQueue = new ArrayList (); 28 29 public void scheduleAck(Sequence seq) { 30 System.out.println("Acking to " + seq.endpoint); 31 try { 32 Thread.sleep(10000); 33 } catch (InterruptedException e) { 34 e.printStackTrace(); } 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 e) { 49 e.printStackTrace(); } 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 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 { 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 |