MySynchro.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: MySynchro.java,v 1.14 2004/10/29 23:33:37 ehardesty Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 
00027 package org.objectweb.jonas.resource;
00028 
00029 import javax.transaction.Synchronization;
00030 
00031 import org.objectweb.util.monolog.api.BasicLevel;
00032 
00033 import java.util.Iterator;
00034 import java.util.Map;
00035 
00045 public class MySynchro implements Synchronization {
00046 
00051     private MCInfo mci = null;
00055     private ConnectionManagerImpl cm = null;
00056 
00057 
00065     public MySynchro(ConnectionManagerImpl pCm, MCInfo pMci) {
00066         mci = pMci;
00067         cm = pCm;
00068         mci.synchro = this;
00069         cm.synchros.add(mci);
00070     }
00071 
00072 
00079     public void afterCompletion(int status) {
00080         if (mci == null) {
00081             return;
00082         }
00083         synchronized (cm) {
00084             mci.synchro = null;
00085             cm.synchros.remove(mci);
00086             if (!mci.usedCs.isEmpty()) {
00087                 // The transaction is finished but the connection isn't closed
00088                 // then just to dissociate the tx to the mci
00089                 cm.usedMCs.remove(mci.ctx);
00090                 mci.ctx = null;
00091                 if (cm.poolTrace.isLoggable(BasicLevel.DEBUG)) {
00092                     cm.poolTrace.log(BasicLevel.DEBUG, "state:\n" + cm.getState("\t"));
00093                 }
00094             } else {
00095                 // The transaction is finished and the logical connections have
00096                 // previously closed. Then release the mci
00097                 try {
00098                     cm.mcs.remove(mci);
00099                     if (mci.ctx != null) {
00100                         cm.usedMCs.remove(mci.ctx);
00101                     } else {
00102                         Iterator it = cm.usedMCs.entrySet().iterator();
00103                         while (it.hasNext()) {
00104                             Map.Entry me = (Map.Entry) it.next();
00105                             if (mci.equals(me.getValue())) {
00106                                 it.remove();
00107                             }
00108                         }
00109                     }
00110 
00111                     mci.ctx = null;
00112                     mci.mc.cleanup();
00113                     // Free up the PreparedStatements
00114                     mci.stmtHash.clear();
00115                     cm.poolMCs.releaseResource(mci.mc, false, false);
00116                     cm.trace.log(BasicLevel.DEBUG, "Later releasing of MC=" + mci.mc);
00117                     mci = null;
00118                     if (cm.poolTrace.isLoggable(BasicLevel.DEBUG)) {
00119                         cm.poolTrace.log(BasicLevel.DEBUG, "state\n" + cm.getState("\t"));
00120                     }
00121                 } catch (Exception e) {
00122                     cm.trace.log(BasicLevel.ERROR,
00123                             "an error related during releasing of ManagedConection",
00124                             e, "MySynchro", "afterCompletion");
00125                 }
00126             }
00127             mci = null;
00128             cm = null;
00129         }
00130     }
00131 
00132 
00137     public void beforeCompletion() {
00138     }
00139 }
00140 

Generated on Tue Feb 15 15:05:19 2005 for JOnAS by  doxygen 1.3.9.1