1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import javax.resource.ResourceException ; 21 import javax.resource.spi.ConnectionManager ; 22 import javax.resource.spi.ConnectionRequestInfo ; 23 import javax.resource.spi.LazyAssociatableConnectionManager ; 24 import javax.resource.spi.ManagedConnectionFactory ; 25 26 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport; 27 import org.apache.geronimo.transaction.manager.NamedXAResource; 28 29 32 public abstract class AbstractConnectionManager implements ConnectionManagerContainer, ConnectionManager , LazyAssociatableConnectionManager , PoolingAttributes { 33 protected final Interceptors interceptors; 34 35 public AbstractConnectionManager() { 37 interceptors = null; 38 } 39 40 public AbstractConnectionManager(Interceptors interceptors) { 41 this.interceptors = interceptors; 42 } 43 44 public Object createConnectionFactory(ManagedConnectionFactory mcf) throws ResourceException { 45 return mcf.createConnectionFactory(this); 46 } 47 48 public ConnectionManager getConnectionManager() { 49 return this; 50 } 51 52 56 public Object allocateConnection(ManagedConnectionFactory managedConnectionFactory, 57 ConnectionRequestInfo connectionRequestInfo) 58 throws ResourceException { 59 ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, connectionRequestInfo); 60 ConnectionInfo ci = new ConnectionInfo(mci); 61 getStack().getConnection(ci); 62 return ci.getConnectionHandle(); 63 } 64 65 70 public void associateConnection(Object connection, 71 ManagedConnectionFactory managedConnectionFactory, 72 ConnectionRequestInfo connectionRequestInfo) 73 throws ResourceException { 74 ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, connectionRequestInfo); 75 ConnectionInfo ci = new ConnectionInfo(mci); 76 ci.setConnectionHandle(connection); 77 getStack().getConnection(ci); 78 } 79 80 ConnectionInterceptor getConnectionInterceptor() { 81 return getStack(); 82 } 83 84 85 public ConnectionManagerContainer.ReturnableXAResource getRecoveryXAResource(ManagedConnectionFactory managedConnectionFactory) throws ResourceException { 86 ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, null); 87 NamedXAResource namedXAResource = (NamedXAResource) mci.getXAResource(); 88 if (namedXAResource == null) { 89 return null; 91 } 92 ConnectionInfo recoveryConnectionInfo = new ConnectionInfo(mci); 93 getRecoveryStack().getConnection(recoveryConnectionInfo); 94 return new ConnectionManagerContainer.ReturnableXAResource(namedXAResource, getRecoveryStack(), recoveryConnectionInfo); 95 } 96 97 99 public int getPartitionCount() { 100 return getPooling().getPartitionCount(); 101 } 102 103 public int getPartitionMaxSize() { 104 return getPooling().getPartitionMaxSize(); 105 } 106 107 public void setPartitionMaxSize(int maxSize) throws InterruptedException { 108 getPooling().setPartitionMaxSize(maxSize); 109 } 110 111 public int getPartitionMinSize() { 112 return getPooling().getPartitionMinSize(); 113 } 114 115 public void setPartitionMinSize(int minSize) { 116 getPooling().setPartitionMinSize(minSize); 117 } 118 119 public int getIdleConnectionCount() { 120 return getPooling().getIdleConnectionCount(); 121 } 122 123 public int getConnectionCount() { 124 return getPooling().getConnectionCount(); 125 } 126 127 public int getBlockingTimeoutMilliseconds() { 128 return getPooling().getBlockingTimeoutMilliseconds(); 129 } 130 131 public void setBlockingTimeoutMilliseconds(int timeoutMilliseconds) { 132 getPooling().setBlockingTimeoutMilliseconds(timeoutMilliseconds); 133 } 134 135 public int getIdleTimeoutMinutes() { 136 return getPooling().getIdleTimeoutMinutes(); 137 } 138 139 public void setIdleTimeoutMinutes(int idleTimeoutMinutes) { 140 getPooling().setIdleTimeoutMinutes(idleTimeoutMinutes); 141 } 142 143 private ConnectionInterceptor getStack() { 144 return interceptors.getStack(); 145 } 146 147 private ConnectionInterceptor getRecoveryStack() { 148 return interceptors.getRecoveryStack(); 149 } 150 151 public PoolingSupport getPooling() { 153 return interceptors.getPoolingAttributes(); 154 } 155 156 public interface Interceptors { 157 ConnectionInterceptor getStack(); 158 159 ConnectionInterceptor getRecoveryStack(); 160 161 PoolingSupport getPoolingAttributes(); 162 } 163 164 public void doStart() throws Exception { 165 166 } 167 168 public void doStop() throws Exception { 169 interceptors.getStack().destroy(); 170 } 171 172 public void doFail() { 173 interceptors.getStack().destroy(); 174 } 175 } 176 | Popular Tags |