Search in sources :

Example 46 with XAResource

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

the class LocalTxConnectorAllocator method createResource.

public ResourceHandle createResource() throws PoolingException {
    try {
        ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);
        ResourceHandle resource = createResourceHandle(mc, spec, this, info);
        ConnectionEventListener l = new LocalTxConnectionEventListener(resource);
        mc.addConnectionEventListener(l);
        resource.setListener(l);
        XAResource xares = new ConnectorXAResource(resource, spec, this, info);
        resource.fillInResourceObjects(null, xares);
        return resource;
    } catch (ResourceException ex) {
        Object[] params = new Object[] { spec.getPoolInfo(), ex.toString() };
        _logger.log(Level.WARNING, "poolmgr.create_resource_error", params);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Resource Exception while creating resource", ex);
        }
        if (ex.getLinkedException() != null) {
            _logger.log(Level.WARNING, "poolmgr.create_resource_linked_error", ex.getLinkedException().toString());
        }
        throw new PoolingException(ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) XAResource(javax.transaction.xa.XAResource) LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ResourceException(javax.resource.ResourceException) LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ConnectionEventListener(com.sun.enterprise.resource.listener.ConnectionEventListener)

Example 47 with XAResource

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

the class LocalTxConnectorAllocator method destroyResource.

public void destroyResource(ResourceHandle resource) throws PoolingException {
    try {
        ManagedConnection mc = (ManagedConnection) resource.getResource();
        ConnectorXAResource.freeListener(mc);
        XAResource xares = resource.getXAResource();
        forceTransactionCompletion(xares);
        mc.destroy();
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("destroyResource for LocalTxConnectorAllocator done");
        }
    } catch (Exception ex) {
        throw new PoolingException(ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) XAResource(javax.transaction.xa.XAResource) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) SystemException(javax.transaction.SystemException)

Example 48 with XAResource

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

the class ResourceRecoveryManagerImpl method recoverXAResources.

/**
 * recover the xa-resources
 * @param force boolean to indicate if it has to be forced.
 */
public void recoverXAResources(boolean force) {
    if (force) {
        try {
            if (txnService == null) {
                Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
                txnService = c.getExtensionByType(TransactionService.class);
            }
            if (!Boolean.valueOf(txnService.getAutomaticRecovery())) {
                return;
            }
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "ejbserver.recovery", "Perform recovery of XAResources...");
            }
            configure();
            Vector xaresList = new Vector();
            Map<RecoveryResourceHandler, Vector> resourcesToHandler = getAllRecoverableResources(xaresList);
            int size = xaresList.size();
            XAResource[] xaresArray = new XAResource[size];
            for (int i = 0; i < size; i++) {
                xaresArray[i] = (XAResource) xaresList.elementAt(i);
            }
            resourceRecoveryStarted();
            if (_logger.isLoggable(Level.FINE)) {
                String msg = localStrings.getStringWithDefault("xaresource.recovering", "Recovering {0} XA resources...", new Object[] { String.valueOf(size) });
                _logger.log(Level.FINE, msg);
            }
            txMgr.recover(xaresArray);
            resourceRecoveryCompleted();
            closeAllResources(resourcesToHandler);
        } catch (Exception ex) {
            _logger.log(Level.SEVERE, "xaresource.recover_error", ex);
        }
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) TransactionService(com.sun.enterprise.transaction.config.TransactionService) Config(com.sun.enterprise.config.serverbeans.Config) RecoveryResourceHandler(com.sun.enterprise.transaction.spi.RecoveryResourceHandler)

Example 49 with XAResource

use of javax.transaction.xa.XAResource in project wso2-axis2-transports by wso2.

the class JMSOutTransportInfo method createJMSSender.

/**
 * Create a one time MessageProducer for this JMS OutTransport information.
 * For simplicity and best compatibility, this method uses only JMS 1.0.2b API.
 * Please be cautious when making any changes
 *
 * @return a JMSSender based on one-time use resources
 * @throws JMSException on errors, to be handled and logged by the caller
 */
public JMSMessageSender createJMSSender(MessageContext msgCtx) throws JMSException {
    // digest the targetAddress and locate CF from the EPR
    loadConnectionFactoryFromProperties();
    // create a one time connection and session to be used
    String user = properties != null ? properties.get(JMSConstants.PARAM_JMS_USERNAME) : null;
    String pass = properties != null ? properties.get(JMSConstants.PARAM_JMS_PASSWORD) : null;
    QueueConnectionFactory qConFac = null;
    TopicConnectionFactory tConFac = null;
    int destType = -1;
    // TODO: there is something missing here for destination type generic
    if (JMSConstants.DESTINATION_TYPE_QUEUE.equals(destinationType)) {
        destType = JMSConstants.QUEUE;
        qConFac = (QueueConnectionFactory) connectionFactory;
    } else if (JMSConstants.DESTINATION_TYPE_TOPIC.equals(destinationType)) {
        destType = JMSConstants.TOPIC;
        tConFac = (TopicConnectionFactory) connectionFactory;
    } else {
        // treat jmsdestination type=queue(default is queue)
        destType = JMSConstants.QUEUE;
        qConFac = (QueueConnectionFactory) connectionFactory;
    }
    if (msgCtx.getProperty(JMSConstants.JMS_XA_TRANSACTION_MANAGER) != null) {
        XAConnection connection = null;
        if (user != null && pass != null) {
            if (qConFac != null) {
                connection = ((XAConnectionFactory) qConFac).createXAConnection(user, pass);
            } else if (tConFac != null) {
                connection = ((XAConnectionFactory) tConFac).createXAConnection(user, pass);
            }
        } else {
            if (qConFac != null) {
                connection = ((XAConnectionFactory) qConFac).createXAConnection();
            } else if (tConFac != null) {
                connection = ((XAConnectionFactory) tConFac).createXAConnection();
            }
        }
        if (connection == null) {
            connection = ((XAConnectionFactory) qConFac).createXAConnection();
        }
        XASession session = null;
        MessageProducer producer = null;
        if (connection != null) {
            if (destType == JMSConstants.QUEUE) {
                session = connection.createXASession();
                producer = session.createProducer(destination);
            } else {
                session = connection.createXASession();
                producer = session.createProducer(destination);
            }
        }
        XAResource xaResource = session.getXAResource();
        TransactionManager tx = null;
        Xid xid1 = null;
        Transaction transaction = null;
        java.util.UUID uuid = java.util.UUID.randomUUID();
        try {
            tx = (TransactionManager) msgCtx.getProperty(JMSConstants.JMS_XA_TRANSACTION_MANAGER);
            transaction = tx.getTransaction();
            msgCtx.setProperty(JMSConstants.JMS_XA_TRANSACTION_MANAGER, tx);
            msgCtx.setProperty(JMSConstants.JMS_XA_TRANSACTION, transaction);
            xid1 = new JMSXid(JMSConstants.JMS_XA_TRANSACTION_PREFIX.getBytes(StandardCharsets.UTF_8), 1, uuid.toString().getBytes());
            msgCtx.setProperty("XID", xid1);
            xaResource.start(xid1, XAResource.TMNOFLAGS);
        } catch (SystemException e) {
            handleException("Error Occurred during starting getting Transaction.", e);
        } catch (XAException e) {
            handleException("Error Occurred during starting XA resource.", e);
        }
        return new JMSMessageSender(connection, session, producer, destination, jmsConnectionFactory == null ? this.cacheLevel : jmsConnectionFactory.getCacheLevel(), jmsSpecVersion, destType == -1 ? null : destType == JMSConstants.QUEUE ? Boolean.TRUE : Boolean.FALSE, transaction, xid1, xaResource);
    } else {
        Connection connection = null;
        if (user != null && pass != null) {
            if (qConFac != null) {
                connection = qConFac.createQueueConnection(user, pass);
            } else if (tConFac != null) {
                connection = tConFac.createTopicConnection(user, pass);
            }
        } else {
            if (qConFac != null) {
                connection = qConFac.createQueueConnection();
            } else if (tConFac != null) {
                connection = tConFac.createTopicConnection();
            }
        }
        if (connection == null) {
            connection = jmsConnectionFactory != null ? jmsConnectionFactory.getConnection() : null;
        }
        Session session = null;
        MessageProducer producer = null;
        if (connection != null) {
            if (destType == JMSConstants.QUEUE) {
                session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                producer = ((QueueSession) session).createSender((Queue) destination);
            } else {
                session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                producer = ((TopicSession) session).createPublisher((Topic) destination);
            }
        }
        return new JMSMessageSender(connection, session, producer, destination, jmsConnectionFactory == null ? this.cacheLevel : jmsConnectionFactory.getCacheLevel(), jmsSpecVersion, destType == -1 ? null : destType == JMSConstants.QUEUE ? Boolean.TRUE : Boolean.FALSE);
    }
}
Also used : XAException(javax.transaction.xa.XAException) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) Transaction(javax.transaction.Transaction) java.util(java.util) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) Queue(javax.jms.Queue)

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