Search in sources :

Example 1 with GeronimoTransactionManager

use of org.apache.geronimo.transaction.manager.GeronimoTransactionManager in project tomee by apache.

the class ManagedConnectionBehaviorTest method run.

@Test
public void run() throws Exception {
    final GeronimoTransactionManager geronimoTransactionManager = new GeronimoTransactionManager((int) TimeUnit.MINUTES.toMillis(10));
    final TransactionManager mgr = new TransactionManagerWrapper(geronimoTransactionManager, "ManagedConnectionBehaviorTest", new GeronimoTransactionManagerFactory.GeronimoXAResourceWrapper());
    final MyDs myDs = new MyDs();
    final DataSource ds = new ManagedDataSource(myDs, geronimoTransactionManager, geronimoTransactionManager);
    {
        // no tx
        final Connection connection = ds.getConnection();
        // not yet needed
        assertTrue(myDs.connections.isEmpty());
        // just to call something
        connection.createBlob();
        assertFalse(myDs.connections.iterator().next().closed);
        connection.close();
        assertTrue(myDs.connections.iterator().next().closed);
        myDs.connections.clear();
    }
    {
        // tx
        mgr.begin();
        final Connection connection = ds.getConnection();
        // not yet needed
        assertTrue(myDs.connections.isEmpty());
        // just to call something
        connection.createBlob();
        assertFalse(myDs.connections.iterator().next().closed);
        mgr.commit();
        assertTrue(myDs.connections.iterator().next().closed);
        assertTrue(myDs.connections.iterator().next().commit);
        assertFalse(myDs.connections.iterator().next().rollback);
        myDs.connections.clear();
    }
    {
        // tx already init
        mgr.begin();
        final Connection connection = ds.getConnection();
        // not yet needed
        assertTrue(myDs.connections.isEmpty());
        // just to call something
        connection.createBlob();
        assertFalse(myDs.connections.iterator().next().closed);
        for (int i = 0; i < 5; i++) {
            // here the connection is already created, ensure we dont leak other connections
            connection.createBlob();
        }
        assertEquals(1, myDs.connections.size());
        mgr.commit();
        assertTrue(myDs.connections.iterator().next().closed);
        assertTrue(myDs.connections.iterator().next().commit);
        assertFalse(myDs.connections.iterator().next().rollback);
        myDs.connections.clear();
    }
    {
        // multiple tx
        mgr.begin();
        final Connection connection = ds.getConnection();
        // not yet needed
        assertTrue(myDs.connections.isEmpty());
        // just to call something
        connection.createBlob();
        assertFalse(myDs.connections.iterator().next().closed);
        final Transaction previous = mgr.suspend();
        mgr.begin();
        final Connection connection2 = ds.getConnection();
        connection2.createBlob();
        assertEquals(2, myDs.connections.size());
        mgr.commit();
        mgr.resume(previous);
        mgr.commit();
        final Iterator<MyConn> iterator = myDs.connections.iterator();
        final MyConn first = iterator.next();
        assertTrue(first.closed);
        assertTrue(first.commit);
        assertTrue(myDs.connections.iterator().next().commit);
        myDs.connections.clear();
    }
}
Also used : Transaction(javax.transaction.Transaction) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) TransactionManager(javax.transaction.TransactionManager) TransactionManagerWrapper(org.apache.openejb.resource.TransactionManagerWrapper) Connection(java.sql.Connection) Iterator(java.util.Iterator) GeronimoTransactionManagerFactory(org.apache.openejb.resource.GeronimoTransactionManagerFactory) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource) DataSource(javax.sql.DataSource) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource) Test(org.junit.Test)

Example 2 with GeronimoTransactionManager

use of org.apache.geronimo.transaction.manager.GeronimoTransactionManager in project tomee by apache.

the class GeronimoTransactionManagerFactory method create.

public static // Deprecated, use defaultTransactionTimeout
GeronimoTransactionManager create(// Deprecated, use defaultTransactionTimeout
Integer defaultTransactionTimeoutSeconds, final Duration defaultTransactionTimeout, final boolean txRecovery, final byte[] tmId, final String bufferClassName, final int bufferSizeKb, final boolean checksumEnabled, final boolean adler32Checksum, // Deprecated, use flushSleepTime
Integer flushSleepTimeMilliseconds, final Duration flushSleepTime, final String logFileDir, final String logFileExt, final String logFileName, final int maxBlocksPerFile, final int maxBuffers, final int maxLogFiles, final int minBuffers, final int threadsWaitingForceThreshold) throws Exception {
    if (flushSleepTime.getUnit() == null) {
        flushSleepTime.setUnit(TimeUnit.MILLISECONDS);
    }
    if (flushSleepTimeMilliseconds == null) {
        flushSleepTimeMilliseconds = (int) TimeUnit.MILLISECONDS.convert(flushSleepTime.getTime(), flushSleepTime.getUnit());
    }
    if (defaultTransactionTimeout.getUnit() == null) {
        defaultTransactionTimeout.setUnit(TimeUnit.SECONDS);
    }
    if (defaultTransactionTimeoutSeconds == null) {
        defaultTransactionTimeoutSeconds = (int) TimeUnit.SECONDS.convert(defaultTransactionTimeout.getTime(), defaultTransactionTimeout.getUnit());
    }
    XidFactory xidFactory = null;
    TransactionLog txLog = null;
    if (txRecovery) {
        SystemInstance.get().setComponent(XAResourceWrapper.class, new GeronimoXAResourceWrapper());
        xidFactory = new XidFactoryImpl(tmId == null ? DEFAULT_TM_ID : tmId);
        txLog = new HOWLLog(bufferClassName == null ? "org.objectweb.howl.log.BlockLogBuffer" : bufferClassName, bufferSizeKb == 0 ? DEFAULT_BUFFER_SIZE : bufferSizeKb, checksumEnabled, adler32Checksum, flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold, xidFactory, SystemInstance.get().getBase().getDirectory("."));
        ((HOWLLog) txLog).doStart();
    }
    final GeronimoTransactionManager geronimoTransactionManager = new DestroyableTransactionManager(defaultTransactionTimeoutSeconds, xidFactory, txLog);
    final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management").set("j2eeType", "TransactionManager");
    LocalMBeanServer.registerDynamicWrapperSilently(new TransactionManagerMBean(geronimoTransactionManager, defaultTransactionTimeout, txLog), jmxName.build());
    return geronimoTransactionManager;
}
Also used : ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) TransactionLog(org.apache.geronimo.transaction.manager.TransactionLog) XidFactoryImpl(org.apache.geronimo.transaction.manager.XidFactoryImpl) HOWLLog(org.apache.geronimo.transaction.log.HOWLLog) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) XidFactory(org.apache.geronimo.transaction.manager.XidFactory)

Example 3 with GeronimoTransactionManager

use of org.apache.geronimo.transaction.manager.GeronimoTransactionManager in project tomee by apache.

the class Assembler method doCreateResource.

private Object doCreateResource(final Collection<ServiceInfo> infos, final ResourceInfo serviceInfo) throws OpenEJBException {
    // do it early otherwise we can loose it
    final String skipPropertiesFallback = (String) serviceInfo.properties.remove("SkipPropertiesFallback");
    final ObjectRecipe serviceRecipe = createRecipe(infos, serviceInfo);
    final boolean properties = PropertiesFactory.class.getName().equals(serviceInfo.className);
    if ("false".equalsIgnoreCase(serviceInfo.properties.getProperty("SkipImplicitAttributes", "false")) && !properties) {
        serviceRecipe.setProperty("transactionManager", transactionManager);
        serviceRecipe.setProperty("ServiceId", serviceInfo.id);
    }
    serviceInfo.properties.remove("SkipImplicitAttributes");
    // if custom instance allow to skip properties fallback to avoid to set unexpectedly it - connectionProps of DBs
    final AtomicReference<Properties> injectedProperties = new AtomicReference<>();
    if (!"true".equalsIgnoreCase(skipPropertiesFallback)) {
        serviceRecipe.setProperty("properties", new UnsetPropertiesRecipe() {

            @Override
            protected Object internalCreate(final Type expectedType, final boolean lazyRefAllowed) throws ConstructionException {
                final Map<String, Object> original = serviceRecipe.getUnsetProperties();
                final Properties properties = new SuperProperties() {

                    @Override
                    public Object remove(final Object key) {
                        // avoid to log them then
                        original.remove(key);
                        return super.remove(key);
                    }
                }.caseInsensitive(// keep our nice case insensitive feature
                true);
                for (final Map.Entry<String, Object> entry : original.entrySet()) {
                    properties.put(entry.getKey(), entry.getValue());
                }
                injectedProperties.set(properties);
                return properties;
            }
        });
    } else {
        // this is not the best fallback we have but since it is super limited it is acceptable
        final Map<String, Object> unsetProperties = serviceRecipe.getUnsetProperties();
        injectedProperties.set(new Properties() {

            @Override
            public String getProperty(final String key) {
                final Object obj = unsetProperties.get(key);
                return String.class.isInstance(obj) ? String.valueOf(obj) : null;
            }

            @Override
            public Set<String> stringPropertyNames() {
                return unsetProperties.keySet();
            }

            @Override
            public Set<Object> keySet() {
                //noinspection unchecked
                return Set.class.cast(unsetProperties.keySet());
            }

            @Override
            public synchronized boolean containsKey(final Object key) {
                return getProperty(String.valueOf(key)) != null;
            }
        });
    }
    if (serviceInfo.types.contains("DataSource") || serviceInfo.types.contains(DataSource.class.getName())) {
        final Properties props = PropertyPlaceHolderHelper.simpleHolds(serviceInfo.properties);
        if (serviceInfo.properties.containsKey("Definition")) {
            final Object encoding = serviceInfo.properties.remove("DefinitionEncoding");
            try {
                // we catch classcast etc..., if it fails it is not important
                final InputStream is = new ByteArrayInputStream(serviceInfo.properties.getProperty("Definition").getBytes(encoding != null ? encoding.toString() : "ISO-8859-1"));
                final Properties p = new SuperProperties();
                IO.readProperties(is, p);
                for (final Entry<Object, Object> entry : p.entrySet()) {
                    final String key = entry.getKey().toString();
                    if (!props.containsKey(key) && !(key.equalsIgnoreCase("url") && props.containsKey("JdbcUrl"))) {
                        // with @DataSource we can get both, see org.apache.openejb.config.ConvertDataSourceDefinitions.rawDefinition()
                        props.put(key, entry.getValue());
                    }
                }
            } catch (final Exception e) {
            // ignored
            }
        }
        serviceRecipe.setProperty("Definition", PropertiesHelper.propertiesToString(props));
    }
    // else: any other kind of resource relying on it? shouldnt be
    replaceResourceAdapterProperty(serviceRecipe);
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    boolean customLoader = false;
    try {
        if (serviceInfo.classpath != null && serviceInfo.classpath.length > 0) {
            final URL[] urls = new URL[serviceInfo.classpath.length];
            for (int i = 0; i < serviceInfo.classpath.length; i++) {
                urls[i] = serviceInfo.classpath[i].toURL();
            }
            loader = new URLClassLoaderFirst(urls, loader);
            customLoader = true;
            serviceRecipe.setProperty("OpenEJBResourceClasspath", "true");
        }
    } catch (final MalformedURLException e) {
        throw new OpenEJBException("Unable to create a classloader for " + serviceInfo.id, e);
    }
    if (!customLoader && serviceInfo.classpathAPI != null) {
        throw new IllegalArgumentException("custom-api provided but not classpath used for " + serviceInfo.id);
    }
    Object service = serviceRecipe.create(loader);
    if (customLoader) {
        final Collection<Class<?>> apis;
        if (serviceInfo.classpathAPI == null) {
            apis = new ArrayList<Class<?>>(Arrays.asList(service.getClass().getInterfaces()));
        } else {
            final String[] split = serviceInfo.classpathAPI.split(" *, *");
            apis = new ArrayList<>(split.length);
            final ClassLoader apiLoader = Thread.currentThread().getContextClassLoader();
            for (final String fqn : split) {
                try {
                    apis.add(apiLoader.loadClass(fqn));
                } catch (final ClassNotFoundException e) {
                    throw new IllegalArgumentException(fqn + " not usable as API for " + serviceInfo.id, e);
                }
            }
        }
        if (apis.size() - (apis.contains(Serializable.class) ? 1 : 0) - (apis.contains(Externalizable.class) ? 1 : 0) > 0) {
            service = Proxy.newProxyInstance(loader, apis.toArray(new Class<?>[apis.size()]), new ClassLoaderAwareHandler(null, service, loader));
        }
    // else proxy would be useless
    }
    serviceInfo.unsetProperties = injectedProperties.get();
    // Java Connector spec ResourceAdapters and ManagedConnectionFactories need special activation
    if (service instanceof ResourceAdapter) {
        final ResourceAdapter resourceAdapter = (ResourceAdapter) service;
        // Create a thead pool for work manager
        final int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
        final Executor threadPool;
        if (threadPoolSize <= 0) {
            logger.warning("Thread pool for '" + serviceInfo.id + "' is (unbounded), consider setting a size using: " + serviceInfo.id + ".QueueSize=[size]");
            threadPool = Executors.newCachedThreadPool(new DaemonThreadFactory(serviceInfo.id + "-worker-"));
        } else {
            threadPool = new ExecutorBuilder().size(threadPoolSize).prefix(serviceInfo.id).threadFactory(new DaemonThreadFactory(serviceInfo.id + "-worker-")).build(new Options(serviceInfo.properties, SystemInstance.get().getOptions()));
            logger.info("Thread pool size for '" + serviceInfo.id + "' is (" + threadPoolSize + ")");
        }
        // WorkManager: the resource adapter can use this to dispatch messages or perform tasks
        final WorkManager workManager;
        if (GeronimoTransactionManager.class.isInstance(transactionManager)) {
            final GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;
            final TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(geronimoTransactionManager);
            // use id as default realm name if realm is not specified in service properties
            final String securityRealmName = getStringProperty(serviceInfo.properties, "realm", serviceInfo.id);
            final SecurityContextHandler securityContextHandler = new SecurityContextHandler(securityRealmName);
            final HintsContextHandler hintsContextHandler = new HintsContextHandler();
            final Collection<WorkContextHandler> workContextHandlers = new ArrayList<WorkContextHandler>();
            workContextHandlers.add(txWorkContextHandler);
            workContextHandlers.add(securityContextHandler);
            workContextHandlers.add(hintsContextHandler);
            workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, workContextHandlers);
        } else {
            workManager = new SimpleWorkManager(threadPool);
        }
        // BootstrapContext: wraps the WorkMananger and XATerminator
        final BootstrapContext bootstrapContext;
        if (transactionManager instanceof GeronimoTransactionManager) {
            bootstrapContext = new GeronimoBootstrapContext(GeronimoWorkManager.class.cast(workManager), (GeronimoTransactionManager) transactionManager, (GeronimoTransactionManager) transactionManager);
        } else if (transactionManager instanceof XATerminator) {
            bootstrapContext = new SimpleBootstrapContext(workManager, (XATerminator) transactionManager);
        } else {
            bootstrapContext = new SimpleBootstrapContext(workManager);
        }
        // start the resource adapter
        try {
            logger.debug("createResource.startingResourceAdapter", serviceInfo.id, service.getClass().getName());
            resourceAdapter.start(bootstrapContext);
        } catch (final ResourceAdapterInternalException e) {
            throw new OpenEJBException(e);
        }
        final Map<String, Object> unset = serviceRecipe.getUnsetProperties();
        unset.remove("threadPoolSize");
        logUnusedProperties(unset, serviceInfo);
        service = new ResourceAdapterReference(resourceAdapter, threadPool, OPENEJB_RESOURCE_JNDI_PREFIX + serviceInfo.id);
    } else if (service instanceof ManagedConnectionFactory) {
        final ManagedConnectionFactory managedConnectionFactory = (ManagedConnectionFactory) service;
        // connection manager is constructed via a recipe so we automatically expose all cmf properties
        final ObjectRecipe connectionManagerRecipe = new ObjectRecipe(GeronimoConnectionManagerFactory.class, "create");
        connectionManagerRecipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
        connectionManagerRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
        connectionManagerRecipe.setAllProperties(serviceInfo.properties);
        connectionManagerRecipe.setProperty("name", serviceInfo.id);
        connectionManagerRecipe.setProperty("mcf", managedConnectionFactory);
        // standard properties
        connectionManagerRecipe.setProperty("transactionManager", transactionManager);
        ClassLoader classLoader = loader;
        if (classLoader == null) {
            classLoader = getClass().getClassLoader();
        }
        if (classLoader == null) {
            classLoader = ClassLoader.getSystemClassLoader();
        }
        connectionManagerRecipe.setProperty("classLoader", classLoader);
        logger.getChildLogger("service").info("createResource.createConnectionManager", serviceInfo.id, service.getClass().getName());
        // create the connection manager
        final ConnectionManager connectionManager = (ConnectionManager) connectionManagerRecipe.create();
        if (connectionManager == null) {
            throw new OpenEJBRuntimeException(messages.format("assembler.invalidConnectionManager", serviceInfo.id));
        }
        final Map<String, Object> unsetA = serviceRecipe.getUnsetProperties();
        final Map<String, Object> unsetB = connectionManagerRecipe.getUnsetProperties();
        final Map<String, Object> unset = new HashMap<String, Object>();
        for (final Entry<String, Object> entry : unsetA.entrySet()) {
            if (unsetB.containsKey(entry.getKey())) {
                unset.put(entry.getKey(), entry.getValue());
            }
        }
        // service becomes a ConnectorReference which merges connection manager and mcf
        service = new ConnectorReference(connectionManager, managedConnectionFactory);
        // init cm if needed
        final Object eagerInit = unset.remove("eagerInit");
        if (eagerInit != null && eagerInit instanceof String && "true".equalsIgnoreCase((String) eagerInit) && connectionManager instanceof AbstractConnectionManager) {
            try {
                ((AbstractConnectionManager) connectionManager).doStart();
                try {
                    final Object cf = managedConnectionFactory.createConnectionFactory(connectionManager);
                    if (cf instanceof ConnectionFactory) {
                        final Connection connection = ((ConnectionFactory) cf).getConnection();
                        connection.getMetaData();
                        connection.close();
                    }
                } catch (final Exception e) {
                // no-op: just to force eager init of pool
                }
            } catch (final Exception e) {
                logger.warning("Can't start connection manager", e);
            }
        }
        logUnusedProperties(unset, serviceInfo);
    } else if (service instanceof DataSource) {
        ClassLoader classLoader = loader;
        if (classLoader == null) {
            classLoader = getClass().getClassLoader();
        }
        final ImportSql importer = new ImportSql(classLoader, serviceInfo.id, (DataSource) service);
        if (importer.hasSomethingToImport()) {
            importer.doImport();
        }
        final ObjectRecipe recipe = DataSourceFactory.forgetRecipe(service, serviceRecipe);
        if (recipe != serviceRecipe || !serviceInfo.properties.containsKey("XaDataSource")) {
            logUnusedProperties(recipe, serviceInfo);
        }
        // else logged on xadatasource itself
        final Properties prop = serviceInfo.properties;
        String url = prop.getProperty("JdbcUrl", prop.getProperty("url"));
        if (url == null) {
            url = prop.getProperty("jdbcUrl");
        }
        if (url == null) {
            logger.debug("Unable to find url for " + serviceInfo.id + " will not monitor it");
        } else {
            final String host = extractHost(url);
            if (host != null) {
                remoteResourceMonitor.addHost(host);
                remoteResourceMonitor.registerIfNot();
            }
        }
    } else if (!Properties.class.isInstance(service)) {
        if (serviceInfo.unsetProperties == null || isTemplatizedResource(serviceInfo)) {
            logUnusedProperties(serviceRecipe, serviceInfo);
        }
    // else wait post construct
    }
    final ResourceCreated event = new ResourceCreated(service, serviceInfo.id);
    SystemInstance.get().fireEvent(event);
    return event.getReplacement() == null ? service : event.getReplacement();
}
Also used : URLClassLoaderFirst(org.apache.openejb.util.classloader.URLClassLoaderFirst) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) Serializable(java.io.Serializable) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) TransactionContextHandler(org.apache.geronimo.connector.work.TransactionContextHandler) ArrayList(java.util.ArrayList) GeronimoWorkManager(org.apache.geronimo.connector.work.GeronimoWorkManager) SuperProperties(org.apache.openejb.util.SuperProperties) ExecutorBuilder(org.apache.openejb.util.ExecutorBuilder) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) ConnectionManager(javax.resource.spi.ConnectionManager) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) SimpleWorkManager(org.apache.openejb.core.transaction.SimpleWorkManager) WorkManager(javax.resource.spi.work.WorkManager) GeronimoWorkManager(org.apache.geronimo.connector.work.GeronimoWorkManager) ResourceAdapter(javax.resource.spi.ResourceAdapter) SecurityContextHandler(org.apache.openejb.core.security.SecurityContextHandler) UnsetPropertiesRecipe(org.apache.xbean.recipe.UnsetPropertiesRecipe) GeronimoConnectionManagerFactory(org.apache.openejb.resource.GeronimoConnectionManagerFactory) DataSource(javax.sql.DataSource) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) HintsContextHandler(org.apache.geronimo.connector.work.HintsContextHandler) SimpleBootstrapContext(org.apache.openejb.core.transaction.SimpleBootstrapContext) ByteArrayInputStream(java.io.ByteArrayInputStream) PropertiesFactory(org.apache.openejb.resource.PropertiesFactory) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) ConnectorReference(org.apache.openejb.core.ConnectorReference) Options(org.apache.openejb.loader.Options) XATerminator(javax.resource.spi.XATerminator) HashSet(java.util.HashSet) Set(java.util.Set) UrlSet(org.apache.xbean.finder.UrlSet) ClassLoaderAwareHandler(org.apache.openejb.util.classloader.ClassLoaderAwareHandler) DaemonThreadFactory(org.apache.openejb.util.DaemonThreadFactory) SimpleWorkManager(org.apache.openejb.core.transaction.SimpleWorkManager) SimpleBootstrapContext(org.apache.openejb.core.transaction.SimpleBootstrapContext) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) BootstrapContext(javax.resource.spi.BootstrapContext) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) SuperProperties(org.apache.openejb.util.SuperProperties) Properties(java.util.Properties) URL(java.net.URL) Entry(java.util.Map.Entry) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) ConnectionFactory(javax.resource.cci.ConnectionFactory) Executor(java.util.concurrent.Executor) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) ResourceCreated(org.apache.openejb.assembler.classic.event.ResourceCreated) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(javax.resource.cci.Connection) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) BeanType(org.apache.openejb.BeanType) Type(java.lang.reflect.Type) TransactionType(org.apache.openejb.core.transaction.TransactionType) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) ConstructionException(org.apache.xbean.recipe.ConstructionException) WorkContextHandler(org.apache.geronimo.connector.work.WorkContextHandler)

Example 4 with GeronimoTransactionManager

use of org.apache.geronimo.transaction.manager.GeronimoTransactionManager in project tomee by apache.

the class JmsTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // create a transaction manager
    final GeronimoTransactionManager transactionManager = new GeronimoTransactionManager();
    // create the ActiveMQ resource adapter instance
    ra = new ActiveMQResourceAdapter();
    // initialize properties
    ra.setServerUrl(brokerAddress);
    ra.setBrokerXmlConfig(brokerXmlConfig);
    ra.setStartupTimeout(new Duration(10, TimeUnit.SECONDS));
    // create a thead pool for ActiveMQ
    final Executor threadPool = Executors.newFixedThreadPool(30);
    // create a work manager which ActiveMQ uses to dispatch message delivery jobs
    final TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(transactionManager);
    final GeronimoWorkManager workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, Collections.<WorkContextHandler>singletonList(txWorkContextHandler));
    // wrap the work mananger and transaction manager in a bootstrap context (connector spec thing)
    final BootstrapContext bootstrapContext = new GeronimoBootstrapContext(workManager, transactionManager, transactionManager);
    // Create a ConnectionFactory
    connectionFactory = new ActiveMQConnectionFactory(brokerAddress);
    ra.setConnectionFactory(connectionFactory);
    // start the resource adapter
    try {
        ra.start(bootstrapContext);
    } catch (final ResourceAdapterInternalException e) {
        throw new OpenEJBException(e);
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) OpenEJBException(org.apache.openejb.OpenEJBException) Executor(java.util.concurrent.Executor) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) TransactionContextHandler(org.apache.geronimo.connector.work.TransactionContextHandler) GeronimoWorkManager(org.apache.geronimo.connector.work.GeronimoWorkManager) ActiveMQResourceAdapter(org.apache.openejb.resource.activemq.ActiveMQResourceAdapter) Duration(org.apache.openejb.util.Duration) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) BootstrapContext(javax.resource.spi.BootstrapContext) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException)

Example 5 with GeronimoTransactionManager

use of org.apache.geronimo.transaction.manager.GeronimoTransactionManager in project tomee by apache.

the class UnenhancedTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    // setup tx mgr
    transactionManager = new GeronimoTransactionManager();
    SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, transactionManager);
    // Put tx mgr into SystemInstance so OpenJPA can find it
    SystemInstance.get().setComponent(TransactionManager.class, transactionManager);
    // init databases
    jtaDs = createJtaDataSource(transactionManager);
    nonJtaDs = createNonJtaDataSource();
}
Also used : GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager)

Aggregations

GeronimoTransactionManager (org.apache.geronimo.transaction.manager.GeronimoTransactionManager)7 Executor (java.util.concurrent.Executor)2 BootstrapContext (javax.resource.spi.BootstrapContext)2 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)2 DataSource (javax.sql.DataSource)2 GeronimoBootstrapContext (org.apache.geronimo.connector.GeronimoBootstrapContext)2 GeronimoWorkManager (org.apache.geronimo.connector.work.GeronimoWorkManager)2 TransactionContextHandler (org.apache.geronimo.connector.work.TransactionContextHandler)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvalidObjectException (java.io.InvalidObjectException)1 ObjectStreamException (java.io.ObjectStreamException)1 Serializable (java.io.Serializable)1 Type (java.lang.reflect.Type)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1