1 23 24 package com.sun.enterprise.resource; 25 26 import java.util.HashSet ; 27 import java.util.Set ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 31 import javax.resource.ResourceException ; 32 import javax.resource.spi.ConnectionRequestInfo ; 33 import javax.resource.spi.ManagedConnection ; 34 import javax.resource.spi.ManagedConnectionFactory ; 35 import javax.resource.spi.ValidatingManagedConnectionFactory ; 36 import javax.security.auth.Subject ; 37 38 import com.sun.enterprise.PoolManager; 39 import com.sun.enterprise.deployment.ConnectorDescriptor; 40 import com.sun.logging.LogDomains; 41 42 43 50 public abstract class AbstractConnectorAllocator 51 implements ResourceAllocator { 52 53 protected PoolManager poolMgr; 54 protected ResourceSpec spec; 55 protected ConnectionRequestInfo reqInfo; 56 protected Subject subject; 57 protected ManagedConnectionFactory mcf; 58 protected ConnectorDescriptor desc; 59 protected ClientSecurityInfo info; 60 61 protected static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 62 63 public AbstractConnectorAllocator() { 64 } 65 66 public AbstractConnectorAllocator(PoolManager poolMgr, 67 ManagedConnectionFactory mcf, 68 ResourceSpec spec, 69 Subject subject, 70 ConnectionRequestInfo reqInfo, 71 ClientSecurityInfo info, 72 ConnectorDescriptor desc) { 73 this.poolMgr = poolMgr; 74 this.mcf = mcf; 75 this.spec = spec; 76 this.subject = subject; 77 this.reqInfo = reqInfo; 78 this.info = info; 79 this.desc = desc; 80 81 } 82 83 public Set getInvalidConnections(Set connectionSet) 84 throws ResourceException { 85 if(mcf instanceof ValidatingManagedConnectionFactory ){ 86 return ((ValidatingManagedConnectionFactory )this.mcf). 87 getInvalidConnections(connectionSet); 88 } 89 return null; 90 } 91 92 public boolean isConnectionValid( ResourceHandle h ) 93 { 94 HashSet conn = new HashSet (); 95 conn.add( h.getResource() ); 96 Set invalids = null; 97 try { 98 invalids = getInvalidConnections( conn ); 99 } catch( ResourceException re ) { 100 } 102 103 if ( (invalids != null && invalids.size() > 0) || 104 h.hasConnectionErrorOccurred() ) { 105 return false; 106 } 107 108 return true; 109 } 110 111 public void destroyResource(ResourceHandle resourceHandle) 112 throws PoolingException { 113 throw new UnsupportedOperationException (); 114 } 115 116 public void fillInResourceObjects(ResourceHandle resourceHandle) 117 throws PoolingException { 118 throw new UnsupportedOperationException (); 119 } 120 121 122 123 public boolean supportsReauthentication() { 124 return this.desc.supportsReauthentication(); 125 } 126 127 public boolean isTransactional() { 128 return true; 129 } 130 131 public void cleanup(ResourceHandle h) throws PoolingException { 132 try { 133 ManagedConnection mc = (ManagedConnection ) h.getResource(); 134 mc.cleanup(); 135 } catch (Exception ex) { 136 _logger.log(Level.WARNING, "managed_con.cleanup-failed", ex); 137 throw new PoolingException(ex.toString(), ex); 138 } 139 } 140 141 public boolean matchConnection(ResourceHandle h) { 142 Set set = new HashSet (); 143 set.add(h.getResource()); 144 try { 145 ManagedConnection mc = 146 mcf.matchManagedConnections(set, subject, reqInfo); 147 return (mc != null); 148 } catch (ResourceException ex) { 149 return false; 150 } 151 } 152 153 public void closeUserConnection(ResourceHandle resource) throws PoolingException { 154 155 try { 156 ManagedConnection mc = (ManagedConnection ) resource.getResource(); 157 mc.cleanup(); 158 } catch (ResourceException ex) { 159 throw new PoolingException(ex); 160 } 161 } 162 163 public boolean shareableWithinComponent() { 164 return false; 165 } 166 167 public Object getSharedConnection(ResourceHandle h) 168 throws PoolingException { 169 throw new UnsupportedOperationException (); 170 } 171 172 } 173 | Popular Tags |