1 23 package com.sun.enterprise.resource; 24 25 import java.util.*; 26 import java.util.logging.*; 27 28 import javax.transaction.*; 29 import javax.transaction.xa.*; 30 31 import com.sun.logging.*; 32 import com.sun.enterprise.*; 33 import com.sun.enterprise.log.Log; 34 35 40 public class ResourceManagerImpl implements ResourceManager { 41 42 43 static Logger _logger = null; 44 static { 45 _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 46 } 47 48 54 public Transaction getTransaction() throws PoolingException{ 55 InvocationManager invmgr = 56 Switch.getSwitch().getInvocationManager(); 57 ComponentInvocation inv = invmgr.getCurrentInvocation(); 58 if (inv == null) { try { 60 return Switch.getSwitch().getTransactionManager().getTransaction(); 61 } catch (Exception ex) { 62 return null; 63 } 64 } 65 return inv.getTransaction(); 66 } 67 68 73 public Object getComponent(){ 74 75 InvocationManager invmgr = 76 Switch.getSwitch().getInvocationManager(); 77 ComponentInvocation inv = invmgr.getCurrentInvocation(); 78 if (inv == null) { 79 return null; 80 } 81 82 return inv.getInstance(); 83 } 84 85 91 public void enlistResource(ResourceHandle h) throws PoolingException{ 92 registerResource(h); 93 } 94 95 101 public void registerResource(ResourceHandle handle) 102 throws PoolingException 103 { 104 try { 105 Transaction tran = null; 106 J2EETransactionManager tm = 107 Switch.getSwitch().getTransactionManager(); 108 if (handle.isTransactional()) { 110 InvocationManager invmgr = 111 Switch.getSwitch().getInvocationManager(); 112 ComponentInvocation inv = invmgr.getCurrentInvocation(); 113 114 if (inv == null) { 115 117 try { 122 tran = tm.getTransaction(); 123 } catch( Exception e ) { 124 tran = null; 125 _logger.log(Level.INFO, e.getMessage()); 126 } 127 } else { 128 tran = inv.getTransaction(); 129 tm.registerComponentResource(handle); 130 } 131 132 if (tran != null) { 133 try{ 134 tm.enlistResource(tran, handle); 135 } catch (Exception ex) { 136 _logger.fine("Exception whle trying to enlist resource " + ex.getMessage()); 137 if(inv != null) { 141 _logger.fine("Attempting to unregister component resource"); 142 tm.unregisterComponentResource(handle); 143 } 144 throw ex; 145 } 146 } 147 } 148 149 } catch (Exception ex) { 150 _logger.log(Level.SEVERE,"poolmgr.component_register_exception",ex); 151 throw new PoolingException(ex.toString(), ex); 152 } 153 } 154 155 protected void enlist( J2EETransactionManager tm, Transaction tran, 157 ResourceHandle h ) throws PoolingException { 158 try { 159 tm.enlistResource( tran, h ); 160 } catch( Exception e ) { 161 PoolingException pe = new PoolingException( e.getMessage() ); 162 pe.initCause( e ); 163 throw pe; 164 } 165 } 166 167 170 public void rollBackTransaction() { 171 InvocationManager invmgr = 172 Switch.getSwitch().getInvocationManager(); 173 J2EETransactionManager tm = Switch.getSwitch().getTransactionManager(); 174 Transaction tran = null; 175 try { 176 ComponentInvocation inv = invmgr.getCurrentInvocation(); 177 if (inv == null) { 178 180 try { 185 tran = tm.getTransaction(); 186 } catch( Exception e ) { 187 tran = null; 188 _logger.log(Level.INFO, e.getMessage()); 189 } 190 191 } else { 192 tran = inv.getTransaction(); 193 } 194 if (tran != null) { 195 tran.setRollbackOnly(); 196 } 197 } catch (SystemException ex) { 198 _logger.log(Level.WARNING,"poolmgr.system_exception",ex); 199 } catch (IllegalStateException ex) { 200 } 202 } 203 204 212 public void delistResource(ResourceHandle resource, int xaresFlag) { 213 unregisterResource(resource,xaresFlag); 214 } 215 216 224 public void unregisterResource(ResourceHandle resource, 225 int xaresFlag) { 226 227 J2EETransactionManager tm = 228 Switch.getSwitch().getTransactionManager(); 229 Transaction tran = null; 230 231 try { 232 if (resource.isTransactional()) { 234 InvocationManager invmgr = 235 Switch.getSwitch().getInvocationManager(); 236 ComponentInvocation inv = invmgr.getCurrentInvocation(); 237 if (inv == null) { 238 240 try { 245 tran = tm.getTransaction(); 246 } catch ( Exception e ) { 247 tran = null; 248 _logger.log( Level.INFO, e.getMessage() ); 249 } 250 } else { 251 tran = inv.getTransaction(); 252 tm.unregisterComponentResource(resource); 253 } 254 if (tran != null && resource.isEnlisted() ) { 255 tm.delistResource(tran, resource, xaresFlag); 256 } 257 } 258 } catch (SystemException ex) { 259 _logger.log(Level.WARNING,"poolmgr.system_exception",ex); 260 } catch (IllegalStateException ex) { 261 } catch (InvocationException ex) { 263 } 266 267 } 268 } 269 | Popular Tags |