1 package net.walend.somnifugi; 2 3 import javax.jms.QueueSender ; 4 import javax.jms.Queue ; 5 import javax.jms.JMSException ; 6 import javax.jms.Message ; 7 import javax.jms.Destination ; 8 9 15 16 public class SomniQueueSender 17 extends SomniMessageProducer 18 implements QueueSender 19 { 20 private SomniQueue queue; 21 22 protected SomniQueueSender(SomniQueue queue,String name,String connectionClientID) 23 { 24 super(queue,name,connectionClientID); 25 this.queue = queue; 26 } 27 28 36 public Queue getQueue() 37 throws JMSException 38 { 39 synchronized(guard) 40 { 41 return queue; 42 } 43 } 44 45 64 public void send(Message message) 65 throws JMSException 66 { 67 synchronized(guard) 68 { 69 send(message,getDeliveryMode(),getPriority(),getTimeToLive()); 70 } 71 } 72 73 91 public void send(Message jmsMessage,int deliveryMode,int priority,long timeToLive) 92 throws JMSException 93 { 94 send(queue,jmsMessage,deliveryMode,priority,timeToLive); 95 } 96 97 119 public void send(Queue queue, Message message) 120 throws JMSException 121 { 122 synchronized(guard) 123 { 124 send(queue,message,getDeliveryMode(),getPriority(),getTimeToLive()); 125 } 126 } 127 128 148 public void send(Queue jmsQueue,Message jmsMessage,int deliveryMode,int priority,long timeToLive) 149 throws JMSException 150 { 151 if(!(jmsMessage instanceof SomniMessage)) 152 { 153 throw new ClassCastException ("message must be an instance of SomniMessage, not "+jmsMessage.getClass().getName()); 154 } 155 if(!(jmsQueue instanceof SomniQueue)) 156 { 157 throw new ClassCastException ("queue must be an instance of SomniQueue, not "+jmsQueue.getClass().getName()); 158 } 159 SomniMessage message = (SomniMessage)jmsMessage; 160 SomniQueue queue = (SomniQueue)jmsQueue; 161 162 synchronized(guard) 163 { 164 try 165 { 166 setMessageDetails(message,deliveryMode,priority,timeToLive); 167 message = message.copy(queue.getCopyMode()); 168 169 queue.getPuttable().put(message); 170 logSent(message,"sent"); 171 } 172 catch(InterruptedException ie) 173 { 174 throw new SomniInterruptedException(ie,message,queue); 175 } 176 } 177 } 178 179 189 190 public Destination getDestination() throws JMSException 191 { 192 return getQueue(); 193 } 194 195 218 219 public void send(Destination destination,Message message,int deliveryMode,int priority,long timeToLive) throws JMSException 220 { 221 throw new UnsupportedOperationException ("I don't know that I'll ever fill this method in."); 222 } 223 224 249 250 public void send(Destination destination, Message message) throws JMSException 251 { 252 throw new UnsupportedOperationException ("I don't know that I'll ever fill this method in."); 253 } 254 255 256 public void close() 257 throws JMSException 258 { 259 super.close(); 260 } 261 262 263 } 264 265 285 | Popular Tags |