1 package net.walend.somnifugi; 2 3 import javax.jms.TopicPublisher ; 4 import javax.jms.Topic ; 5 import javax.jms.JMSException ; 6 import javax.jms.Message ; 7 import javax.jms.Destination ; 8 9 15 16 public class SomniTopicPublisher 17 extends SomniMessageProducer 18 implements TopicPublisher 19 { 20 private SomniTopic topic; 21 22 protected SomniTopicPublisher(SomniTopic topic,String name,String connectionClientID) 23 { 24 super(topic,name,connectionClientID); 25 this.topic = topic; 26 } 27 28 36 public Topic getTopic() 37 throws JMSException 38 { 39 synchronized(guard) 40 { 41 return topic; 42 } 43 } 44 45 65 public void publish(Message message) 66 throws JMSException 67 { 68 synchronized(guard) 69 { 70 publish(message,getDeliveryMode(),getPriority(),getTimeToLive()); 71 } 72 } 73 74 93 public void publish(Message jmsMessage,int deliveryMode,int priority,long timeToLive) 94 throws JMSException 95 { 96 publish(topic,jmsMessage,deliveryMode,priority,timeToLive); 97 } 98 99 122 public void publish(Topic topic, Message message) 123 throws JMSException 124 { 125 synchronized(guard) 126 { 127 publish(topic,message,getDeliveryMode(),getPriority(),getTimeToLive()); 128 } 129 } 130 131 152 public void publish(Topic jmsTopic,Message jmsMessage,int deliveryMode,int priority,long timeToLive) 153 throws JMSException 154 { 155 if(!(jmsMessage instanceof SomniMessage)) 156 { 157 throw new ClassCastException ("message must be an instance of SomniMessage, not "+jmsMessage.getClass().getName()); 158 } 159 if(!(jmsTopic instanceof SomniTopic)) 160 { 161 throw new ClassCastException ("topic must be an instance of SomniTopic, not "+jmsTopic.getClass().getName()); 162 } 163 164 SomniMessage message = (SomniMessage)jmsMessage; 165 SomniTopic topic = (SomniTopic)jmsTopic; 166 167 synchronized(guard) 168 { 169 try 170 { 171 setMessageDetails(message,deliveryMode,priority,timeToLive); 172 topic.getPuttable().put(message); 173 logSent(message,"published"); 174 } 175 catch(InterruptedException ie) 176 { 177 throw new SomniInterruptedException(ie,message,topic); 178 } 179 } 180 } 181 182 192 193 public Destination getDestination() throws JMSException 194 { 195 return getTopic(); 196 } 197 198 218 219 public void send(Message message) throws JMSException 220 { 221 throw new IllegalStateException ("I don't know that I'll ever fill this method in."); 222 } 223 224 245 246 public void send(Message message,int deliveryMode,int priority,long timeToLive) throws JMSException 247 { 248 throw new IllegalStateException ("I don't know that I'll ever fill this method in."); 249 } 250 251 274 275 public void send(Destination destination,Message message,int deliveryMode,int priority,long timeToLive) throws JMSException 276 { 277 throw new IllegalStateException ("I don't know that I'll ever fill this method in."); 278 } 279 280 305 306 public void send(Destination destination, Message message) throws JMSException 307 { 308 throw new IllegalStateException ("I don't know that I'll ever fill this method in."); 309 } 310 311 public void close() 312 throws JMSException 313 { 314 super.close(); 315 } 316 } 317 318 338 | Popular Tags |