1 package net.walend.somnifugi; 2 3 import javax.naming.Context ; 4 import javax.naming.NamingException ; 5 6 import javax.jms.QueueSession ; 7 import javax.jms.Queue ; 8 import javax.jms.JMSException ; 9 import javax.jms.QueueReceiver ; 10 import javax.jms.QueueSender ; 11 import javax.jms.QueueBrowser ; 12 import javax.jms.TemporaryQueue ; 13 import javax.jms.Destination ; 14 import javax.jms.MessageProducer ; 15 import javax.jms.MessageConsumer ; 16 import javax.jms.Topic ; 17 import javax.jms.TopicSubscriber ; 18 import javax.jms.TemporaryTopic ; 19 import javax.jms.InvalidDestinationException ; 20 21 27 28 public class SomniQueueSession 29 extends SomniSession 30 implements QueueSession 31 { 32 private int tempCount=0; 33 34 protected SomniQueueSession(String name,SomniExceptionListener exceptionLisetener,boolean started,Context context,int acknowledgeMode,String connectionClientID) 35 { 36 super(name,exceptionLisetener,started,context,acknowledgeMode,connectionClientID); 37 } 38 39 60 public Queue createQueue(String queueName) 61 throws JMSException 62 { 63 return SomniQueueCache.IT.getQueue(queueName,getContext()); 64 } 65 66 75 public QueueReceiver createReceiver(Queue queue) 76 throws JMSException 77 { 78 SomniQueue aqueue = (SomniQueue)queue; 79 80 synchronized(guard) 81 { 82 checkClosed(); 83 String consumerName = createConsumerName(aqueue.getName(),"Receiver"); 84 85 SomniQueueReceiver result = new SomniQueueReceiver((SomniQueue)queue,consumerName,getExceptionListener(),this); 86 addConsumer(result); 87 return result; 88 } 89 } 90 91 107 public QueueReceiver createReceiver(Queue queue,String messageSelectorString) 108 throws JMSException 109 { 110 SomniQueue aqueue = (SomniQueue)queue; 111 SomniMessageSelector messageSelector = new SQL92MessageSelector(messageSelectorString); 112 113 synchronized(guard) 114 { 115 checkClosed(); 116 String consumerName = createConsumerName(aqueue.getName(),"Receiver"); 117 118 SomniQueueReceiver result = new SomniQueueReceiver((SomniQueue)queue,consumerName,getExceptionListener(),messageSelector,this); 119 addConsumer(result); 120 return result; 121 } 122 } 123 124 134 public QueueSender createSender(Queue queue) 135 throws JMSException 136 { 137 synchronized(guard) 138 { 139 checkClosed(); 140 SomniQueueSender result = new SomniQueueSender((SomniQueue)queue,createProducerName(queue.getQueueName(),"Sender"),getConnectionClientID()); 141 addProducer(result); 142 return result; 143 } 144 } 145 146 155 public QueueBrowser createBrowser(Queue queue) 156 throws JMSException 157 { 158 return new SomniQueueBrowser((SomniQueue)queue); 159 } 160 161 176 public QueueBrowser createBrowser(Queue queue,String messageSelectorString) 177 throws JMSException 178 { 179 return new SomniQueueBrowser((SomniQueue)queue,messageSelectorString); 180 } 181 182 190 public TemporaryQueue createTemporaryQueue() 191 throws JMSException 192 { 193 String tempName; 194 synchronized(guard) 195 { 196 tempName = getName()+":temp"+tempCount; 197 tempCount++; 198 } 199 SomniTemporaryQueue queue = new SomniTemporaryQueue(tempName,ChannelFactoryCache.IT.getChannelFactory(tempName,getContext(),true),getContext()); 200 SomniQueueCache.IT.putTemporaryQueue(queue); 201 202 return queue; 203 } 204 205 207 227 228 public MessageProducer createProducer(Destination destination) throws JMSException 229 { 230 try 231 { 232 return createSender((Queue )destination); 233 } 234 catch(ClassCastException cce) 235 { 236 throw new InvalidDestinationException ("destination must be a Queue, not a "+destination.getClass().getName(),cce.getMessage()); 237 } 238 } 239 240 241 255 256 public MessageConsumer createConsumer(Destination destination) throws JMSException 257 { 258 try 259 { 260 return createReceiver((Queue )destination); 261 } 262 catch(ClassCastException cce) 263 { 264 throw new InvalidDestinationException ("destination must be a Queue, not a "+destination.getClass().getName(),cce.getMessage()); 265 } 266 } 267 268 269 295 public MessageConsumer createConsumer(Destination destination, java.lang.String messageSelector) 296 throws JMSException 297 { 298 try 299 { 300 return createReceiver((Queue )destination,messageSelector); 301 } 302 catch(ClassCastException cce) 303 { 304 throw new InvalidDestinationException ("destination must be a Queue, not a "+destination.getClass().getName(),cce.getMessage()); 305 } 306 } 307 308 309 346 public MessageConsumer createConsumer(Destination destination,String messageSelector,boolean NoLocal) 347 throws JMSException 348 { 349 if(NoLocal) 351 { 352 throw new UnsupportedOperationException ("You're using NoLocal in Somnifugi? That's a pretty boring consumer."); 353 } 354 try 355 { 356 return createReceiver((Queue )destination,messageSelector); 357 } 358 catch(ClassCastException cce) 359 { 360 throw new InvalidDestinationException ("destination must be a Queue, not a "+destination.getClass().getName(),cce.getMessage()); 361 } 362 } 363 364 385 386 public Topic createTopic(String topicName) throws JMSException 387 { 388 throw new IllegalStateException ("Don't use a QueueSession to work with Topics"); 389 } 390 391 401 403 439 440 public TopicSubscriber createDurableSubscriber(Topic topic,String name) 441 throws JMSException 442 { 443 throw new IllegalStateException ("Don't use a QueueSession to work with Topics"); 444 } 445 446 447 489 490 public TopicSubscriber createDurableSubscriber(Topic topic,String name,String messageSelector,boolean noLocal) 491 throws JMSException 492 { 493 throw new IllegalStateException ("Don't use a QueueSession to work with Topics"); 494 } 495 496 497 507 508 public TemporaryTopic createTemporaryTopic() throws JMSException 509 { 510 throw new IllegalStateException ("Don't use a QueueSession to work with Topics"); 511 } 512 513 514 534 535 public void unsubscribe(String name) throws JMSException 536 { 537 throw new IllegalStateException ("Don't use a QueueSession to work with Topics"); 538 } 539 540 541 } 542 543 563 | Popular Tags |