00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00088
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
00096
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
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