1 23 package com.sun.enterprise.resource; 24 25 import com.sun.enterprise.util.i18n.StringManager; 26 import javax.transaction.*; 27 import javax.resource.spi.ManagedConnection ; 28 import java.util.logging.Level ; 29 import java.util.List ; 30 import com.sun.enterprise.distributedtx.J2EETransactionManagerImpl; 31 import com.sun.enterprise.J2EETransactionManager; 32 import com.sun.enterprise.Switch; 33 import javax.resource.ResourceException ; 34 import com.sun.enterprise.PoolManager; 35 import com.sun.enterprise.ComponentInvocation; 36 import java.util.ListIterator ; 37 38 43 public class LazyEnlistableResourceManagerImpl extends ResourceManagerImpl { 44 45 private static StringManager sm = 46 StringManager.getManager(LazyEnlistableResourceManagerImpl.class); 47 48 protected void enlist( J2EETransactionManager tm, Transaction tran, 49 ResourceHandle h ) 50 { 51 } 53 54 59 public void registerResource(ResourceHandle handle) 60 throws PoolingException { 61 handle.setEnlistmentSuspended(true); 62 super.registerResource(handle); 63 } 64 68 public void lazyEnlist( ManagedConnection mc ) throws ResourceException { 69 if ( _logger.isLoggable(Level.FINE) ) { 70 _logger.fine("@@@@ Entering lazyEnlist"); 71 } 72 73 J2EETransactionManager tm = Switch.getSwitch().getTransactionManager(); 74 75 Transaction tran = null; 76 77 try { 78 tran = tm.getTransaction(); 79 if ( tran == null ) { 80 if (_logger.isLoggable(Level.FINE)) { 81 _logger.fine(" Transaction null - not enlisting "); 82 } 83 84 return; 85 } 86 } catch( SystemException se ) { 87 ResourceException re = new ResourceException ( se.getMessage() ); 88 re.initCause( se ); 89 throw re; 90 } 91 92 93 List invList = Switch.getSwitch().getInvocationManager().getAllInvocations(); 94 95 ResourceHandle h = null; 96 for ( int j = invList.size(); j > 0; j-- ) { 97 ComponentInvocation inv = (ComponentInvocation) invList.get( j - 1 ); 98 Object comp = inv.getInstance(); 99 100 List l = ((J2EETransactionManagerImpl)tm).getResourceList( comp, inv ); 101 102 ListIterator it = l.listIterator(); 103 while( it.hasNext()) { 104 ResourceHandle hand = (ResourceHandle) it.next(); 105 ManagedConnection toEnlist = (ManagedConnection ) hand.getResource(); 106 if ( mc.equals( toEnlist ) ) { 107 h = hand; 108 break; 109 } 110 } 111 } 112 113 if( h != null && tran != null && h.getResourceState().isUnenlisted()) { 122 try { 123 h.setEnlistmentSuspended(false); 125 tm.enlistResource( tran, h ); 126 h.setEnlistmentSuspended(true); 128 } catch( Exception e ) { 129 if ( h != null ) { 132 PoolManager mgr = Switch.getSwitch().getPoolManager(); 133 mgr.putbackDirectToPool( h, h.getResourceSpec().getConnectionPoolName()); 134 } 135 _logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn"); 136 if (_logger.isLoggable(Level.FINE) ) { 137 _logger.fine("rm.enlistResource threw Exception. Returning resource to pool"); 138 } 139 throw new ResourceException ( e ); 141 } 142 } 143 } 144 145 146 } 147 | Popular Tags |