1 43 package org.objectweb.jotm; 44 45 import java.net.InetAddress ; 46 import java.util.Vector ; 47 import java.rmi.RemoteException ; 48 import javax.transaction.xa.Xid ; 49 import javax.rmi.PortableRemoteObject ; 50 51 public class TransactionFactoryImpl 52 extends PortableRemoteObject 53 implements TransactionFactory { 54 55 58 int timeoutMax = 3600; 60 private Vector coordinatorList = new Vector (); 61 62 65 public TransactionFactoryImpl() throws RemoteException { 66 if (TraceTm.jotm.isDebugEnabled()) { 67 TraceTm.jotm.debug("default constructor"); 68 } 69 } 70 71 76 public synchronized Control create(int timeout) throws RemoteException { 77 if (TraceTm.jotm.isDebugEnabled()) { 78 TraceTm.jotm.debug("timeout=" + timeout); 79 } 80 81 ControlImpl ctrl = null; 82 83 if (timeout == 0 || timeout > timeoutMax) 85 timeout = timeoutMax; 86 87 XidImpl xid = new XidImpl("TMServer", 0); 90 91 try { 93 ctrl = new ControlImpl(timeout, xid, null); 94 } catch (Exception e) { 95 TraceTm.jotm.error("Cannot create ControlImpl", e); 96 } 97 return ctrl; 98 } 99 100 107 public synchronized Control recreate(TransactionContext ctx) throws RemoteException { 108 if (TraceTm.jotm.isDebugEnabled()) { 109 TraceTm.jotm.debug("TransactionContext=" + ctx); 110 } 111 112 ControlImpl ctrl = null; 114 115 synchronized (coordinatorList) { 116 for (int i = 0; i < coordinatorList.size(); i++) { 117 Coordinator coord = (Coordinator) coordinatorList.elementAt(i); 118 if (coord.equals(ctx.getCoordinator())) { 119 if (TraceTm.jotm.isDebugEnabled()) { 120 TraceTm.jotm.debug("recreate: Control already in the list"); 121 } 122 ctrl = (ControlImpl) coord; 123 break; 124 } 125 } 126 } 127 if (ctrl != null) { 128 if (TraceTm.jotm.isDebugEnabled()) { 129 TraceTm.jotm.debug("recreate twice"); 130 } 131 return ctrl; 132 } 133 134 Xid xid = ctx.getXid(); 136 137 try { 140 ctrl = new ControlImpl(ctx.getTimeout(), xid, ctx.getCoordinator()); 141 } catch (Exception e) { 142 TraceTm.jotm.error("Cannot create ControlImpl", e); 143 } 144 return ctrl; 145 } 146 147 151 public int getPortNumber() throws RemoteException { 152 return 0; 154 } 155 156 160 public String getHostName() throws RemoteException { 161 try { 162 return InetAddress.getLocalHost().getHostName(); 163 } catch (Exception e) { 164 throw new RemoteException ("" + e); 165 } 166 } 167 } 168 | Popular Tags |