1 23 package org.objectweb.joram.client.connector; 24 25 import javax.jms.*; 26 import javax.jms.IllegalStateException ; 27 import java.util.Vector ; 28 29 import org.objectweb.util.monolog.api.BasicLevel; 30 31 37 public class OutboundConnection implements javax.jms.Connection 38 { 39 40 ManagedConnectionImpl managedCx; 41 42 XAConnection xac; 43 44 boolean valid = true; 45 46 Vector sessions; 47 48 54 OutboundConnection(ManagedConnectionImpl managedCx, 55 XAConnection xac) { 56 57 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 58 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 59 "OutboundConnection(" + managedCx + 60 ", " + xac + ")"); 61 62 this.managedCx = managedCx; 63 this.xac = xac; 64 sessions = new Vector (); 65 } 66 67 71 public void setClientID(String clientID) throws JMSException { 72 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 73 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 74 this + " setClientID(" + clientID + ")"); 75 if (! valid) 76 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 77 78 throw new IllegalStateException ("Forbidden call on a component's " 79 + "connection."); 80 } 81 82 86 public void setExceptionListener(ExceptionListener listener) 87 throws JMSException { 88 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 89 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 90 this + " setExceptionListener(" + listener + ")"); 91 92 if (! valid) 93 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 94 95 throw new IllegalStateException ("Forbidden call on a component's " 96 + "connection."); 97 } 98 99 106 public Session createSession(boolean transacted, int acknowledgeMode) 107 throws JMSException { 108 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 109 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 110 this + " createSession(" + transacted + 111 ", " + acknowledgeMode + ")"); 112 113 if (! valid) 114 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 115 116 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 117 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 118 this + " createSession sess = " + managedCx.session); 119 120 Session sess = managedCx.session; 121 if (sess == null) 122 sess = xac.createSession(false, acknowledgeMode); 123 124 return new OutboundSession(sess, this, transacted); 125 } 126 127 131 public String getClientID() throws JMSException 132 { 133 if (! valid) 134 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 135 136 throw new IllegalStateException ("Forbidden call on a component's " 137 + "connection."); 138 } 139 140 146 public ConnectionMetaData getMetaData() throws JMSException 147 { 148 if (! valid) 149 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 150 151 return xac.getMetaData(); 152 } 153 154 158 public ExceptionListener getExceptionListener() throws JMSException 159 { 160 if (! valid) 161 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 162 163 throw new IllegalStateException ("Forbidden call on a component's " 164 + "connection."); 165 } 166 167 173 public void start() throws JMSException { 174 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 175 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " start()"); 176 177 if (! valid) 178 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 179 180 xac.start(); 181 182 for (int i = 0; i < sessions.size(); i++) { 183 OutboundSession session = (OutboundSession) sessions.get(i); 184 session.start(); 185 186 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 187 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " start session = " + session); 188 } 189 } 190 191 195 public void stop() throws JMSException { 196 197 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 198 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " stop()"); 199 200 if (! valid) 201 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 202 203 throw new IllegalStateException ("Forbidden call on a component's " 204 + "connection."); 205 } 206 207 211 public ConnectionConsumer 212 createConnectionConsumer(Destination destination, 213 String messageSelector, 214 ServerSessionPool sessionPool, 215 int maxMessages) 216 throws JMSException { 217 if (! valid) 218 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 219 220 throw new IllegalStateException ("Forbidden call on a component's " 221 + "connection."); 222 } 223 224 228 public ConnectionConsumer 229 createDurableConnectionConsumer(Topic topic, 230 String subscriptionName, 231 String messageSelector, 232 ServerSessionPool sessionPool, 233 int maxMessages) 234 throws JMSException 235 { 236 if (! valid) 237 throw new javax.jms.IllegalStateException ("Invalid connection handle."); 238 239 throw new IllegalStateException ("Forbidden call on a component's " 240 + "connection."); 241 } 242 243 249 public synchronized void close() throws JMSException { 250 valid = false; 251 252 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 253 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " close()"); 254 255 for (int i = 0; i < sessions.size(); i++) { 256 OutboundSession session = (OutboundSession) sessions.get(i); 257 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 258 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " close() session = " + session); 259 260 session.close(); 261 } 262 263 managedCx.closeHandle(this); 264 } 265 266 271 public boolean cnxEquals(Object obj) { 272 return (obj instanceof Connection) 273 && xac.equals(obj); 274 } 275 276 279 public void cleanup() { 280 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 281 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " cleanup()"); 282 org.objectweb.joram.client.jms.Connection cnx = 283 (org.objectweb.joram.client.jms.Connection) xac; 284 cnx.cleanup(); 285 } 286 287 public String toString() 288 { 289 return "OutboundConnection[" + xac.toString() + "]"; 290 } 291 } 292 | Popular Tags |