1 package net.walend.somnifugi; 2 3 import javax.naming.Referenceable ; 4 import javax.naming.Reference ; 5 import javax.naming.NamingException ; 6 import javax.naming.Context ; 7 8 import javax.jms.QueueConnection ; 9 import javax.jms.QueueSession ; 10 import javax.jms.JMSException ; 11 import javax.jms.ConnectionConsumer ; 12 import javax.jms.Queue ; 13 import javax.jms.ServerSessionPool ; 14 import javax.jms.ResourceAllocationException ; 15 import javax.jms.Session ; 16 import javax.jms.Destination ; 17 import javax.jms.Topic ; 18 19 25 26 public class SomniQueueConnection 27 extends SomniConnection 28 implements QueueConnection , Referenceable 29 { 30 31 protected SomniQueueConnection(SomniQueueConnectionFactory factory,String clientID,Context context) 32 { 33 super(factory,clientID,context); 34 } 35 36 57 public QueueSession createQueueSession(boolean transacted,int acknowledgeMode) 58 throws JMSException 59 { 60 if(transacted) 61 { 62 throw new ResourceAllocationException ("somnifugi sessions are nontransactional."); 63 } 64 if((acknowledgeMode!=Session.AUTO_ACKNOWLEDGE)&&(acknowledgeMode!=Session.CLIENT_ACKNOWLEDGE)) 65 { 66 throw new ResourceAllocationException ("somnifugi sessions must be AUTO_ACKNOWLEDGE or CLIENT_ACKNOWLEDGE, not "+acknowledgeMode); 67 } 68 synchronized(guard) 69 { 70 SomniQueueSession session = new SomniQueueSession(createSessionName(),(SomniExceptionListener)getExceptionListener(),isStarted(),getContext(),acknowledgeMode,getClientID()); 71 addSession(session); 72 73 return session; 74 } 75 } 76 77 102 public ConnectionConsumer createConnectionConsumer(Queue queue,String messageSelector,ServerSessionPool sessionPool,int maxMessages) 103 throws JMSException 104 { 105 throw new UnsupportedOperationException ("Don't use somnifugi in an EJB app server. It plays with Threads."); 106 } 107 108 109 132 133 public Session createSession(boolean transacted,int acknowledgeMode) 134 throws JMSException 135 { 136 return createQueueSession(transacted,acknowledgeMode); 137 } 138 139 165 166 public ConnectionConsumer createConnectionConsumer(Destination destination, 167 String messageSelector, 168 ServerSessionPool sessionPool, 169 int maxMessages) 170 throws JMSException 171 { 172 throw new UnsupportedOperationException ("Don't use somnifugi in an EJB app server. It plays with Threads."); 173 } 174 175 202 203 public ConnectionConsumer createDurableConnectionConsumer(Topic topic, 204 String subscriptionName, 205 String messageSelector, 206 ServerSessionPool sessionPool, 207 int maxMessages) 208 throws JMSException 209 { 210 throw new IllegalStateException ("Don't use somnifugi in an EJB app server. It plays with Threads. Plus, why does a method in Connection take a Topic?"); 211 } 212 213 214 public Reference getReference() 216 throws NamingException 217 { 218 return new Reference (this.getClass().getName(),SomniQueueConnectionFactory.class.getName(),null); 219 } 220 221 } 222 223 243 | Popular Tags |