use of org.apache.geronimo.connector.outbound.GenericConnectionManager in project aries by apache.
the class ConnectionManagerFactory method init.
public void init() throws Exception {
if (transactionManager == null && ("xa".equals(transaction) || "local".equals(transaction))) {
throw new IllegalArgumentException("transactionManager must be set");
}
if (managedConnectionFactory == null) {
throw new IllegalArgumentException("managedConnectionFactory must be set");
}
// Apply the default value for property if necessary
if (transactionSupport == null) {
// No transaction
if ("local".equalsIgnoreCase(transaction)) {
transactionSupport = LocalTransactions.INSTANCE;
} else if ("none".equalsIgnoreCase(transaction)) {
transactionSupport = NoTransactions.INSTANCE;
} else if ("xa".equalsIgnoreCase(transaction)) {
transactionSupport = new XATransactions(true, false);
} else {
throw new IllegalArgumentException("Unknown transaction type " + transaction + " (must be local, none or xa)");
}
}
if (poolingSupport == null) {
// No pool
if (!pooling) {
poolingSupport = new NoPool();
} else {
if (partitionStrategy == null || "none".equalsIgnoreCase(partitionStrategy)) {
// unpartitioned pool
poolingSupport = new SinglePool(poolMaxSize, poolMinSize, connectionMaxWaitMilliseconds, connectionMaxIdleMinutes, allConnectionsEqual, !allConnectionsEqual, false);
} else if ("by-connector-properties".equalsIgnoreCase(partitionStrategy)) {
// partition by connector properties such as username and password on a jdbc connection
poolingSupport = new PartitionedPool(poolMaxSize, poolMinSize, connectionMaxWaitMilliseconds, connectionMaxIdleMinutes, allConnectionsEqual, !allConnectionsEqual, false, true, false);
} else if ("by-subject".equalsIgnoreCase(partitionStrategy)) {
// partition by caller subject
poolingSupport = new PartitionedPool(poolMaxSize, poolMinSize, connectionMaxWaitMilliseconds, connectionMaxIdleMinutes, allConnectionsEqual, !allConnectionsEqual, false, false, true);
} else {
throw new IllegalArgumentException("Unknown partition strategy " + partitionStrategy + " (must be none, by-connector-properties or by-subject)");
}
}
}
if (connectionTracker == null) {
connectionTracker = new ConnectionTrackingCoordinator();
}
if (transactionManagerMonitor == null && transactionManager != null) {
transactionManagerMonitor = new GeronimoTransactionListener(connectionTracker);
transactionManager.addTransactionAssociationListener(transactionManagerMonitor);
}
if (connectionManager == null) {
if (validateOnMatch || backgroundValidation) {
// Wrap the original ManagedConnectionFactory to add validation capability
managedConnectionFactory = new ValidatingDelegatingManagedConnectionFactory((UserPasswordManagedConnectionFactory) managedConnectionFactory);
}
if (backgroundValidation) {
// Instantiate the Validating Connection Manager
connectionManager = new ValidatingGenericConnectionManager(transactionSupport, poolingSupport, subjectSource, connectionTracker, transactionManager, managedConnectionFactory, name != null ? name : getClass().getName(), getClass().getClassLoader(), backgroundValidationMilliseconds);
} else {
// Instantiate the Geronimo Connection Manager
connectionManager = new GenericConnectionManager(transactionSupport, poolingSupport, subjectSource, connectionTracker, transactionManager, managedConnectionFactory, name != null ? name : getClass().getName(), getClass().getClassLoader());
}
connectionManager.doStart();
}
}
use of org.apache.geronimo.connector.outbound.GenericConnectionManager in project tomee by apache.
the class GeronimoConnectionManagerFactoryTest method evictionNotAllEquals.
@Test
public void evictionNotAllEquals() throws Exception {
final MyMcf mcf = new MyMcf();
final GeronimoConnectionManagerFactory factory = new GeronimoConnectionManagerFactory();
factory.setValidationInterval(new Duration("1 second"));
factory.setTransactionSupport("local");
factory.setMcf(mcf);
factory.setPooling(true);
factory.setPartitionStrategy("none");
factory.setTransactionManager(new TransactionManagerImpl());
factory.setPoolMinSize(1);
factory.setAllConnectionsEqual(false);
final GenericConnectionManager mgr = factory.create();
mgr.doStart();
try {
mgr.allocateConnection(mcf, new // just to use it
ConnectionRequestInfo() {
});
sleep(2500);
assertTrue(mcf.evicted.get());
assertTrue(mcf.destroyed.get());
} finally {
mgr.doStop();
}
}
use of org.apache.geronimo.connector.outbound.GenericConnectionManager in project tomee by apache.
the class GeronimoConnectionManagerFactory method create.
public GenericConnectionManager create() {
final PoolingSupport poolingSupport = createPoolingSupport();
ClassLoader classLoader = this.classLoader;
if (classLoader == null) {
Thread.currentThread().getContextClassLoader();
}
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
if (classLoader == null) {
classLoader = ClassLoader.getSystemClassLoader();
}
final TransactionSupport txSupport = createTransactionSupport();
final RecoverableTransactionManager tm;
if (transactionManager instanceof RecoverableTransactionManager) {
tm = (RecoverableTransactionManager) transactionManager;
} else {
if (txSupport.isRecoverable()) {
throw new OpenEJBRuntimeException("currently recoverable tx support (xa) needs a geronimo tx manager");
}
tm = new SimpleRecoverableTransactionManager(transactionManager, name);
}
final GenericConnectionManager mgr;
if (validationIntervalMs >= 0 && mcf instanceof ValidatingManagedConnectionFactory) {
if (name == null) {
name = getClass().getSimpleName();
}
mgr = new ValidatingGenericConnectionManager(txSupport, poolingSupport, null, new AutoConnectionTracker(), tm, mcf, name, classLoader, validationIntervalMs);
} else {
mgr = new GenericConnectionManager(txSupport, poolingSupport, null, new AutoConnectionTracker(), tm, mcf, name, classLoader);
}
return mgr;
}
use of org.apache.geronimo.connector.outbound.GenericConnectionManager in project tomee by apache.
the class GeronimoConnectionManagerFactoryTest method eviction.
// ensure we don't have an exception TOMEE-1806
@Test
public void eviction() throws Exception {
final MyMcf mcf = new MyMcf();
final GeronimoConnectionManagerFactory factory = new GeronimoConnectionManagerFactory();
factory.setValidationInterval(new Duration("1 second"));
factory.setTransactionSupport("local");
factory.setMcf(mcf);
factory.setPooling(true);
factory.setPartitionStrategy("none");
factory.setTransactionManager(new TransactionManagerImpl());
factory.setPoolMinSize(1);
factory.setAllConnectionsEqual(true);
final GenericConnectionManager mgr = factory.create();
mgr.doStart();
try {
mgr.allocateConnection(mcf, new // just to use it
ConnectionRequestInfo() {
});
sleep(2500);
assertTrue(mcf.evicted.get());
assertTrue(mcf.destroyed.get());
} finally {
mgr.doStop();
}
}
Aggregations