KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > connector > ManagedConnectionImpl


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - ScalAgent Distributed Technologies
4  * Copyright (C) 2004 - Bull SA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (Bull SA)
22  * Contributor(s): Nicolas Tachker (Bull SA)
23  * Florent Benoit (Bull SA)
24  */

25 package org.objectweb.joram.client.connector;
26
27 import javax.jms.JMSException JavaDoc;
28 import javax.jms.Session JavaDoc;
29 import javax.jms.XAConnection JavaDoc;
30 import javax.jms.XAQueueConnection JavaDoc;
31 import javax.jms.XASession JavaDoc;
32 import javax.jms.XATopicConnection JavaDoc;
33 import javax.resource.ResourceException JavaDoc;
34 import javax.resource.spi.CommException JavaDoc;
35 import javax.resource.spi.ConnectionEvent JavaDoc;
36 import javax.resource.spi.ConnectionEventListener JavaDoc;
37 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
38 import javax.resource.spi.IllegalStateException JavaDoc;
39 import javax.resource.spi.LocalTransactionException JavaDoc;
40 import javax.resource.spi.ManagedConnectionMetaData JavaDoc;
41 import javax.resource.spi.ResourceAdapterInternalException JavaDoc;
42 import javax.resource.spi.SecurityException JavaDoc;
43 import javax.transaction.xa.XAResource JavaDoc;
44
45 import java.io.PrintWriter JavaDoc;
46 import java.util.Vector JavaDoc;
47
48 import org.objectweb.util.monolog.api.BasicLevel;
49
50 /**
51  * A <code>ManagedConnectionImpl</code> instance wraps a physical connection
52  * to an underlying JORAM server, and provides "handles" for handling this
53  * physical connection.
54  */

55 public class ManagedConnectionImpl
56              implements javax.resource.spi.ManagedConnection JavaDoc,
57                         javax.resource.spi.LocalTransaction JavaDoc,
58                         javax.jms.ExceptionListener JavaDoc
59 {
60   /** Central adapter authority. */
61   private JoramAdapter ra;
62
63   /** Physical connection to the JORAM server. */
64   private XAConnection JavaDoc cnx = null;
65   /** Vector of connection handles. */
66   private Vector JavaDoc handles;
67   /** Vector of condition event listeners. */
68   private Vector JavaDoc listeners;
69   /** <code>true</code> if a local transaction has been started. */
70   private boolean startedLocalTx = false;
71   /** Connection meta data. */
72   private ManagedConnectionMetaDataImpl metaData = null;
73   /** Out stream for error logging and tracing. */
74   private PrintWriter JavaDoc out = null;
75
76   /** <code>true</code> if the connection is valid. */
77   private boolean valid = false;
78
79   /** hashCode */
80   private int hashCode = -1;
81
82   /** Underlying JORAM server host name. */
83   String JavaDoc hostName;
84   /** Underlying JORAM server port number. */
85   int serverPort;
86   /** Messaging mode (PTP or PubSub or Unified). */
87   String JavaDoc mode;
88   /** User identification. */
89   String JavaDoc userName;
90   /**
91    * Unique session for the use of managed components, involved in local or
92    * distributed transactions.
93    */

94   Session JavaDoc session = null;
95
96   /**
97    * Creates a <code>ManagedConnectionImpl</code> instance wrapping a
98    * physical connection to the underlying JORAM server.
99    *
100    * @param ra Central adapter authority.
101    * @param cnx Physical connection to the JORAM server.
102    * @param hostName JORAM server host name.
103    * @param serverPort JORAM server port number.
104    * @param userName User identification.
105    */

106   ManagedConnectionImpl(JoramAdapter ra,
107                         XAConnection JavaDoc cnx,
108                         String JavaDoc hostName,
109                         int serverPort,
110                         String JavaDoc userName) {
111     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
112       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, "ManagedConnectionImpl(" + ra +
113                                     ", " + cnx +
114                                     ", " + hostName +
115                                     ", " + serverPort +
116                                     ", " + userName + ")");
117
118     this.ra = ra;
119     this.cnx = cnx;
120     this.hostName = hostName;
121     this.serverPort = serverPort;
122     this.userName = userName;
123
124     if (cnx instanceof XAQueueConnection JavaDoc)
125       mode = "PTP";
126     else if (cnx instanceof XATopicConnection JavaDoc)
127       mode = "PubSub";
128     else
129       mode = "Unified";
130
131     try {
132       cnx.setExceptionListener(this);
133     }
134     catch (JMSException JavaDoc exc) {}
135
136     handles = new Vector JavaDoc();
137     listeners = new Vector JavaDoc();
138
139     valid = true;
140
141     hashCode = -1;
142
143     ra.addProducer(this);
144   }
145
146
147   /**
148    * Returns a new <code>OutboundConnection</code> instance for handling the
149    * physical connection.
150    *
151    * @exception CommException If the wrapped physical connection is lost.
152    */

153   public Object JavaDoc getConnection(javax.security.auth.Subject JavaDoc subject,
154                               ConnectionRequestInfo JavaDoc cxRequestInfo)
155                 throws ResourceException JavaDoc {
156     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
157       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
158                                     this + " getConnection(" + subject +
159                                     ", " + cxRequestInfo + ")");
160
161     if (! isValid()) {
162         if (out != null)
163             out.print("Physical connection to the underlying JORAM server has been lost.");
164       throw new CommException JavaDoc("Physical connection to the underlying "
165                               + "JORAM server has been lost.");
166     }
167
168     OutboundConnection handle;
169
170     if (cnx instanceof XAQueueConnection JavaDoc)
171       handle = new OutboundQueueConnection(this, (XAQueueConnection JavaDoc) cnx);
172     else if (cnx instanceof XATopicConnection JavaDoc)
173       handle = new OutboundTopicConnection(this, (XATopicConnection JavaDoc) cnx);
174     else
175       handle = new OutboundConnection(this, cnx);
176
177     handles.add(handle);
178
179     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
180       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
181                                     this + " getConnection handles = " + handles);
182     return handle;
183   }
184
185   /**
186    * Dissociates a given connection handle and associates it to this
187    * managed connection.
188    *
189    * @exception CommException If the wrapped physical connection is lost.
190    * @exception ResourceException If the provided handle is invalid.
191    */

192   public void associateConnection(Object JavaDoc connection)
193     throws ResourceException JavaDoc {
194     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
195       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
196                                     this + " associateConnection(" + connection + ")");
197
198     if (! isValid()) {
199         if (out != null)
200             out.print("Physical connection to the underlying JORAM server has been lost.");
201       throw new CommException JavaDoc("Physical connection to the underlying "
202                               + "JORAM server has been lost.");
203     }
204
205     if (! (connection instanceof OutboundConnection)) {
206         if (out != null)
207             out.print("The provided connection handle is not a JORAM handle.");
208       throw new ResourceException JavaDoc("The provided connection handle is not "
209                                   + "a JORAM handle.");
210     }
211
212     OutboundConnection newConn = (OutboundConnection) connection;
213     newConn.managedCx = this;
214     newConn.xac = (org.objectweb.joram.client.jms.XAConnection) cnx;
215   }
216
217   /** Adds a connection event listener. */
218   public void addConnectionEventListener(ConnectionEventListener JavaDoc listener)
219   {
220     listeners.add(listener);
221   }
222
223   /** Removes a connection event listener. */
224   public void removeConnectionEventListener(ConnectionEventListener JavaDoc listener)
225   {
226     listeners.remove(listener);
227   }
228
229   /**
230    * Provides a <code>XAResource</code> instance for managing distributed
231    * transactions.
232    *
233    * @exception CommException If the physical connection
234    * is lost.
235    * @exception IllegalStateException If the managed connection is
236    * involved in a local
237    * transaction.
238    * @exception ResourceAdapterInternalException If the XA resource can't be
239    * retrieved.
240    */

241   public XAResource JavaDoc getXAResource() throws ResourceException JavaDoc {
242     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
243       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
244                                     this + " getXAResource()");
245
246     if (! isValid()) {
247         if (out != null)
248             out.print("Physical connection to the underlying JORAM server has been lost.");
249       throw new CommException JavaDoc("Physical connection to the underlying "
250                               + "JORAM server has been lost.");
251     }
252
253     try {
254       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
255         AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
256                                       this + " getXAResource session = " + session);
257
258       if (session == null) {
259         OutboundConnection outboundCnx = null;
260         for (java.util.Enumeration JavaDoc e = handles.elements(); e.hasMoreElements(); ) {
261           outboundCnx = (OutboundConnection) e.nextElement();
262           if (outboundCnx.cnxEquals(cnx)) break;
263         }
264
265         if (outboundCnx == null)
266           outboundCnx = (OutboundConnection) getConnection(null,null);
267
268         if (outboundCnx != null) {
269           if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
270             AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
271                                           this + " getXAResource outboundCnx = " + outboundCnx +
272                                           "\n outboundCnx.sess = " + outboundCnx.sessions);
273
274           OutboundSession outboundSession = null;
275           if (outboundCnx.sessions.size() > 0) {
276             outboundSession = (OutboundSession) outboundCnx.sessions.get(0);
277
278             if (!(outboundSession.sess instanceof XASession JavaDoc)) {
279               if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
280                 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
281                                               this + " getXAResource outboundSession.sess = " + outboundSession.sess);
282
283               // getXARessourceManager (create by XAConnection)
284
org.objectweb.joram.client.jms.XAResourceMngr xaResourceMngr = null;
285               if (cnx instanceof org.objectweb.joram.client.jms.XAConnection) {
286                 xaResourceMngr = ((org.objectweb.joram.client.jms.XAConnection) cnx).getXAResourceMngr();
287               } else if (cnx instanceof org.objectweb.joram.client.jms.XAQueueConnection) {
288                 xaResourceMngr = ((org.objectweb.joram.client.jms.XAQueueConnection) cnx).getXAResourceMngr();
289               } else if (cnx instanceof org.objectweb.joram.client.jms.XATopicConnection) {
290                 xaResourceMngr = ((org.objectweb.joram.client.jms.XATopicConnection) cnx).getXAResourceMngr();
291               }
292
293               if (xaResourceMngr == null)
294                 xaResourceMngr = new org.objectweb.joram.client.jms.XAResourceMngr(
295                   (org.objectweb.joram.client.jms.Connection) outboundCnx.xac);
296
297               if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
298                 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
299                                               this + " getXAResource xaResourceMngr = " + xaResourceMngr);
300
301               org.objectweb.joram.client.jms.Session sess =
302                 (org.objectweb.joram.client.jms.Session) outboundSession.sess;
303               // set Session transacted = true
304
sess.setTransacted(true);
305
306               session = (Session JavaDoc) new org.objectweb.joram.client.jms.XASession(
307                 (org.objectweb.joram.client.jms.Connection) outboundCnx.xac,
308                 sess,
309                 xaResourceMngr);
310
311               if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
312                 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
313                                               this + " getXAResource session = " + session);
314             }
315           } else {
316             if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
317               AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
318                                             this + " getXAResource createXASession");
319             session = cnx.createXASession();
320           }
321         }
322       } else if (session instanceof org.objectweb.joram.client.jms.XASession) {
323         if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
324           AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
325                                         this + " getXAResource session is XASession and not null");
326         // set Session transacted = true
327
((org.objectweb.joram.client.jms.XASession)session).getDelegateSession().setTransacted(true);
328
329         // TODO
330
// cnx.sessions.add((org.objectweb.joram.client.jms.Session) session);
331
} else if (! (session instanceof javax.jms.XASession JavaDoc)) {
332           if (out != null)
333               out.print("Managed connection not involved in a local transaction.");
334         throw new IllegalStateException JavaDoc("Managed connection not involved "
335                                         + "in a local transaction.");
336       }
337
338
339       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
340         AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
341                                       this + " getXAResource return = " +
342                                       ((XASession JavaDoc) session).getXAResource());
343
344       return ((XASession JavaDoc) session).getXAResource();
345     }
346     catch (JMSException JavaDoc exc) {
347         if (out != null)
348             out.print("Could not get XA resource: " + exc);
349       throw new ResourceAdapterInternalException JavaDoc("Could not get XA resource: "
350                                                  + exc);
351     }
352   }
353
354   /**
355    * Returns this managed connection instance as a
356    * <code>LocalTransaction</code> instance for managing local transactions.
357    *
358    * @exception CommException If the physical connection is lost.
359    * @exception IllegalStateException If the managed connection is
360    * involved in a distributed
361    * transaction.
362    * @exception LocalTransactionException If the LocalTransaction resource
363    * can't be created.
364    */

365   public javax.resource.spi.LocalTransaction JavaDoc getLocalTransaction()
366     throws ResourceException JavaDoc {
367     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
368       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
369                                     this + " getLocalTransaction()");
370
371     if (! isValid()) {
372         if (out != null)
373             out.print("Physical connection to the underlying JORAM server has been lost.");
374       throw new CommException JavaDoc("Physical connection to the underlying "
375                               + "JORAM server has been lost.");
376     }
377     try {
378       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
379         AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
380                                       this + " getLocalTransaction session = " + session);
381       if (session == null)
382         session = cnx.createSession(true, 0);
383       else if (session instanceof javax.jms.XASession JavaDoc) {
384           if (out != null)
385               out.print("Managed connection already involved in a distributed transaction.");
386         throw new IllegalStateException JavaDoc("Managed connection already involved "
387                                         + "in a distributed transaction.");
388       }
389
390       return this;
391     }
392     catch (JMSException JavaDoc exc) {
393         if (out != null)
394             out.print("Could not build underlying transacted JMS session: " + exc);
395       throw new LocalTransactionException JavaDoc("Could not build underlying "
396                                           + "transacted JMS session: " + exc);
397     }
398   }
399
400   /**
401    * Returns the metadata information for the underlying JORAM server.
402    *
403    * @exception ResourceException Never thrown.
404    */

405   public ManagedConnectionMetaData JavaDoc getMetaData() throws ResourceException JavaDoc
406   {
407     if (metaData == null)
408       metaData = new ManagedConnectionMetaDataImpl(userName);
409
410     return metaData;
411   }
412
413   /**
414    * Sets the log writer for this <code>ManagedConnectionImpl</code>
415    * instance.
416    *
417    * @exception ResourceException Never thrown.
418    */

419   public void setLogWriter(PrintWriter JavaDoc out) throws ResourceException JavaDoc
420   {
421     this.out = out;
422   }
423
424   /**
425    * Gets the log writer for this <code>ManagedConnectionImpl</code>
426    * instance.
427    *
428    * @exception ResourceException Never thrown.
429    */

430   public PrintWriter JavaDoc getLogWriter() throws ResourceException JavaDoc
431   {
432     return out;
433   }
434
435   /**
436    * Invalidates the created handles and prepares the physical connection
437    * to be put back into a connection pool.
438    *
439    * @exception ResourceException Never thrown.
440    */

441   public synchronized void cleanup()
442     throws ResourceException JavaDoc {
443     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
444       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " cleanup()");
445
446     OutboundConnection handle;
447     while (! handles.isEmpty()) {
448       handle = (OutboundConnection) handles.remove(0);
449       handle.cleanup();
450     }
451     session = null;
452   }
453
454   /**
455    * Destroys the physical connection to the underlying JORAM server.
456    *
457    * @exception ResourceException Never thrown.
458    */

459   public synchronized void destroy()
460     throws ResourceException JavaDoc {
461     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
462       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " destroy()");
463
464     cleanup();
465
466     try {
467       cnx.close();
468     }
469     catch (Exception JavaDoc exc) {}
470
471     ra.removeProducer(this);
472
473     valid = false;
474   }
475
476   /**
477    * Returns a code based on the JORAM server and user identification
478    * parameters.
479    */

480   public int hashCode() {
481     if (hashCode == -1)
482       hashCode = (mode + ":" + hostName + ":" + ":" + serverPort + "-" + userName).hashCode();
483     return hashCode;
484   }
485
486   /**
487    * Compares <code>ManagedConnectionImpl</code> instances according to their
488    * server and user identification parameters.
489    */

490   public boolean equals(Object JavaDoc o) {
491     if (! (o instanceof ManagedConnectionImpl))
492       return false;
493
494     ManagedConnectionImpl other = (ManagedConnectionImpl) o;
495
496     boolean res =
497       mode.equals(other.mode)
498       && hostName.equals(other.hostName)
499       && serverPort == other.serverPort
500       && userName.equals(other.userName)
501       && cnx.equals(other.cnx);
502
503     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
504       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " equals = " + res);
505
506     return res;
507   }
508
509   /** Notifies that the wrapped physical connection has been lost. */
510   public synchronized void onException(JMSException JavaDoc exc) {
511
512     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
513       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " onException(" + exc + ")");
514
515     // Physical connection already invalid: doing nothing.
516
if (! isValid())
517       return;
518
519     // Asynchronous JORAM exception does not notify of a connection loss:
520
// doing nothing.
521
if (! (exc instanceof javax.jms.IllegalStateException JavaDoc))
522       return;
523
524     ConnectionEvent JavaDoc event =
525       new ConnectionEvent JavaDoc(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED);
526
527     ConnectionEventListener JavaDoc listener;
528     for (int i = 0; i < listeners.size(); i++) {
529       listener = (ConnectionEventListener JavaDoc) listeners.get(i);
530       listener.connectionErrorOccurred(event);
531     }
532
533     valid = false;
534   }
535
536
537   /**
538    * Notifies that the local transaction is beginning.
539    *
540    * @exception CommException If the wrapped physical connection
541    * is lost.
542    * @exception LocalTransactionException If a local transaction has already
543    * begun.
544    * @exception
545    */

546   public synchronized void begin() throws ResourceException JavaDoc {
547
548     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
549       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " begin()");
550
551     if (! isValid())
552       throw new CommException JavaDoc("Physical connection to the underlying "
553                               + "JORAM server has been lost.");
554
555     if (startedLocalTx)
556       throw new LocalTransactionException JavaDoc("Local transaction has "
557                                           + "already begun.");
558
559     ConnectionEvent JavaDoc event =
560       new ConnectionEvent JavaDoc(this, ConnectionEvent.LOCAL_TRANSACTION_STARTED);
561
562     ConnectionEventListener JavaDoc listener;
563     for (int i = 0; i < listeners.size(); i++) {
564       listener = (ConnectionEventListener JavaDoc) listeners.get(i);
565       listener.localTransactionStarted(event);
566     }
567
568     startedLocalTx = true;
569   }
570
571   /**
572    * Commits the local transaction.
573    *
574    * @exception CommException If the wrapped physical connection
575    * is lost.
576    * @exception LocalTransactionException If the local transaction has not
577    * begun, or if the commit fails.
578    */

579   public synchronized void commit() throws ResourceException JavaDoc {
580
581     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
582       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " commit()");
583
584     if (! isValid())
585       throw new CommException JavaDoc("Physical connection to the underlying "
586                               + "JORAM server has been lost.");
587
588     if (! startedLocalTx)
589       throw new LocalTransactionException JavaDoc("Local transaction has not begun.");
590
591     try {
592       session.commit();
593     }
594     catch (JMSException JavaDoc exc) {
595       throw new LocalTransactionException JavaDoc("Commit of the transacted JMS "
596                                           + "session failed: " + exc);
597     }
598
599     ConnectionEvent JavaDoc event =
600       new ConnectionEvent JavaDoc(this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
601
602     ConnectionEventListener JavaDoc listener;
603     for (int i = 0; i < listeners.size(); i++) {
604       listener = (ConnectionEventListener JavaDoc) listeners.get(i);
605       listener.localTransactionCommitted(event);
606     }
607
608     startedLocalTx = false;
609   }
610
611   /**
612    * Rollsback the local transaction.
613    *
614    * @exception CommException If the wrapped physical connection
615    * is lost.
616    * @exception LocalTransactionException If the local transaction has not
617    * begun, or if the rollback fails.
618    */

619   public synchronized void rollback() throws ResourceException JavaDoc {
620
621     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
622       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " rollback()");
623
624     if (! isValid())
625       throw new CommException JavaDoc("Physical connection to the underlying "
626                               + "JORAM server has been lost.");
627
628     if (! startedLocalTx)
629       throw new LocalTransactionException JavaDoc("Local transaction has not begun.");
630
631     try {
632       session.rollback();
633     }
634     catch (JMSException JavaDoc exc) {
635       throw new LocalTransactionException JavaDoc("Rollback of the transacted JMS "
636                                           + "session failed: " + exc);
637     }
638
639     ConnectionEvent JavaDoc event =
640       new ConnectionEvent JavaDoc(this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
641
642     ConnectionEventListener JavaDoc listener;
643     for (int i = 0; i < listeners.size(); i++) {
644       listener = (ConnectionEventListener JavaDoc) listeners.get(i);
645       listener.localTransactionRolledback(event);
646     }
647
648     startedLocalTx = false;
649   }
650
651
652   /**
653    * Returns <code>true</code> if this managed connection matches given
654    * parameters.
655    */

656   boolean matches(String JavaDoc hostName,
657                   int serverPort,
658                   String JavaDoc userName,
659                   String JavaDoc mode) {
660     return this.hostName.equals(hostName)
661            && this.serverPort == serverPort
662            && this.userName.equals(userName)
663            && this.mode.equals(mode);
664   }
665
666   /**
667    * Returns <code>false</code> if the wrapped physical connection has been
668    * lost or destroyed, <code>true</code> if it is still valid.
669    */

670   boolean isValid()
671   {
672     return valid;
673   }
674
675   /** Notifies of the closing of one of the connection handles. */
676   void closeHandle(OutboundConnection handle) {
677     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
678       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " closeHandle(" + handle + ")");
679
680     ConnectionEvent JavaDoc event =
681       new ConnectionEvent JavaDoc(this, ConnectionEvent.CONNECTION_CLOSED);
682     event.setConnectionHandle(handle);
683
684     ConnectionEventListener JavaDoc listener;
685     for (int i = 0; i < listeners.size(); i++) {
686       listener = (ConnectionEventListener JavaDoc) listeners.get(i);
687       listener.connectionClosed(event);
688     }
689   }
690 }
691
Popular Tags