Search in sources :

Example 1 with GenericConnectionManager

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();
    }
}
Also used : NoPool(org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool) SinglePool(org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool) GenericConnectionManager(org.apache.geronimo.connector.outbound.GenericConnectionManager) ConnectionTrackingCoordinator(org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator) UserPasswordManagedConnectionFactory(org.tranql.connector.UserPasswordManagedConnectionFactory) XATransactions(org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions) GeronimoTransactionListener(org.apache.geronimo.connector.outbound.connectiontracking.GeronimoTransactionListener) PartitionedPool(org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool)

Example 2 with GenericConnectionManager

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();
    }
}
Also used : GenericConnectionManager(org.apache.geronimo.connector.outbound.GenericConnectionManager) TransactionManagerImpl(org.apache.geronimo.transaction.manager.TransactionManagerImpl) Duration(org.apache.openejb.util.Duration) Test(org.junit.Test)

Example 3 with GenericConnectionManager

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;
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) RecoverableTransactionManager(org.apache.geronimo.transaction.manager.RecoverableTransactionManager) GenericConnectionManager(org.apache.geronimo.connector.outbound.GenericConnectionManager) TransactionSupport(org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport) PoolingSupport(org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport) ValidatingManagedConnectionFactory(javax.resource.spi.ValidatingManagedConnectionFactory)

Example 4 with GenericConnectionManager

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();
    }
}
Also used : GenericConnectionManager(org.apache.geronimo.connector.outbound.GenericConnectionManager) TransactionManagerImpl(org.apache.geronimo.transaction.manager.TransactionManagerImpl) Duration(org.apache.openejb.util.Duration) Test(org.junit.Test)

Aggregations

GenericConnectionManager (org.apache.geronimo.connector.outbound.GenericConnectionManager)4 TransactionManagerImpl (org.apache.geronimo.transaction.manager.TransactionManagerImpl)2 Duration (org.apache.openejb.util.Duration)2 Test (org.junit.Test)2 ValidatingManagedConnectionFactory (javax.resource.spi.ValidatingManagedConnectionFactory)1 NoPool (org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool)1 PartitionedPool (org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool)1 PoolingSupport (org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport)1 SinglePool (org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool)1 TransactionSupport (org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport)1 XATransactions (org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions)1 ConnectionTrackingCoordinator (org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator)1 GeronimoTransactionListener (org.apache.geronimo.connector.outbound.connectiontracking.GeronimoTransactionListener)1 RecoverableTransactionManager (org.apache.geronimo.transaction.manager.RecoverableTransactionManager)1 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)1 UserPasswordManagedConnectionFactory (org.tranql.connector.UserPasswordManagedConnectionFactory)1