Search in sources :

Example 41 with XAResource

use of javax.transaction.xa.XAResource in project aries by apache.

the class LogTest method testGeronimo.

@Test
@Ignore
public void testGeronimo() throws Exception {
    System.err.println("Geronimo");
    XidFactory xidFactory = new XidFactoryImpl("hi".getBytes());
    HOWLLog txLog = new HOWLLog("org.objectweb.howl.log.BlockLogBuffer", 4, true, true, 50, new File(".").getAbsolutePath(), "log", "geronimo", 512, 0, 2, 4, -1, true, xidFactory, null);
    txLog.doStart();
    GeronimoTransactionManager tm = new GeronimoTransactionManager(600, xidFactory, txLog);
    XAResource xar1 = new TestXAResource("res1");
    XAResource xar2 = new TestXAResource("res2");
    tm.registerNamedXAResourceFactory(new TestXAResourceFactory("res1"));
    tm.registerNamedXAResourceFactory(new TestXAResourceFactory("res2"));
    for (int i = minThreads; i <= maxThreads; i *= 10) {
        for (int j = minTxPerThread; j <= maxTxPerThread; j *= 10) {
            long ms = testThroughput(tm, xar1, xar2, i, j);
            System.err.println("TPS (" + i + " threads, " + j + " tx) = " + ((i * j) / (ms / 1000.0)));
        }
    }
    txLog.doStop();
    System.err.println();
    System.err.flush();
}
Also used : NamedXAResource(org.apache.geronimo.transaction.manager.NamedXAResource) XAResource(javax.transaction.xa.XAResource) HOWLLog(org.apache.geronimo.transaction.log.HOWLLog) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) File(java.io.File) XidFactory(org.apache.geronimo.transaction.manager.XidFactory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 42 with XAResource

use of javax.transaction.xa.XAResource in project aries by apache.

the class TransactionLogTest method doRecoveryRequired.

public void doRecoveryRequired(BiConsumer<XAResource, XAResource> ordering, TransactionStatus expectedFinalState) throws Exception {
    //Register the recoverable resource
    ArgumentCaptor<ServiceListener> captor = ArgumentCaptor.forClass(ServiceListener.class);
    Mockito.verify(ctx).addServiceListener(captor.capture(), Mockito.anyString());
    Mockito.when(ctx.getService(serviceRef)).thenReturn(new TestRecoverableResource("foo", dataSource));
    captor.getValue().serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, serviceRef));
    XAConnection xaConn = dataSource.getXAConnection();
    AtomicReference<TransactionStatus> ref = new AtomicReference<TransactionStatus>();
    try {
        txControl.required(() -> {
            txControl.getCurrentContext().postCompletion(ref::set);
            Connection conn = xaConn.getConnection();
            // conn.setAutoCommit(false);
            XAResource dsResource = xaConn.getXAResource();
            XAResource poison = Mockito.mock(XAResource.class);
            Mockito.when(poison.prepare(Mockito.any())).thenAnswer(i -> {
                conn.createStatement().execute("shutdown immediately");
                Thread.sleep(1000);
                return XA_OK;
            });
            ordering.accept(dsResource, poison);
            return conn.createStatement().execute("Insert into TEST_TABLE values ( 'Hello World!' )");
        });
    } catch (TransactionException te) {
        assertEquals(expectedFinalState, ref.get());
        assertEquals(expectedFinalState == ROLLED_BACK, te instanceof TransactionRolledBackException);
    } finally {
        try {
            xaConn.close();
        } catch (SQLException sqle) {
        }
    }
    setupServerAndDataSource();
}
Also used : ServiceListener(org.osgi.framework.ServiceListener) SQLException(java.sql.SQLException) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) TransactionStatus(org.osgi.service.transaction.control.TransactionStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) XAResource(javax.transaction.xa.XAResource) RecoverableXAResource(org.osgi.service.transaction.control.recovery.RecoverableXAResource) TransactionException(org.osgi.service.transaction.control.TransactionException) ServiceEvent(org.osgi.framework.ServiceEvent) TransactionRolledBackException(org.osgi.service.transaction.control.TransactionRolledBackException) XAConnection(javax.sql.XAConnection)

Example 43 with XAResource

use of javax.transaction.xa.XAResource in project warn-report by saaavsaaa.

the class DistributeTransaction method initXAResource.

XAResource initXAResource(XAConnection xacon) {
    XAResource xares = null;
    try {
        System.out.print("Setting up a XA resource: ");
        xares = xacon.getXAResource();
        System.out.println("Okay.");
    } catch (SQLException e) {
        sqlerr(e);
    }
    return xares;
}
Also used : XAResource(javax.transaction.xa.XAResource) SQLException(java.sql.SQLException)

Example 44 with XAResource

use of javax.transaction.xa.XAResource in project Payara by payara.

the class InboundRecoveryHandler method recoverInboundTransactions.

private void recoverInboundTransactions(List<XAResource> xaresList) {
    List<Application> applications = deployedApplications.getApplications();
    try {
        _logger.log(Level.INFO, "Recovery of Inbound Transactions started.");
        if (applications.size() == 0) {
            _logger.log(Level.FINE, "No applications deployed.");
            return;
        }
        // List of CMT enabled MDB descriptors on the application server instance.
        List<EjbDescriptor> xaEnabledMDBList = new ArrayList<EjbDescriptor>();
        // Done so as to initialize connectors-runtime before loading inbound active RA. need a better way ?
        ConnectorRuntime cr = connectorRuntimeProvider.get();
        for (Application application : applications) {
            Vector ejbDescVec = getEjbDescriptors(application, appsRegistry);
            for (int j = 0; j < ejbDescVec.size(); j++) {
                EjbDescriptor desc = (EjbDescriptor) ejbDescVec.elementAt(j);
                // add it to the list of xaEnabledMDBList.
                if (desc instanceof EjbMessageBeanDescriptor && desc.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
                    xaEnabledMDBList.add(desc);
                    _logger.log(Level.FINE, "Found a CMT MDB: " + desc.getEjbClassName());
                }
            }
        }
        if (xaEnabledMDBList.size() == 0) {
            _logger.log(Level.FINE, "Found no CMT MDBs in all applications");
            return;
        }
        ConnectorRegistry creg = ConnectorRegistry.getInstance();
        // for each RA (key in the map) get the list (value) of MDB Descriptors
        Map<String, List<EjbDescriptor>> mappings = createRAEjbMapping(xaEnabledMDBList);
        // For each RA
        for (Map.Entry entry : mappings.entrySet()) {
            String raMid = (String) entry.getKey();
            List<EjbDescriptor> respectiveDesc = mappings.get(raMid);
            try {
                createActiveResourceAdapter(raMid);
            } catch (Exception ex) {
                _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", raMid);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, ex.toString(), ex);
                }
            }
            ActiveInboundResourceAdapter activeInboundRA = (ActiveInboundResourceAdapter) creg.getActiveResourceAdapter(raMid);
            // assert activeInboundRA instanceof ActiveInboundResourceAdapter;
            boolean isSystemJmsRA = false;
            if (ConnectorsUtil.isJMSRA(activeInboundRA.getModuleName())) {
                isSystemJmsRA = true;
            }
            javax.resource.spi.ResourceAdapter resourceAdapter = activeInboundRA.getResourceAdapter();
            // activationSpecList represents the ActivationSpec[] that would be
            // sent to the getXAResources() method.
            ArrayList<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
            try {
                for (int i = 0; i < respectiveDesc.size(); i++) {
                    try {
                        // Get a MessageBeanDescriptor from respectiveDesc ArrayList
                        EjbMessageBeanDescriptor descriptor = (EjbMessageBeanDescriptor) respectiveDesc.get(i);
                        // to be updated J2EE 1.4 style props.
                        if (isSystemJmsRA) {
                            // XXX: Find out the pool descriptor corres to MDB and update
                            // MDBRuntimeInfo with that.
                            activeInboundRA.updateMDBRuntimeInfo(descriptor, null);
                        }
                        // Get the ActivationConfig Properties from the MDB Descriptor
                        Set activationConfigProps = RARUtils.getMergedActivationConfigProperties(descriptor);
                        // get message listener type
                        String msgListenerType = descriptor.getMessageListenerType();
                        // start resource adapter and get ActivationSpec class for
                        // the given message listener type from the ConnectorRuntime
                        ActivationSpec aspec = (ActivationSpec) (Class.forName(cr.getActivationSpecClass(raMid, msgListenerType), false, resourceAdapter.getClass().getClassLoader()).newInstance());
                        aspec.setResourceAdapter(resourceAdapter);
                        // Populate ActivationSpec class with ActivationConfig properties
                        SetMethodAction sma = new SetMethodAction(aspec, activationConfigProps);
                        sma.run();
                        activationSpecList.add(aspec);
                    } catch (Exception e) {
                        _logger.log(Level.WARNING, "error.creating.activationspec", e.getMessage());
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, e.toString(), e);
                        }
                    }
                }
                // Get XA resources from RA.
                ActivationSpec[] activationSpecArray = activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]);
                XAResource[] xar = resourceAdapter.getXAResources(activationSpecArray);
                // Add the resources to the xaresList which is used by the RecoveryManager
                if (xar != null) {
                    for (int p = 0; p < xar.length; p++) {
                        xaresList.add(xar[p]);
                    }
                }
            // Catch UnsupportedOperationException if a RA does not support XA
            // which is fine.
            } catch (UnsupportedOperationException uoex) {
                _logger.log(Level.FINE, uoex.getMessage());
            // otherwise catch the unexpected exception
            } catch (Exception e) {
                _logger.log(Level.SEVERE, "exception.during.inbound.resource.acqusition", e);
            }
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, "exception.during.inbound.recovery", e);
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) Vector(java.util.Vector) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) XAResource(javax.transaction.xa.XAResource) EjbMessageBeanDescriptor(com.sun.enterprise.deployment.EjbMessageBeanDescriptor) ActivationSpec(javax.resource.spi.ActivationSpec) Application(com.sun.enterprise.config.serverbeans.Application) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 45 with XAResource

use of javax.transaction.xa.XAResource in project Payara by payara.

the class ConnectorAllocator method fillInResourceObjects.

public void fillInResourceObjects(ResourceHandle resource) throws PoolingException {
    try {
        ManagedConnection mc = (ManagedConnection) resource.getResource();
        Object con = mc.getConnection(subject, reqInfo);
        resource.incrementCount();
        XAResource xares = mc.getXAResource();
        resource.fillInResourceObjects(con, xares);
    } catch (ResourceException ex) {
        throw new PoolingException(ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) XAResource(javax.transaction.xa.XAResource) ResourceException(javax.resource.ResourceException)

Aggregations

XAResource (javax.transaction.xa.XAResource)49 Xid (javax.transaction.xa.Xid)14 Test (org.junit.Test)13 SystemException (javax.transaction.SystemException)12 Transaction (javax.transaction.Transaction)11 ResourceException (javax.resource.ResourceException)9 XAException (javax.transaction.xa.XAException)9 XidImpl (org.neo4j.kernel.impl.transaction.XidImpl)9 RollbackException (javax.transaction.RollbackException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ManagedConnection (javax.resource.spi.ManagedConnection)6 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)6 SQLException (java.sql.SQLException)5 RelationshipType (org.neo4j.graphdb.RelationshipType)5 Map (java.util.Map)4 XAConnection (javax.sql.XAConnection)4 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)3 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)3