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() + ']');
}
}
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);
}
}
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);
}
}
}
}
Aggregations