1 57 58 package org.apache.wsif.util.jms; 59 60 import java.util.ArrayList ; 61 import java.util.Arrays ; 62 63 import javax.jms.JMSException ; 64 import javax.jms.Message ; 65 import javax.jms.Queue ; 66 import javax.jms.QueueReceiver ; 67 import org.apache.wsif.WSIFException; 68 import org.apache.wsif.logging.Trc; 69 70 74 public class JMS2HTTPBridgeDestination extends WSIFJMSDestination { 75 public static final String COLDSTART = "cold"; 76 public static final String WARMSTART = "warm"; 77 78 private boolean verbose; 79 private static final ArrayList allStarts = 80 new ArrayList (Arrays.asList(new Object [] { COLDSTART, WARMSTART })); 81 82 89 public JMS2HTTPBridgeDestination( 90 WSIFJMSFinder finder, 91 String altDestName, 92 long timeout, 93 String startType, 94 boolean verbose) 95 throws WSIFException { 96 super(finder, altDestName, timeout); 97 Trc.entry( 98 this, 99 finder, 100 altDestName, 101 new Long (timeout), 102 startType, 103 new Boolean (verbose)); 104 105 this.verbose = verbose; 106 107 readQ = writeQ; 109 writeQ = null; 110 111 if (!allStarts.contains(startType)) 112 throw new WSIFException("StartType must either be warm or cold"); 113 114 if (COLDSTART.equals(startType)) { 115 if (verbose) 116 System.out.println("Wiping messages off the read queue"); 117 Message msg = null; 118 try { 119 QueueReceiver rec = session.createReceiver(readQ); 120 for (;;) { 121 msg = rec.receive(100); 122 if (msg != null) { 123 if (verbose) 124 System.out.println("Removing an input message"); 125 } else 126 break; 127 } 128 } catch (Exception ignored) { 129 Trc.exception(ignored); 130 } 131 } 132 Trc.exit(); 133 } 134 135 140 public void listen(WSIFJMSListener listener) throws WSIFException { 141 Trc.entry(this, listener); 142 listen(listener, readQ); 143 Trc.exit(); 144 } 145 146 152 public void listen(WSIFJMSListener listener, Queue queue) 153 throws WSIFException { 154 Trc.entry(this, listener, queue); 155 areWeClosed(); 156 157 try { 158 QueueReceiver qr = session.createReceiver(queue); 159 qr.setMessageListener(listener); 160 connection.setExceptionListener(listener); 161 162 connection.start(); 163 164 for (int i = 1; !Thread.interrupted(); i++) { 165 Thread.yield(); 166 Thread.sleep(5000); 167 if (verbose) 168 System.out.println("Waiting... " + i); 169 } 170 } catch (JMSException je) { 171 Trc.exception(je); 172 throw WSIFJMSConstants.ToWsifException(je); 173 } catch (InterruptedException ignored) { 174 Trc.exception(ignored); 175 System.out.println("Exitting"); 176 } 177 Trc.exit(); 178 } 179 180 public void setReplyToQueue() throws WSIFException { 182 Trc.entry(this); 183 Trc.exit(); 184 } 185 186 public void setReplyToQueue(String replyTo) throws WSIFException { 187 Trc.entry(this, replyTo); 188 Trc.exit(); 189 } 190 191 195 public void setReplyToQueue(Queue replyTo) throws WSIFException { 196 Trc.entry(this, replyTo); 197 areWeClosed(); 198 199 if (writeQ == null) 200 writeQ = replyTo; 201 else if (!writeQ.equals(replyTo)) { 202 203 if (sender != null) { 204 try { 205 sender.close(); 206 } catch (Exception e) { 207 Trc.exception(e); 208 } 209 sender = null; 210 } 211 writeQ = replyTo; 212 } 213 Trc.exit(); 214 } 215 } | Popular Tags |