1 23 24 package com.sun.enterprise.resource; 25 26 27 import java.util.logging.Level ; 28 29 import javax.transaction.xa.XAResource ; 30 import javax.resource.spi.*; 31 import javax.resource.ResourceException ; 32 import javax.security.auth.Subject ; 33 34 import com.sun.enterprise.deployment.ConnectorDescriptor; 35 import com.sun.enterprise.PoolManager; 36 37 38 41 public class ConnectorAllocator extends AbstractConnectorAllocator { 42 43 private boolean shareable; 44 45 46 class ConnectionListenerImpl implements ConnectionEventListener { 47 private ResourceHandle resource; 48 49 public ConnectionListenerImpl(ResourceHandle resource) { 50 this.resource = resource; 51 } 52 53 public void connectionClosed(ConnectionEvent evt) { 54 if (resource.hasConnectionErrorOccurred()) { 55 return; 56 } 57 58 resource.decrementCount(); 59 if (resource.getShareCount() == 0) { 60 poolMgr.resourceClosed(resource); 61 } 62 63 } 64 65 public void connectionErrorOccurred(ConnectionEvent evt) { 66 resource.setConnectionErrorOccurred(); 67 68 ManagedConnection mc = (ManagedConnection) evt.getSource(); 69 mc.removeConnectionEventListener(this); 70 poolMgr.resourceErrorOccurred(resource); 71 try { 72 mc.destroy(); 73 } catch (ResourceException ex) { 74 } 76 } 77 78 public void localTransactionStarted(ConnectionEvent evt) { 79 } 81 82 public void localTransactionCommitted(ConnectionEvent evt) { 83 } 85 86 public void localTransactionRolledback(ConnectionEvent evt) { 87 } 89 } 90 91 public ConnectorAllocator(PoolManager poolMgr, 92 ManagedConnectionFactory mcf, 93 ResourceSpec spec, 94 Subject subject, 95 ConnectionRequestInfo reqInfo, 96 ClientSecurityInfo info, 97 ConnectorDescriptor desc, 98 boolean shareable) { 99 super(poolMgr, mcf, spec, subject, reqInfo, info, desc); 100 this.shareable = shareable; 101 } 102 103 104 public ResourceHandle createResource() 105 throws PoolingException 106 { 107 try { 108 ManagedConnection mc = 109 mcf.createManagedConnection(subject, reqInfo); 110 111 ResourceHandle resource = 112 new ResourceHandle(mc, spec, this, info); 113 ConnectionEventListener l = 114 new ConnectionListenerImpl(resource); 115 mc.addConnectionEventListener(l); 116 return resource; 117 } catch (ResourceException ex) { 118 throw new PoolingException(ex); 119 } 120 } 121 122 public void fillInResourceObjects(ResourceHandle resource) 123 throws PoolingException 124 { 125 try { 126 ManagedConnection mc = (ManagedConnection) resource.getResource(); 127 Object con = mc.getConnection( subject, reqInfo ); 128 resource.incrementCount(); 129 XAResource xares = mc.getXAResource(); 130 resource.fillInResourceObjects(con, xares); 131 } catch( ResourceException ex ) { 132 throw new PoolingException( ex ); 133 } 134 } 135 136 public void destroyResource(ResourceHandle resource) 137 throws PoolingException { 138 139 try { 140 closeUserConnection(resource); 141 } catch (Exception ex) { 142 } 144 145 try { 146 ManagedConnection mc = (ManagedConnection) resource.getResource(); 147 mc.destroy(); 148 } catch (Exception ex) { 149 _logger.log(Level.WARNING, ex.getMessage()); 150 throw new PoolingException(ex); 151 } 152 153 } 154 155 public boolean shareableWithinComponent() { 156 return shareable; 157 } 158 } 159 | Popular Tags |