KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > distributedtx > J2EETransactionManagerImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.distributedtx;
24
25 import java.util.*;
26 import java.rmi.RemoteException JavaDoc;
27 import javax.transaction.*;
28 import javax.transaction.xa.*;
29
30 import com.sun.enterprise.*;
31 import com.sun.ejb.*;
32 import com.sun.enterprise.resource.*;
33 import com.sun.enterprise.log.Log;
34
35 import javax.servlet.Servlet JavaDoc;
36 import javax.servlet.Filter JavaDoc;
37 import javax.servlet.SingleThreadModel JavaDoc;
38 import javax.ejb.EnterpriseBean JavaDoc;
39
40 import javax.resource.spi.XATerminator JavaDoc;
41 import javax.resource.spi.work.WorkException JavaDoc;
42
43
44 // START IASRI 4662745
45
import com.sun.enterprise.config.ConfigContext;
46 import com.sun.enterprise.config.ConfigBean;
47 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
48 import com.sun.enterprise.config.serverbeans.Config;
49 import com.sun.enterprise.server.ApplicationServer;
50 import com.sun.enterprise.server.ServerContext;
51 import com.sun.enterprise.config.ConfigException;
52 import com.sun.enterprise.config.serverbeans.TransactionService;
53 import com.sun.enterprise.config.serverbeans.ElementProperty;
54 import com.sun.enterprise.transaction.TransactionAdminBean;
55 import com.sun.enterprise.transaction.JTSConfigChangeEventListener;
56 import com.sun.enterprise.admin.event.tx.JTSEvent;
57 import com.sun.enterprise.util.i18n.StringManager;
58 // END IASRI 4662745
59

60 import com.sun.jts.jta.TransactionManagerImpl;
61
62 //START OF IASRI 4664284
63
import java.util.logging.*;
64 import com.sun.logging.*;
65 //END OF IASRI 4664284
66

67 // START IASRI 4705808 TTT001 -- use BaseCache instead of Hashtable
68
import com.sun.appserv.util.cache.Cache;
69 import com.sun.appserv.util.cache.BaseCache;
70 // END IASRI 4705808 TTT001
71

72
73 import com.sun.ejb.ComponentContext;
74
75
76 /**
77  * This class implements the Transaction Manager for the J2EE RI.
78  * It provides implementations of the JTA TransactionManager interface,
79  * which delegates actual transaction work to JTS.
80  * It also implements the association between transactions, resources and
81  * components at various stages of the component lifecycle.
82  *
83  * @author Tony Ng
84  */

85 public class J2EETransactionManagerImpl implements J2EETransactionManager {
86
87     // START OF IASRI 4664284
88
static Logger _logger=LogDomains.getLogger(LogDomains.JTA_LOGGER);
89     // END OF IASRI 4664284
90

91     private static final String JavaDoc TX_TIMEOUT = "transaction.timeout";
92     private static final String JavaDoc TX_OPT = "transaction.nonXA.optimization";
93
94     // an implementation of the JTA TransactionManager provided by JTS.
95
private TransactionManager tm;
96
97     // If multipleEnlistDelists is set to true, with in the transaction, for the same
98
// - connection multiple enlistments and delistments might happen
99
// - By setting the System property ALLOW_MULTIPLE_ENLISTS_DELISTS to true
100
// - multipleEnlistDelists can be enabled
101
private boolean multipleEnlistDelists = false;
102     // Sting Manager for Localization
103
private static StringManager sm = StringManager.getManager(J2EETransactionManagerImpl.class);
104     protected InvocationManager invMgr;
105
106     protected PoolManager poolmgr;
107
108     // START OF IASRI 4629815
109
//
110
//protected ResourcePoolManager resourcePoolMgr; //Added by Miriam - ECU
111
// START OF IASRI 4629815
112
//
113

114     protected int transactionTimeout;
115     protected ThreadLocal JavaDoc<Integer JavaDoc> txnTmout = new ThreadLocal JavaDoc();
116     protected boolean useLAO = true;
117
118     // START IASRI 4662745
119
// admin and monitoring related parameters
120
protected Hashtable statusMap;
121     protected Vector activeTransactions;
122     protected boolean monitoringEnabled = false;
123
124     static protected int JTAStatus[] =
125     {
126         javax.transaction.Status.STATUS_ACTIVE,
127         javax.transaction.Status.STATUS_MARKED_ROLLBACK,
128         javax.transaction.Status.STATUS_PREPARED,
129         javax.transaction.Status.STATUS_COMMITTED,
130         javax.transaction.Status.STATUS_ROLLEDBACK,
131         javax.transaction.Status.STATUS_UNKNOWN,
132         javax.transaction.Status.STATUS_NO_TRANSACTION,
133         javax.transaction.Status.STATUS_PREPARING,
134         javax.transaction.Status.STATUS_COMMITTING,
135         javax.transaction.Status.STATUS_ROLLING_BACK
136     };
137
138     static protected String JavaDoc STATUS[] =
139     {
140         "Active",
141         "MarkedRollback",
142         "Prepared",
143         "Committed",
144         "RolledBack",
145         "UnKnown",
146         "NoTransaction",
147         "Preparing",
148         "Committing",
149         "RollingBack"
150     };
151     protected int m_transCommitted = 0;
152     protected int m_transRolledback = 0;
153     protected int m_transInFlight = 0;
154     // END IASRI 4662745
155

156     /**
157      * instance -> resource list mapping
158      * // START IASRI 4705808 TTT002 -- use List instead of Vector
159      * For EJB, a mapping of EnterpriseBean -> ArrayList
160      * For Servlets/JSPs, a mapping of <Context+Thread> -> ArrayList
161      * // END IASRI 4705808 TTT002
162      */

163     // START IASRI 4705808 TTT001 -- use BaseCache instead of Hashtable
164
private Cache resourceTable;
165     // END IASRI 4705808 TTT001
166

167
168
169     public J2EETransactionManagerImpl() {
170         if (_logger.isLoggable(Level.FINE))
171             _logger.log(Level.FINE,"TM: Initializing distributed TM...");
172         //tm = TransactionManagerImpl.getTransactionManagerImpl();
173
if( Switch.getSwitch().getPoolManager() == null ) {
174         poolmgr = new PoolManagerImpl();
175         Switch.getSwitch().setPoolManager( poolmgr );
176     } else {
177             poolmgr = Switch.getSwitch().getPoolManager();
178     }
179         Switch.getSwitch().setPoolManager(poolmgr);
180
181         ResourceInstaller installer = new ResourceInstaller();
182         Switch.getSwitch().setResourceInstaller(installer);
183
184     // START IASRI 4705808 TTT001 -- use BaseCache instead of Hashtable
185
//int maxEntries = 16000; // FIXME: this maxEntry should be a config
186
int maxEntries = 8192; // FIXME: this maxEntry should be a config
187
float loadFactor = 0.75f; // FIXME: this loadFactor should be a config
188
// for now, let's get it from system prop
189
try {
190             String JavaDoc mEnlistDelists
191                 = System.getProperty("ALLOW_MULTIPLE_ENLISTS_DELISTS");
192             if ("true".equals(mEnlistDelists)) {
193                 multipleEnlistDelists = true;
194         if (_logger.isLoggable(Level.FINE))
195                 _logger.log(Level.FINE,"TM: multiple enlists, delists are enabled");
196             }
197         String JavaDoc maxEntriesValue
198         = System.getProperty("JTA_RESOURCE_TABLE_MAX_ENTRIES");
199             if (maxEntriesValue != null) {
200                 int temp = Integer.parseInt(maxEntriesValue);
201                 if (temp > 0) {
202                     maxEntries = temp;
203                 }
204             }
205         String JavaDoc loadFactorValue
206         = System.getProperty("JTA_RESOURCE_TABLE_DEFAULT_LOAD_FACTOR");
207             if (loadFactorValue != null) {
208                 float f = Float.parseFloat(loadFactorValue);
209                 if (f > 0) {
210                      loadFactor = f;
211                 }
212             }
213         } catch (Exception JavaDoc ex) {
214             // ignore
215
}
216     Properties cacheProps = null;
217
218         resourceTable = new BaseCache();
219         ((BaseCache)resourceTable).init(maxEntries, loadFactor, cacheProps);
220     // END IASRI 4705808 TTT001
221

222         invMgr = Switch.getSwitch().getInvocationManager();
223         // START IASRI 4662745
224

225         ServerContext sCtx = ApplicationServer.getServerContext();
226         // running on the server side
227
if (sCtx != null) {
228             ConfigContext ctx = sCtx.getConfigContext();
229             TransactionService txnService = null;
230             try {
231                 txnService = ServerBeansFactory.getTransactionServiceBean(ctx);
232                 transactionTimeout = Integer.parseInt(txnService.getTimeoutInSeconds());
233                 ElementProperty[] eprops = txnService.getElementProperty();
234                 for (int index = 0; index < eprops.length; index++) {
235                     if ("use-last-agent-optimization".equals(eprops[index].getName())) {
236                         if ("false".equals(eprops[index].getValue())) {
237                             useLAO = false;
238                     if (_logger.isLoggable(Level.FINE))
239                             _logger.log(Level.FINE,"TM: LAO is disabled");
240                         }
241                     }
242                 }
243             } catch(ConfigException e) {
244                 throw new RuntimeException JavaDoc(sm.getString("enterprise_distributedtx.config_excep",e));
245             } catch (NumberFormatException JavaDoc ex) {
246             }
247         }
248         // ENF OF BUG 4665539
249
if (_logger.isLoggable(Level.FINE))
250             _logger.log(Level.FINE,"TM: Tx Timeout = " + transactionTimeout);
251
252         // monitor and administration
253
activeTransactions = new Vector();
254         statusMap = new Hashtable();
255         for (int i=0; i<JTAStatus.length; i++) {
256             statusMap.put(new Integer JavaDoc(JTAStatus[i]),STATUS[i]);
257         }
258         // END IASRI 4662745
259

260     // START IASRI 4705808 TTT004 -- monitor resource table stats
261
try {
262         String JavaDoc doStats
263         = System.getProperty("MONITOR_JTA_RESOURCE_TABLE_STATISTICS");
264             if (Boolean.getBoolean(doStats)) {
265         registerStatisticMonitorTask();
266         }
267         } catch (Exception JavaDoc ex) {
268             // ignore
269
}
270     // END IASRI 4705808 TTT004
271
}
272
273     public static J2EETransactionManager createTransactionManager() {
274         ServerConfiguration sc = ServerConfiguration.getConfiguration();
275     String JavaDoc txOpt = sc.getProperty(TX_OPT);
276
277         if (_logger.isLoggable(Level.FINE))
278             _logger.log(Level.FINE,"TM: Tx Opt = " + txOpt);
279
280     J2EETransactionManager j2eeTM;
281     if ( txOpt != null && txOpt.equals("false") )
282         j2eeTM = new J2EETransactionManagerImpl();
283     else {
284         j2eeTM = new J2EETransactionManagerOpt();
285             J2EETransaction.j2eeTM = (J2EETransactionManagerOpt)j2eeTM;
286         }
287
288     return j2eeTM;
289     }
290
291     public static void createJTSTransactionManager() {
292         // It is assumed that transaction manager is already created
293
// and is available in switch.
294
J2EETransactionManagerImpl impl = (J2EETransactionManagerImpl)
295         Switch.getSwitch().getTransactionManager();
296
297         impl.tm = TransactionManagerImpl.getTransactionManagerImpl();
298        
299     }
300
301     private static void print(String JavaDoc s) {
302         /** IASRI 4664284
303         System.err.println(s);
304         **/

305         // START OF IASRI 4664284
306
_logger.log(Level.FINE,s);
307         // END OF IASRI 4664284
308

309     }
310
311
312 /****************************************************************************/
313 /** Implementations of J2EETransactionManager APIs **************************/
314 /****************************************************************************/
315
316     /**
317      * Return true if a "null transaction context" was received
318      * from the client. See EJB2.0 spec section 19.6.2.1.
319      * A null tx context has no Coordinator objref. It indicates
320      * that the client had an active
321      * tx but the client container did not support tx interop.
322      */

323     public boolean isNullTransaction()
324     {
325     try {
326         return com.sun.jts.pi.InterceptorImpl.isTxCtxtNull();
327     } catch ( Exception JavaDoc ex ) {
328         // sometimes JTS throws an EmptyStackException if isTxCtxtNull
329
// is called outside of any CORBA invocation.
330
return false;
331     }
332     }
333
334     public void recover(XAResource[] resourceList) {
335         int size = resourceList.length;
336         Vector v = new Vector();
337         for (int i=0; i<size; i++) {
338             v.addElement(resourceList[i]);
339         }
340         ((TransactionManagerImpl)tm).recover(v.elements());
341     }
342
343     public boolean enlistResource(Transaction tran, ResourceHandle h)
344         throws RollbackException,
345                IllegalStateException JavaDoc, SystemException {
346         if (_logger.isLoggable(Level.FINE))
347             _logger.log(Level.FINE,"TM: enlistResource");
348         if (h.isTransactional() && (!h.isEnlisted() || !h.isShareable() || multipleEnlistDelists)) {
349             XAResource res = h.getXAResource();
350             boolean result = tran.enlistResource(res);
351             if (!h.isEnlisted())
352                 poolmgr.resourceEnlisted(tran, h);
353             return result;
354         } else {
355             return true;
356         }
357     }
358
359     public boolean enlistLAOResource(Transaction tran, ResourceHandle h)
360         throws RollbackException,
361                IllegalStateException JavaDoc, SystemException {
362         if (_logger.isLoggable(Level.FINE))
363             _logger.log(Level.FINE,"TM: enlistLAOResource");
364         if (h.isTransactional()) {
365             XAResource res = h.getXAResource();
366             boolean result = tran.enlistResource(res);
367             return result;
368         } else {
369             return true;
370         }
371     }
372
373     public void enlistComponentResources() throws RemoteException JavaDoc {
374         if (_logger.isLoggable(Level.FINE))
375             _logger.log(Level.FINE,"TM: enlistComponentResources");
376         ComponentInvocation inv = invMgr.getCurrentInvocation();
377         // BEGIN IASRI# 4646060
378
if (inv == null) {
379             throw new InvocationException();
380         }
381         // END IASRI# 4646060
382
try {
383             Transaction tran = getTransaction();
384             inv.setTransaction(tran);
385             enlistComponentResources(inv);
386         } catch (InvocationException ex) {
387             /** IASRI 4664284
388             ex.printStackTrace();
389             ex.printStackTrace(Log.err);
390             **/

391             //START OF IASRI 4664284
392
_logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_enlist" ,ex);
393             //END OF IASRI 4664284
394

395             throw new RemoteException JavaDoc(ex.getMessage(), ex.getNestedException());
396         } catch (Exception JavaDoc ex) {
397             /** IASRI 4664284
398             ex.printStackTrace();
399             ex.printStackTrace(Log.err);
400             **/

401             //START OF IASRI 4664284
402
_logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_enlist" ,ex);
403             //END OF IASRI 4664284
404
throw new RemoteException JavaDoc(ex.getMessage(), ex);
405         }
406     }
407
408     public void delistComponentResources(boolean suspend)
409         throws RemoteException JavaDoc {
410         if (_logger.isLoggable(Level.FINE))
411             _logger.log(Level.FINE,"TM: delistComponentResources");
412         ComponentInvocation inv = invMgr.getCurrentInvocation();
413         // BEGIN IASRI# 4646060
414
if (inv == null) {
415             throw new InvocationException();
416         }
417         // END IASRI# 4646060
418
try {
419             delistComponentResources(inv, suspend);
420         } catch (InvocationException ex) {
421             /** IASRI 4664284
422             ex.printStackTrace();
423             ex.printStackTrace(Log.err);
424             **/

425             // START OF IASRI 4664284
426
_logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_delist",ex);
427             // END OF IASRI 4664284
428

429             throw new RemoteException JavaDoc("", ex.getNestedException());
430         } catch (Exception JavaDoc ex) {
431             /** IASRI 4664284
432             ex.printStackTrace();
433             ex.printStackTrace(Log.err);
434             **/

435             // START OF IASRI 4664284
436
_logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_delist",ex);
437             // END OF IASRI 4664284
438
throw new RemoteException JavaDoc("", ex);
439         }
440     }
441
442     public void registerComponentResource(ResourceHandle h) {
443         ComponentInvocation inv = invMgr.getCurrentInvocation();
444         if (inv != null) {
445             Object JavaDoc instance = inv.getInstance();
446             if (instance == null) return;
447             h.setComponentInstance(instance);
448             List l = getResourceList(instance, inv);
449             l.add(h);
450         } else {
451             throw new InvocationException();
452         }
453     }
454
455     public void unregisterComponentResource(ResourceHandle h) {
456         Object JavaDoc instance = h.getComponentInstance();
457         if (instance == null) return;
458         h.setComponentInstance(null);
459         ComponentInvocation inv = invMgr.getCurrentInvocation();
460         List l = null;
461         if (inv != null)
462             l = getExistingResourceList(instance, inv);
463         else
464             l = getExistingResourceList(instance);
465     if (l != null) {
466             l.remove(h);
467     }
468     }
469
470     private void handleResourceError(ResourceHandle h,
471                                      Exception JavaDoc ex, Transaction tran,
472                                      ComponentInvocation inv) {
473
474         if (_logger.isLoggable(Level.FINE)) {
475             if (h.isTransactional()) {
476                 _logger.log(Level.FINE,"TM: HandleResourceError " +
477                                    h.getXAResource() +
478                                    "," + ex);
479             }
480         }
481         /** IASRI 4658504
482         // unregister resource
483         Object instance = inv.getInstance();
484         if (instance == null) return;
485         Vector v = getResourceList(instance);
486         v.removeElement(h);
487
488         ** IASRI 4658504 **/

489         try {
490             if (tran != null && h.isTransactional() && h.isEnlisted() ) {
491                 tran.delistResource(h.getXAResource(), XAResource.TMSUCCESS);
492             }
493         } catch (Exception JavaDoc ex2) {
494             // ignore
495
}
496
497
498         if (ex instanceof RollbackException) {
499             // transaction marked as rollback
500
return;
501         } else if (ex instanceof IllegalStateException JavaDoc) {
502             // transaction aborted by time out
503
// close resource
504
try {
505                 h.getResourceAllocator().closeUserConnection(h);
506             } catch (Exception JavaDoc ex2) {
507                 //Log.err.println(ex2);
508
}
509         } else {
510             // destroy resource. RM Error.
511
try {
512                 h.getResourceAllocator().destroyResource(h);
513             } catch (Exception JavaDoc ex2) {
514                 //Log.err.println(ex2);
515
}
516         }
517     }
518
519     private void enlistComponentResources(ComponentInvocation inv)
520     throws InvocationException {
521
522         // Exception ex1 = null;
523
try {
524             Transaction tran = inv.getTransaction();
525             if (isTransactionActive(tran)) {
526         /** IASRI 4658504
527                 Vector v = getResourceList(inv.getInstance());
528                 Enumeration e = v.elements();
529                 while (e.hasMoreElements()) {
530                     ResourceHandle h = (ResourceHandle) e.nextElement();
531                     try {
532                         enlistResource(tran, h);
533                     } catch (Exception ex) {
534                         handleResourceError(h, ex, tran, inv);
535                     }
536                 }
537         ** IASRI 4658504 **/

538         
539                 List l = getResourceList(inv.getInstance(), inv);
540                 Iterator it = l.iterator();
541         // END IASRI 4705808 TTT002
542
while(it.hasNext()) {
543             ResourceHandle h = (ResourceHandle) it.next();
544             try{
545             enlistResource(tran,h);
546             }catch(Exception JavaDoc ex){
547                         // ex1 = ex;
548
it.remove();
549             handleResourceError(h,ex,tran,inv);
550             }
551         }
552         //END OF IASRI 4658504
553
}
554         } catch (Exception JavaDoc ex) {
555             /** IASRI 4664284
556             ex.printStackTrace();
557             ex.printStackTrace(Log.err);
558             **/

559             // START OF IASRI 4664284
560
_logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_enlist",ex);
561             // END OF IASRI 4664284
562
//throw new InvocationException(ex);
563
}
564         /**
565         if (ex1 != null) {
566             InvocationException ivx = new InvocationException(ex1.getMessage());
567             ivx.initCause(ex1);
568             throw ivx;
569         }
570         **/

571     }
572
573     private void delistComponentResources(ComponentInvocation inv,
574                                           boolean suspend)
575         throws InvocationException {
576
577         try {
578             Transaction tran = inv.getTransaction();
579             if (isTransactionActive(tran)) {
580                 /** IASRI 4658504
581                 Vector v = getResourceList(inv.getInstance());
582                 Enumeration e = v.elements();
583                 int flag = XAResource.TMSUCCESS;
584                 if (suspend) flag = XAResource.TMSUSPEND;
585                 while (e.hasMoreElements()) {
586                     ResourceHandle h = (ResourceHandle) e.nextElement();
587                     try {
588                         delistResource(tran, h, flag);
589                     } catch (IllegalStateException ex) {
590                         // ignore error due to tx time out
591                     } catch (Exception ex) {
592                         handleResourceError(h, ex, tran, inv);
593                     }
594                 }
595                 **IASRI 4658504 **/

596
597                 List l = getExistingResourceList(inv.getInstance(), inv);
598                 if (l == null)
599                     l = new ArrayList(0);
600                 Iterator it = l.iterator();
601         // END IASRI 4705808 TTT002
602
int flag = XAResource.TMSUCCESS;
603         if(suspend)flag = XAResource.TMSUSPEND;
604         while(it.hasNext()){
605             ResourceHandle h = (ResourceHandle)it.next();
606             try{
607                         if ( h.isEnlisted() ) {
608                 delistResource(tran,h,flag);
609                         }
610             } catch (IllegalStateException JavaDoc ex) {
611             // ignore error due to tx time out
612
}catch(Exception JavaDoc ex){
613             it.remove();
614             handleResourceError(h,ex,tran,inv);
615             }
616         }
617         //END OF IASRI 4658504
618
}
619         } catch (Exception JavaDoc ex) {
620             /** IASRI 4664284
621             ex.printStackTrace();
622             ex.printStackTrace(Log.err);
623             **/

624             // START OF IASRI 4664284
625
_logger.log(Level.SEVERE,"enterprise_distributedtx.excep_in_delist",ex);
626             // END OF IASRI 4664284
627
//throw new InvocationException(ex);
628
}
629     }
630
631     private boolean isTransactionActive(Transaction tran) {
632         return (tran != null);
633     }
634
635     
636     public void preInvoke(ComponentInvocation prev)
637     throws InvocationException {
638         if ( prev != null && prev.getTransaction() != null &&
639         prev.isTransactionCompleting() == false) {
640             // do not worry about delisting previous invocation resources
641
// if transaction is being completed
642
delistComponentResources(prev, true); // delist with TMSUSPEND
643
}
644         
645     }
646
647
648     public void postInvoke(ComponentInvocation curr, ComponentInvocation prev)
649     throws InvocationException {
650         
651         if ( curr != null && curr.getTransaction() != null )
652             delistComponentResources(curr, false); // delist with TMSUCCESS
653
if ( prev != null && prev.getTransaction() != null &&
654         prev.isTransactionCompleting() == false) {
655             // do not worry about re-enlisting previous invocation resources
656
// if transaction is being completed
657
enlistComponentResources(prev);
658         }
659         
660     }
661
662
663     public void componentDestroyed(Object JavaDoc instance) {
664         if (_logger.isLoggable(Level.FINE))
665             _logger.log(Level.FINE,"TM: componentDestroyed" + instance);
666     // START IASRI 4705808 TTT002 -- use List instead of Vector
667
// Mod: remove the bad behavior of adding an empty list then remove it
668
List l = (List)resourceTable.get(getInstanceKey(instance));
669         if (l != null) {
670             //START IASRI 4720840
671
resourceTable.remove(getInstanceKey(instance));
672             //END IASRI 4720840
673
Iterator it = l.iterator();
674             while (it.hasNext()) {
675                 ResourceHandle h = (ResourceHandle) it.next();
676                 try {
677                     h.getResourceAllocator().closeUserConnection(h);
678                 } catch (PoolingException ex) {
679                     /** IASRI 4664284
680                     if (debug) ex.printStackTrace();
681                     **/

682                     // START OF IASRI 4664284
683
if (_logger.isLoggable(Level.FINE))
684                         _logger.log(Level.WARNING,"enterprise_distributedtx.pooling_excep", ex);
685                     // END OF IASRI 4664284
686
}
687             }
688             l.clear();
689             //START IASRI 4720840
690
// resourceTable.remove(getInstanceKey(instance));
691
//END IASRI 4720840
692
}
693     // END IASRI 4705808 TTT002
694
}
695
696     public void ejbDestroyed(ComponentContext context) {
697     if (_logger.isLoggable(Level.FINE))
698             _logger.log(Level.FINE, " ejbDestroyed: " + context);
699         List l = (List)context.getResourceList();
700         if (l != null) {
701             Iterator it = l.iterator();
702             while (it.hasNext()) {
703                 ResourceHandle h = (ResourceHandle) it.next();
704                 try {
705                     h.getResourceAllocator().closeUserConnection(h);
706                 } catch (PoolingException ex) {
707             if (_logger.isLoggable(Level.FINE))
708                         _logger.log(Level.WARNING,"enterprise_distributedtx.pooling_excep", ex);
709                 }
710             }
711             l.clear();
712         }
713     }
714
715
716
717     private Object JavaDoc getInstanceKey(Object JavaDoc instance) {
718         Object JavaDoc key = null;
719         if (instance instanceof Servlet JavaDoc ||
720             instance instanceof Filter JavaDoc) {
721             // Servlet or Filter
722
if (instance instanceof SingleThreadModel JavaDoc) {
723                 key = instance;
724             } else {
725                 Vector pair = new Vector(2);
726                 pair.addElement(instance);
727                 pair.addElement(Thread.currentThread());
728                 key = pair;
729             }
730         } else {
731             key = instance;
732         }
733         return key;
734     }
735
736     //START IASRI 4720840
737
public List getExistingResourceList(Object JavaDoc instance) {
738         Object JavaDoc key = getInstanceKey(instance);
739         return (List) resourceTable.get(key);
740     }
741     //END IASRI 4720840
742

743     public List getExistingResourceList(Object JavaDoc instance, ComponentInvocation inv) {
744         List l = null;
745         if (inv.getInvocationType() == ComponentInvocation.EJB_INVOCATION) {
746             ComponentContext ctx = inv.context;
747             if (ctx != null)
748                 l = ctx.getResourceList();
749             return l;
750         }
751         else {
752             Object JavaDoc key = getInstanceKey(instance);
753             return (List) resourceTable.get(key);
754        }
755     }
756
757     // START IASRI 4705808 TTT001 -- use BaseCache instead of Hashtable
758
public List getResourceList(Object JavaDoc instance) {
759         Object JavaDoc key = getInstanceKey(instance);
760         List l = (List) resourceTable.get(key);
761         if (l == null) {
762             l = new ArrayList(); //FIXME: use an optimum size?
763
resourceTable.put(key, l);
764         }
765         return l;
766     }
767     // END IASRI 4705808 TTT002
768

769     public List getResourceList(Object JavaDoc instance, ComponentInvocation inv) {
770         List l = null;
771         if (inv.getInvocationType() == ComponentInvocation.EJB_INVOCATION) {
772             ComponentContext ctx = inv.context;
773             if (ctx != null)
774                 l = ctx.getResourceList();
775             else {
776             l = new ArrayList(0);
777             }
778         }
779         else {
780             Object JavaDoc key = getInstanceKey(instance);
781             l = (List) resourceTable.get(key);
782             if (l == null) {
783                 l = new ArrayList(); //FIXME: use an optimum size?
784
resourceTable.put(key, l);
785             }
786         }
787         return l;
788     }
789
790
791
792     /**
793      * @param suspend true if the transaction association should
794      * be suspended rather than ended.
795      */

796     public boolean delistResource(Transaction tran, ResourceHandle h,
797                                   int flag)
798         throws IllegalStateException JavaDoc, SystemException {
799         if (_logger.isLoggable(Level.FINE))
800             _logger.log(Level.FINE,"TM: delistResource");
801         if (!h.isShareable() || multipleEnlistDelists) {
802             if (h.isTransactional() && h.isEnlisted()) {
803                 return tran.delistResource(h.getXAResource(), flag);
804             } else {
805                 return true;
806             }
807         }
808         return true;
809     }
810
811     public void registerSynchronization(Synchronization sync)
812         throws IllegalStateException JavaDoc, SystemException
813     {
814         if (_logger.isLoggable(Level.FINE))
815             _logger.log(Level.FINE,"TM: registerSynchronization");
816         try {
817             Transaction tran = getTransaction();
818             if (tran != null) {
819                 tran.registerSynchronization(sync);
820             }
821         } catch (RollbackException ex) {
822             /** IASRI 4664284
823             ex.printStackTrace();
824             ex.printStackTrace(Log.err);
825             **/

826             //START OF IASRI 4664284
827
_logger.log(Level.SEVERE,"enterprise_distributedtx.rollbackexcep_in_regsynch",ex);
828             //END OF IASRI 4664284
829

830             throw new IllegalStateException JavaDoc();
831         }
832     }
833
834     public void begin(int timeout)
835         throws NotSupportedException, SystemException {
836
837         //START RI PERFIMPROVEMENT
838
/***
839         // Just to tell that, use this timeout for the transaction, there is no need
840         // to synchronized and thus serrialize the activity. Now this is avoided by
841         // the introduction of two new methods begin(timeout) in TransactionManagerImpl
842         // and CurrentImpl
843
844         // ensure no other thread change the timeout
845         synchronized(tm) {
846             tm.setTransactionTimeout(timeout);
847             tm.begin();
848             tm.setTransactionTimeout(0);
849             // START IASRI 4662745
850             if (monitoringEnabled) {
851                 Transaction tran = tm.getTransaction();
852                 activeTransactions.addElement(tran);
853                 m_transInFlight++;
854             }
855             // END IASRI 4662745
856         }
857         **/

858
859         ((TransactionManagerImpl)tm).begin(timeout);
860         // START IASRI 4662745
861
if (monitoringEnabled) {
862             Transaction tran = tm.getTransaction();
863             activeTransactions.addElement(tran);
864             m_transInFlight++;
865         }
866         // END IASRI 4662745
867
//END RI PERFIMPROVEMENT
868
}
869
870
871     public void checkTransactionExport(boolean isLocal) { }
872
873     public void checkTransactionImport() { }
874
875     private void validateTransactionManager() throws IllegalStateException JavaDoc {
876         if (tm == null) {
877             throw new IllegalStateException JavaDoc
878             (sm.getString("enterprise_distributedtx.transaction_notactive"));
879         }
880     }
881
882
883
884 /****************************************************************************/
885 /** Implementations of JTA TransactionManager APIs **************************/
886 /****************************************************************************/
887
888
889     /**
890      * Create a new transaction and associate it with the current thread.
891      *
892      * @exception NotSupportedException Thrown if the thread is already
893      * associated with a transaction.
894      *
895      * @exception SystemException Thrown if the transaction manager
896      * encounters an unexpected error condition
897      *
898      */

899     public void begin() throws NotSupportedException, SystemException {
900         if (_logger.isLoggable(Level.FINE))
901             _logger.log(Level.FINE,"TM: begin");
902
903         //START RI PERFIMPROVEMENT
904
/***
905         // Just to tell that, use this timeout for the transaction, there is no need
906         // to synchronize and thus serrialize the activity. Now this is avoided by
907         // the introduction of two new methods begin(timeout) in TransactionManagerImpl
908         // and CurrentImpl
909
910         synchronized(tm) {
911             // ensure no other thread change the timeout
912             tm.setTransactionTimeout(transactionTimeout);
913             tm.begin();
914             tm.setTransactionTimeout(0);
915
916             // START IASRI 4662745
917             if (monitoringEnabled) {
918                 Transaction tran = tm.getTransaction();
919                 activeTransactions.addElement(tran);
920                 m_transInFlight++;
921             }
922             // END IASRI 4662745
923         }
924         ***/

925         ((TransactionManagerImpl)tm).begin(getEffectiveTimeout());
926
927         // START IASRI 4662745
928
if (monitoringEnabled) {
929             Transaction tran = tm.getTransaction();
930             activeTransactions.addElement(tran);
931             m_transInFlight++;
932         }
933        // END IASRI 4662745
934
// END IASRI PERFIMPROVEMENT
935
}
936
937     /**
938      * Complete the transaction associated with the current thread. When this
939      * method completes, the thread becomes associated with no transaction.
940      *
941      * @exception RollbackException Thrown to indicate that
942      * the transaction has been rolled back rather than committed.
943      *
944      * @exception HeuristicMixedException Thrown to indicate that a heuristic
945      * decision was made and that some relevant updates have been committed
946      * while others have been rolled back.
947      *
948      * @exception HeuristicRollbackException Thrown to indicate that a
949      * heuristic decision was made and that some relevant updates have been
950      * rolled back.
951      *
952      * @exception SecurityException Thrown to indicate that the thread is
953      * not allowed to commit the transaction.
954      *
955      * @exception IllegalStateException Thrown if the current thread is
956      * not associated with a transaction.
957      *
958      * @exception SystemException Thrown if the transaction manager
959      * encounters an unexpected error condition
960      *
961      */

962     public void commit() throws RollbackException,
963     HeuristicMixedException, HeuristicRollbackException, SecurityException JavaDoc,
964     IllegalStateException JavaDoc, SystemException {
965         if (_logger.isLoggable(Level.FINE))
966             _logger.log(Level.FINE,"TM: commit");
967         validateTransactionManager();
968         Object JavaDoc obj = null;
969         if(monitoringEnabled){
970             obj = tm.getTransaction();
971         }
972         if (invMgr.isInvocationStackEmpty()) {
973             try{
974                 tm.commit();
975                 if (monitoringEnabled){
976                     monitorTxCompleted(obj, true);
977                 }
978             }catch(RollbackException e){
979                 if (monitoringEnabled){
980                     monitorTxCompleted(obj, false);
981                 }
982                 throw e;
983             }catch(HeuristicRollbackException e){
984                 if (monitoringEnabled){
985                     monitorTxCompleted(obj, false);
986                 }
987                 throw e;
988             }catch(HeuristicMixedException e){
989                 if (monitoringEnabled){
990                     monitorTxCompleted(obj, true);
991                 }
992                 throw e;
993             }
994         } else {
995             ComponentInvocation curr = null;
996             try {
997                 curr = invMgr.getCurrentInvocation();
998                 curr.setTransactionCompeting(true);
999                 tm.commit();
1000                if (monitoringEnabled){
1001                    monitorTxCompleted(obj, true);
1002                }
1003            } catch (InvocationException ex) {
1004                assert false;
1005            }catch(RollbackException e){
1006                if (monitoringEnabled){
1007                    monitorTxCompleted(obj, false);
1008                }
1009                throw e;
1010            }catch(HeuristicRollbackException e){
1011                if (monitoringEnabled){
1012                    monitorTxCompleted(obj, false);
1013                }
1014                throw e;
1015            }catch(HeuristicMixedException e){
1016                if (monitoringEnabled){
1017                    monitorTxCompleted(obj, true);
1018                }
1019                throw e;
1020            } finally {
1021                if (curr != null) {
1022                    curr.setTransactionCompeting(false);
1023                }
1024            }
1025        }
1026        
1027    }
1028
1029    /**
1030     * Obtain the status of the transaction associated with the current thread.
1031     *
1032     * @return The transaction status. If no transaction is associated with
1033     * the current thread, this method returns the Status.NoTransaction
1034     * value.
1035     *
1036     * @exception SystemException Thrown if the transaction manager
1037     * encounters an unexpected error condition
1038     *
1039     */

1040    public int getStatus() throws SystemException {
1041        if (tm != null) {
1042            return tm.getStatus();
1043        } else {
1044            return javax.transaction.Status.STATUS_NO_TRANSACTION;
1045        }
1046    }
1047
1048    /**
1049     * Get the transaction object that represents the transaction
1050     * context of the calling thread
1051     *
1052     * @exception SystemException Thrown if the transaction manager
1053     * encounters an unexpected error condition
1054     *
1055     */

1056    public Transaction getTransaction() throws SystemException {
1057        if (tm == null) {
1058            return null;
1059        } else {
1060            return tm.getTransaction();
1061        }
1062    }
1063
1064    /**
1065     * Resume the transaction context association of the calling thread
1066     * with the transaction represented by the supplied Transaction object.
1067     * When this method returns, the calling thread is associated with the
1068     * transaction context specified.
1069     *
1070     * @exception InvalidTransactionException Thrown if the parameter
1071     * transaction object contains an invalid transaction
1072     *
1073     * @exception IllegalStateException Thrown if the thread is already
1074     * associated with another transaction.
1075     *
1076     * @exception SystemException Thrown if the transaction manager
1077     * encounters an unexpected error condition
1078     */

1079    public void resume(Transaction tobj)
1080        throws InvalidTransactionException, IllegalStateException JavaDoc,
1081            SystemException {
1082        if (_logger.isLoggable(Level.FINE))
1083            _logger.log(Level.FINE,"TM: resume");
1084        tm.resume(tobj);
1085    }
1086
1087
1088    /**
1089     * Roll back the transaction associated with the current thread. When this
1090     * method completes, the thread becomes associated with no transaction.
1091     *
1092     * @exception SecurityException Thrown to indicate that the thread is
1093     * not allowed to roll back the transaction.
1094     *
1095     * @exception IllegalStateException Thrown if the current thread is
1096     * not associated with a transaction.
1097     *
1098     * @exception SystemException Thrown if the transaction manager
1099     * encounters an unexpected error condition
1100     *
1101     */

1102    public void rollback() throws IllegalStateException JavaDoc, SecurityException JavaDoc,
1103    SystemException {
1104        if (_logger.isLoggable(Level.FINE))
1105            _logger.log(Level.FINE,"TM: rollback");
1106        validateTransactionManager();
1107        // START IASRI 4662745
1108
Object JavaDoc obj = null;
1109        if (monitoringEnabled){
1110            obj = tm.getTransaction();
1111        }
1112        if (invMgr.isInvocationStackEmpty()) {
1113            tm.rollback();
1114        } else {
1115            ComponentInvocation curr = null;
1116            try {
1117                curr = invMgr.getCurrentInvocation();
1118                curr.setTransactionCompeting(true);
1119                tm.rollback();
1120            } catch (InvocationException ex) {
1121                assert false;
1122            } finally {
1123                if (curr != null) {
1124                    curr.setTransactionCompeting(false);
1125                }
1126            }
1127        }
1128        
1129        if (monitoringEnabled){
1130            monitorTxCompleted(obj, false);
1131        }
1132        // END IASRI 4662745
1133

1134    }
1135    
1136    /**
1137     * Modify the transaction associated with the current thread such that
1138     * the only possible outcome of the transaction is to roll back the
1139     * transaction.
1140     *
1141     * @exception IllegalStateException Thrown if the current thread is
1142     * not associated with a transaction.
1143     *
1144     * @exception SystemException Thrown if the transaction manager
1145     * encounters an unexpected error condition
1146     *
1147     */

1148    public void setRollbackOnly()
1149        throws IllegalStateException JavaDoc, SystemException {
1150        if (_logger.isLoggable(Level.FINE))
1151            _logger.log(Level.FINE,"TM: setRollbackOnly");
1152        validateTransactionManager();
1153        tm.setRollbackOnly();
1154    }
1155
1156    /**
1157     * Modify the value of the timeout value that is associated with the
1158     * transactions started by the current thread with the begin method.
1159     *
1160     * <p> If an application has not called this method, the transaction
1161     * service uses some default value for the transaction timeout.
1162     *
1163     * @param seconds The value of the timeout in seconds. If the value
1164     * is zero, the transaction service restores the default value.
1165     *
1166     * @exception SystemException Thrown if the transaction manager
1167     * encounters an unexpected error condition
1168     *
1169     */

1170    public void setTransactionTimeout(int seconds) throws SystemException {
1171        if (seconds < 0) seconds = 0;
1172        txnTmout.set(seconds);
1173        // transactionTimeout = seconds;
1174
}
1175
1176    public void cleanTxnTimeout() {
1177        txnTmout.set(null);
1178    }
1179
1180    int getEffectiveTimeout() {
1181        Integer JavaDoc tmout = txnTmout.get();
1182        if (tmout == null) {
1183            return transactionTimeout;
1184        }
1185        else {
1186            return tmout;
1187        }
1188    }
1189
1190    public void setDefaultTransactionTimeout(int seconds) {
1191        if (seconds < 0) seconds = 0;
1192        transactionTimeout = seconds;
1193    }
1194
1195    /**
1196     * Suspend the transaction currently associated with the calling
1197     * thread and return a Transaction object that represents the
1198     * transaction context being suspended. If the calling thread is
1199     * not associated with a transaction, the method returns a null
1200     * object reference. When this method returns, the calling thread
1201     * is associated with no transaction.
1202     *
1203     * @exception SystemException Thrown if the transaction manager
1204     * encounters an unexpected error condition
1205     *
1206     * @exception SystemException Thrown if the transaction manager
1207     * encounters an unexpected error condition
1208     *
1209     */

1210    public Transaction suspend() throws SystemException {
1211        if (_logger.isLoggable(Level.FINE))
1212            _logger.log(Level.FINE,"TM: suspend");
1213        validateTransactionManager();
1214        return tm.suspend();
1215    }
1216
1217    // START IASRI 4662745
1218
/*
1219    * This method returns the details of the Currently Active Transactions
1220    * Called by Admin Framework when transaction monitoring is enabled
1221    * @returns ArrayList of TransactionAdminBean
1222    * @see TransactionAdminBean
1223    */

1224    public ArrayList getActiveTransactions() {
1225    ArrayList tranBeans = new ArrayList();
1226        Vector active = (Vector)activeTransactions.clone(); // get the clone of the active transactions
1227
for(int i=0;i<active.size();i++){
1228            try{
1229                Transaction tran = (Transaction)active.elementAt(i);
1230                String JavaDoc id="unknown";
1231                long startTime = 0;
1232                long elapsedTime = 0;
1233                String JavaDoc status = "unknown";
1234                String JavaDoc componentName = "unknown";
1235                ArrayList<String JavaDoc> resourceNames = null;
1236                if(tran instanceof com.sun.jts.jta.TransactionImpl){
1237                    id=((com.sun.jts.jta.TransactionImpl)tran).getTransactionId();
1238                    startTime = ((com.sun.jts.jta.TransactionImpl)tran).getStartTime();
1239
1240                }else if(tran instanceof J2EETransaction){
1241                    J2EETransaction tran1 = (J2EETransaction)tran;
1242                    id=tran1.getTransactionId();
1243                    startTime = tran1.getStartTime();
1244                    componentName = tran1.getComponentName();
1245                    resourceNames = tran1.getResourceNames();
1246                }
1247                elapsedTime = System.currentTimeMillis()-startTime;
1248                status = (String JavaDoc)statusMap.get(new Integer JavaDoc(tran.getStatus()));
1249                TransactionAdminBean tBean = new TransactionAdminBean(tran,id,status,elapsedTime,
1250                                             componentName, resourceNames);
1251                tranBeans.add(tBean);
1252            }catch(Exception JavaDoc ex){
1253                //LOG !!!
1254
}
1255        }
1256    return tranBeans;
1257    }
1258    /*
1259    * Called by Admin Framework when transaction monitoring is enabled
1260    */

1261    public void forceRollback(Transaction tran) throws IllegalStateException JavaDoc, SystemException{
1262        if (tran != null){
1263            tran.setRollbackOnly();
1264        }
1265    }
1266    /* Returned Number of transactions commited since the time monitoring
1267     * was enabeld
1268     * Called by Admin Framework when transaction monitoring is enabled
1269     */

1270
1271    public int getNumberOfTransactionsCommitted(){
1272        return m_transCommitted;
1273    }
1274
1275    /* Returned Number of transactions Rolledback since the time monitoring
1276     * was enabeld
1277     * Called by Admin Framework when transaction monitoring is enabled
1278     */

1279    public int getNumberOfTransactionsRolledBack(){
1280        return m_transRolledback;
1281    }
1282
1283    /* Returned Number of transactions Active
1284     * Called by Admin Framework when transaction monitoring is enabled
1285     */

1286    public int getNumberOfActiveTransactions(){
1287        return m_transInFlight;
1288    }
1289    /*
1290     * Called by Admin Framework to freeze the transactions.
1291     */

1292    public synchronized void freeze(){
1293        if(com.sun.jts.CosTransactions.AdminUtil.isFrozenAll()){
1294            //multiple freezes will hang this thread, therefore just return
1295
return;
1296        }
1297        com.sun.jts.CosTransactions.AdminUtil.freezeAll();
1298    }
1299    /*
1300     * Called by Admin Framework to freeze the transactions. These undoes the work done by the freeze.
1301     */

1302    public synchronized void unfreeze(){
1303        if(com.sun.jts.CosTransactions.AdminUtil.isFrozenAll()){
1304            com.sun.jts.CosTransactions.AdminUtil.unfreezeAll();
1305        }
1306    }
1307
1308    /*
1309     * Called by Admin Framework.
1310     */

1311    public synchronized boolean isFrozen(){
1312        return com.sun.jts.CosTransactions.AdminUtil.isFrozenAll();
1313    }
1314
1315
1316    /**
1317     * Recreate a transaction based on the Xid. This call causes the calling
1318     * thread to be associated with the specified transaction. <p>
1319     * This is used by importing transactions via the Connector contract.
1320     *
1321     * @param xid the Xid object representing a transaction.
1322     */

1323    public void recreate(Xid xid, long timeout) throws WorkException JavaDoc {
1324        ((TransactionManagerImpl) tm).recreate(xid, timeout);
1325    }
1326
1327    /**
1328     * Release a transaction. This call causes the calling thread to be
1329     * dissociated from the specified transaction. <p>
1330     * This is used by importing transactions via the Connector contract.
1331     *
1332     * @param xid the Xid object representing a transaction.
1333     */

1334    public void release(Xid xid) throws WorkException JavaDoc {
1335        ((TransactionManagerImpl) tm).release(xid);
1336    }
1337
1338    /**
1339     * Provides a handle to a <code>XATerminator</code> instance. The
1340     * <code>XATerminator</code> instance could be used by a resource adapter
1341     * to flow-in transaction completion and crash recovery calls from an EIS.
1342     * <p>
1343     * This is used by importing transactions via the Connector contract.
1344     *
1345     * @return a <code>XATerminator</code> instance.
1346     */

1347    public XATerminator JavaDoc getXATerminator() {
1348        return ((TransactionManagerImpl) tm).getXATerminator();
1349    }
1350
1351
1352    protected void monitorTxCompleted(Object JavaDoc tran, boolean committed){
1353        if(tran==null || !activeTransactions.remove(tran)){
1354            // WARN !!!
1355
return;
1356        }
1357        if(committed){
1358            m_transCommitted++;
1359        }else{
1360            m_transRolledback++;
1361        }
1362        m_transInFlight--;
1363    }
1364    public void setMonitoringEnabled(boolean enabled){
1365        monitoringEnabled = enabled;
1366    //reset the variables
1367
m_transCommitted = 0;
1368        m_transRolledback = 0;
1369        m_transInFlight = 0;
1370        activeTransactions.removeAllElements();
1371    }
1372    static {
1373        com.sun.enterprise.admin.event.AdminEventListenerRegistry.addEventListener(JTSEvent.eventType, new JTSConfigChangeEventListener());
1374    }
1375    // END IASRI 4662745
1376

1377    // overridden in the Opt
1378
public boolean isTimedOut() {
1379        return false;
1380    }
1381
1382    // START IASRI 4705808 TTT004 -- monitor resource table stats
1383
// Mods: Adding method for statistic dumps using TimerTask
1384
private void registerStatisticMonitorTask() {
1385        TimerTask task = new StatisticMonitorTask();
1386        Timer timer = Switch.getSwitch().getTimer();
1387        // for now, get monitoring interval from system prop
1388
int statInterval = 2 * 60 * 1000;
1389        try {
1390        String JavaDoc interval
1391        = System.getProperty("MONITOR_JTA_RESOURCE_TABLE_SECONDS");
1392            int temp = Integer.parseInt(interval);
1393            if (temp > 0) {
1394                statInterval = temp;
1395            }
1396        } catch (Exception JavaDoc ex) {
1397            // ignore
1398
}
1399
1400        timer.scheduleAtFixedRate(task, 0, statInterval);
1401    }
1402
1403    // Mods: Adding TimerTask class for statistic dumps
1404
class StatisticMonitorTask extends TimerTask {
1405        public void run() {
1406            if (resourceTable != null) {
1407                Map stats = resourceTable.getStats();
1408                Iterator it = stats.keySet().iterator();
1409                String JavaDoc key;
1410        //FIXME: use logger instead of System.out
1411
System.out.println("********** J2EETransactionManagerImpl.resourceTable stats *****");
1412                while (it.hasNext()) {
1413                    key = (String JavaDoc)it.next();
1414                    System.out.println(key + ": " + stats.get(key).toString());
1415                }
1416            }
1417        }
1418    }
1419    // END IASRI 4705808 TTT004
1420
}
1421
Popular Tags