Search in sources :

Example 1 with CacheTmLookup

use of org.apache.ignite.cache.jta.CacheTmLookup in project ignite by apache.

the class CacheJtaManager method registerCache.

/** {@inheritDoc} */
@Override
public void registerCache(CacheConfiguration<?, ?> cfg) throws IgniteCheckedException {
    String cacheLookupClsName = cfg.getTransactionManagerLookupClassName();
    if (cacheLookupClsName != null) {
        CacheTmLookup tmLookup = tmLookupRef.get();
        if (tmLookup == null) {
            tmLookup = createTmLookup(cacheLookupClsName);
            if (tmLookupRef.compareAndSet(null, tmLookup))
                return;
            tmLookup = tmLookupRef.get();
        }
        if (!cacheLookupClsName.equals(tmLookup.getClass().getName()))
            throw new IgniteCheckedException("Failed to start cache with CacheTmLookup that specified in cache " + "configuration, because node uses another CacheTmLookup [cache" + cfg.getName() + ", tmLookupClassName=" + cacheLookupClsName + ", tmLookupUsedByNode=" + tmLookup.getClass().getName() + ']');
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheTmLookup(org.apache.ignite.cache.jta.CacheTmLookup)

Example 2 with CacheTmLookup

use of org.apache.ignite.cache.jta.CacheTmLookup in project ignite by apache.

the class CacheJtaManager method createTmLookup.

/**
     * @throws IgniteCheckedException
     */
private CacheTmLookup createTmLookup(String tmLookupClsName) throws IgniteCheckedException {
    try {
        Class<?> cls = Class.forName(tmLookupClsName);
        CacheTmLookup res = (CacheTmLookup) cls.newInstance();
        cctx.kernalContext().resource().injectGeneric(res);
        if (res instanceof LifecycleAware)
            ((LifecycleAware) res).start();
        return res;
    } catch (Exception e) {
        throw new IgniteCheckedException("Failed to instantiate transaction manager lookup.", e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LifecycleAware(org.apache.ignite.lifecycle.LifecycleAware) CacheTmLookup(org.apache.ignite.cache.jta.CacheTmLookup) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 3 with CacheTmLookup

use of org.apache.ignite.cache.jta.CacheTmLookup in project ignite by apache.

the class CacheJtaManager method checkJta.

/** {@inheritDoc} */
@Override
public void checkJta() throws IgniteCheckedException {
    if (jtaTm == null) {
        try {
            CacheTmLookup tmLookup = tmLookupRef.get();
            if (tmLookup == null)
                return;
            jtaTm = tmLookup.getTm();
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to get transaction manager: " + e, e);
        }
    }
    if (jtaTm != null) {
        CacheJtaResource rsrc = this.rsrc.get();
        if (rsrc == null || rsrc.isFinished()) {
            try {
                Transaction jtaTx = jtaTm.getTransaction();
                if (jtaTx != null) {
                    GridNearTxLocal tx = cctx.tm().userTx();
                    if (tx == null) {
                        TransactionConfiguration tCfg = cctx.kernalContext().config().getTransactionConfiguration();
                        tx = cctx.tm().newTx(/*implicit*/
                        false, /*implicit single*/
                        false, null, tCfg.getDefaultTxConcurrency(), tCfg.getDefaultTxIsolation(), tCfg.getDefaultTxTimeout(), /*store enabled*/
                        true, /*tx size*/
                        0);
                    }
                    rsrc = new CacheJtaResource(tx, cctx.kernalContext());
                    if (useJtaSync)
                        jtaTx.registerSynchronization(rsrc);
                    else if (!jtaTx.enlistResource(rsrc))
                        throw new IgniteCheckedException("Failed to enlist XA resource to JTA user transaction.");
                    this.rsrc.set(rsrc);
                }
            } catch (SystemException e) {
                throw new IgniteCheckedException("Failed to obtain JTA transaction.", e);
            } catch (RollbackException e) {
                throw new IgniteCheckedException("Failed to enlist XAResource to JTA transaction.", e);
            }
        }
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) RollbackException(javax.transaction.RollbackException) CacheTmLookup(org.apache.ignite.cache.jta.CacheTmLookup) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 CacheTmLookup (org.apache.ignite.cache.jta.CacheTmLookup)3 RollbackException (javax.transaction.RollbackException)2 SystemException (javax.transaction.SystemException)2 Transaction (javax.transaction.Transaction)1 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 LifecycleAware (org.apache.ignite.lifecycle.LifecycleAware)1