ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [13/50] incubator-ignite git commit: # IGNITE-591 Deprecate CacheConfiguration.transactionLookupClassName, create TransactionConfiguration.txLookupClassName instead.
Date Wed, 08 Jul 2015 14:53:14 GMT
# IGNITE-591 Deprecate CacheConfiguration.transactionLookupClassName, create TransactionConfiguration.txLookupClassName
instead.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/006209c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/006209c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/006209c6

Branch: refs/heads/ignite-929
Commit: 006209c6f4dff212c3aa7b48acb3bca9b303d5f8
Parents: b84fdaa
Author: sevdokimov <sergey.evdokimov@jetbrains.com>
Authored: Sat Jul 4 17:09:48 2015 +0300
Committer: sevdokimov <sergey.evdokimov@jetbrains.com>
Committed: Sat Jul 4 17:09:48 2015 +0300

----------------------------------------------------------------------
 .../configuration/CacheConfiguration.java       |   4 +
 .../configuration/TransactionConfiguration.java |  23 +++
 .../processors/cache/GridCacheAttributes.java   |   3 +
 .../processors/cache/GridCacheContext.java      |   7 +-
 .../processors/cache/GridCacheProcessor.java    |  21 +--
 .../cache/GridCacheSharedContext.java           |  15 +-
 .../cache/jta/CacheJtaManagerAdapter.java       |  17 +-
 .../cache/jta/CacheNoopJtaManager.java          |   2 +-
 .../visor/cache/VisorCacheConfiguration.java    |  11 --
 .../loadtests/hashmap/GridCacheTestContext.java |   5 +-
 .../HibernateTransactionalDataRegion.java       |  12 +-
 .../apache/ignite/cache/jta/CacheTmLookup.java  |   3 +-
 .../processors/cache/jta/CacheJtaManager.java   | 167 +++++++++++--------
 .../processors/cache/GridCacheJtaSelfTest.java  |  43 ++++-
 .../GridTmLookupLifecycleAwareSelfTest.java     |  30 +++-
 .../commands/cache/VisorCacheCommand.scala      |   2 -
 16 files changed, 234 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index e2308f2..63c7269 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -967,7 +967,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
      * Gets class name of transaction manager finder for integration for JEE app servers.
      *
      * @return Transaction manager finder.
+     * @deprecated Use {@link TransactionConfiguration#getTxManagerLookupClassName()} instead.
      */
+    @Deprecated
     public String getTransactionManagerLookupClassName() {
         return tmLookupClsName;
     }
@@ -978,7 +980,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
      * @param tmLookupClsName Name of class implementing GridCacheTmLookup interface that
is used to
      *      receive JTA transaction manager.
      * @return {@code this} for chaining.
+     * @deprecated Use {@link TransactionConfiguration#setTxManagerLookupClassName(String)}
instead.
      */
+    @Deprecated
     public CacheConfiguration<K, V> setTransactionManagerLookupClassName(String tmLookupClsName)
{
         this.tmLookupClsName = tmLookupClsName;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
index 9a4114b..5fed59f 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/TransactionConfiguration.java
@@ -61,6 +61,9 @@ public class TransactionConfiguration implements Serializable {
     /** Pessimistic tx log linger. */
     private int pessimisticTxLogLinger = DFLT_PESSIMISTIC_TX_LOG_LINGER;
 
+    /** Name of class implementing GridCacheTmLookup. */
+    private String tmLookupClsName;
+
     /**
      * Empty constructor.
      */
@@ -78,6 +81,7 @@ public class TransactionConfiguration implements Serializable {
         pessimisticTxLogLinger = cfg.getPessimisticTxLogLinger();
         pessimisticTxLogSize = cfg.getPessimisticTxLogSize();
         txSerEnabled = cfg.isTxSerializableEnabled();
+        tmLookupClsName = cfg.getTxManagerLookupClassName();
     }
 
     /**
@@ -202,4 +206,23 @@ public class TransactionConfiguration implements Serializable {
     public void setPessimisticTxLogLinger(int pessimisticTxLogLinger) {
         this.pessimisticTxLogLinger = pessimisticTxLogLinger;
     }
+
+    /**
+     * Gets class name of transaction manager finder for integration for JEE app servers.
+     *
+     * @return Transaction manager finder.
+     */
+    public String getTxManagerLookupClassName() {
+        return tmLookupClsName;
+    }
+
+    /**
+     * Sets look up mechanism for available {@code TransactionManager} implementation, if
any.
+     *
+     * @param tmLookupClsName Name of class implementing GridCacheTmLookup interface that
is used to
+     *      receive JTA transaction manager.
+     */
+    public void setTxManagerLookupClassName(String tmLookupClsName) {
+        this.tmLookupClsName = tmLookupClsName;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
index 755b89a..78c4722 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
@@ -186,7 +186,10 @@ public class GridCacheAttributes implements Serializable {
 
     /**
      * @return Transaction manager lookup class name.
+     * @deprecated Transaction manager lookup must be configured in 
+     *  {@link TransactionConfiguration#getTxManagerLookupClassName()}.
      */
+    @Deprecated
     public String transactionManagerLookupClassName() {
         return ccfg.getTransactionManagerLookupClassName();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index 580e452..c454da9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -133,9 +133,6 @@ public class GridCacheContext<K, V> implements Externalizable {
     /** Replication manager. */
     private GridCacheDrManager drMgr;
 
-    /** JTA manager. */
-    private CacheJtaManagerAdapter jtaMgr;
-
     /** Conflict resolver manager. */
     private CacheConflictResolutionManager rslvrMgr;
 
@@ -251,7 +248,6 @@ public class GridCacheContext<K, V> implements Externalizable {
         CacheDataStructuresManager dataStructuresMgr,
         GridCacheTtlManager ttlMgr,
         GridCacheDrManager drMgr,
-        CacheJtaManagerAdapter jtaMgr,
         CacheConflictResolutionManager<K, V> rslvrMgr,
         CachePluginManager pluginMgr
     ) {
@@ -292,7 +288,6 @@ public class GridCacheContext<K, V> implements Externalizable {
         this.dataStructuresMgr = add(dataStructuresMgr);
         this.ttlMgr = add(ttlMgr);
         this.drMgr = add(drMgr);
-        this.jtaMgr = add(jtaMgr);
         this.rslvrMgr = add(rslvrMgr);
         this.pluginMgr = add(pluginMgr);
 
@@ -1018,7 +1013,7 @@ public class GridCacheContext<K, V> implements Externalizable
{
      * @return JTA manager.
      */
     public CacheJtaManagerAdapter jta() {
-        return jtaMgr;
+        return sharedCtx.jta();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 8124594..1acb351 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -495,7 +495,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         cleanup(cfg, cfg.getEvictionPolicy(), false);
         cleanup(cfg, cfg.getAffinity(), false);
         cleanup(cfg, cfg.getAffinityMapper(), false);
-        cleanup(cfg, cctx.jta().tmLookup(), false);
         cleanup(cfg, cctx.store().configuredStore(), false);
 
         NearCacheConfiguration nearCfg = cfg.getNearConfiguration();
@@ -1001,8 +1000,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         ctx.kernalContext().query().onCacheStop(ctx);
         ctx.kernalContext().continuous().onCacheStop(ctx);
 
-        U.stopLifecycleAware(log, lifecycleAwares(cache.configuration(), ctx.jta().tmLookup(),
-            ctx.store().configuredStore()));
+        U.stopLifecycleAware(log, lifecycleAwares(cache.configuration(), ctx.store().configuredStore()));
 
         if (log.isInfoEnabled())
             log.info("Stopped cache: " + cache.name());
@@ -1120,9 +1118,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         pluginMgr.validate();
 
-        CacheJtaManagerAdapter jta = JTA.create(cfg.getTransactionManagerLookupClassName()
== null);
-
-        jta.createTmLookup(cfg);
+        sharedCtx.jta().registerCache(cfg);
 
         // Skip suggestions for internal caches.
         if (cacheType.userCache())
@@ -1130,8 +1126,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         Collection<Object> toPrepare = new ArrayList<>();
 
-        toPrepare.add(jta.tmLookup());
-
         if (cfgStore instanceof GridCacheLoaderWriterStore) {
             toPrepare.add(((GridCacheLoaderWriterStore)cfgStore).loader());
             toPrepare.add(((GridCacheLoaderWriterStore)cfgStore).writer());
@@ -1141,7 +1135,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         prepare(cfg, toPrepare);
 
-        U.startLifecycleAware(lifecycleAwares(cfg, jta.tmLookup(), cfgStore));
+        U.startLifecycleAware(lifecycleAwares(cfg, cfgStore));
 
         GridCacheAffinityManager affMgr = new GridCacheAffinityManager();
         GridCacheEventManager evtMgr = new GridCacheEventManager();
@@ -1181,7 +1175,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             dataStructuresMgr,
             ttlMgr,
             drMgr,
-            jta,
             rslvrMgr,
             pluginMgr
         );
@@ -1311,7 +1304,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 dataStructuresMgr,
                 ttlMgr,
                 drMgr,
-                jta,
                 rslvrMgr,
                 pluginMgr
             );
@@ -1632,7 +1624,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      */
     @SuppressWarnings("unchecked")
     private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx,
-        Collection<CacheStoreSessionListener> storeSesLsnrs) {
+        Collection<CacheStoreSessionListener> storeSesLsnrs) throws IgniteCheckedException
{
         IgniteTxManager tm = new IgniteTxManager();
         GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
         GridCacheVersionManager verMgr = new GridCacheVersionManager();
@@ -1640,6 +1632,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager();
         GridCacheIoManager ioMgr = new GridCacheIoManager();
 
+        CacheJtaManagerAdapter jta = JTA.createOptional();
+        
         return new GridCacheSharedContext(
             kernalCtx,
             tm,
@@ -1648,7 +1642,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             depMgr,
             exchMgr,
             ioMgr,
-            storeSesLsnrs
+            storeSesLsnrs,
+            jta
         );
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
index 1071ef2..7f4daff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSharedContext.java
@@ -27,6 +27,7 @@ import org.apache.ignite.internal.managers.deployment.*;
 import org.apache.ignite.internal.managers.discovery.*;
 import org.apache.ignite.internal.managers.eventstorage.*;
 import org.apache.ignite.internal.processors.affinity.*;
+import org.apache.ignite.internal.processors.cache.jta.*;
 import org.apache.ignite.internal.processors.cache.store.*;
 import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.cache.version.*;
@@ -54,6 +55,9 @@ public class GridCacheSharedContext<K, V> {
     /** Cache transaction manager. */
     private IgniteTxManager txMgr;
 
+    /** JTA manager. */
+    private CacheJtaManagerAdapter jtaMgr;
+
     /** Partition exchange manager. */
     private GridCachePartitionExchangeManager<K, V> exchMgr;
 
@@ -94,12 +98,14 @@ public class GridCacheSharedContext<K, V> {
         GridCacheDeploymentManager<K, V> depMgr,
         GridCachePartitionExchangeManager<K, V> exchMgr,
         GridCacheIoManager ioMgr,
-        Collection<CacheStoreSessionListener> storeSesLsnrs
+        Collection<CacheStoreSessionListener> storeSesLsnrs,
+        CacheJtaManagerAdapter jtaMgr
     ) {
         this.kernalCtx = kernalCtx;
         this.mvccMgr = add(mvccMgr);
         this.verMgr = add(verMgr);
         this.txMgr = add(txMgr);
+        this.jtaMgr = add(jtaMgr);
         this.depMgr = add(depMgr);
         this.exchMgr = add(exchMgr);
         this.ioMgr = add(ioMgr);
@@ -281,6 +287,13 @@ public class GridCacheSharedContext<K, V> {
     }
 
     /**
+     * @return JTA manager.
+     */
+    public CacheJtaManagerAdapter jta() {
+        return jtaMgr;
+    }
+
+    /**
      * @return Exchange manager.
      */
     public GridCachePartitionExchangeManager<K, V> exchange() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManagerAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManagerAdapter.java
index ef9204d..85fa4b0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManagerAdapter.java
@@ -25,15 +25,7 @@ import org.jetbrains.annotations.*;
 /**
  * Provides possibility to integrate cache transactions with JTA.
  */
-public abstract class CacheJtaManagerAdapter extends GridCacheManagerAdapter {
-    /**
-     * Creates transaction manager finder.
-     *
-     * @param ccfg Cache configuration.
-     * @throws IgniteCheckedException If failed.
-     */
-    public abstract void createTmLookup(CacheConfiguration ccfg) throws IgniteCheckedException;
-
+public abstract class CacheJtaManagerAdapter extends GridCacheSharedManagerAdapter {
     /**
      * Checks if cache is working in JTA transaction and enlist cache as XAResource if necessary.
      *
@@ -42,6 +34,13 @@ public abstract class CacheJtaManagerAdapter extends GridCacheManagerAdapter
{
     public abstract void checkJta() throws IgniteCheckedException;
 
     /**
+     * @param cfg Cache configuration.
+     * @throws IgniteCheckedException If {@link CacheConfiguration#getTransactionManagerLookupClassName()}
is incompatible with
+     *     another caches or {@link TransactionConfiguration#getTxManagerLookupClassName()}.
+     */
+    public abstract void registerCache(CacheConfiguration<?, ?> cfg) throws IgniteCheckedException;
+
+    /**
      * Gets transaction manager finder. Returns Object to avoid dependency on JTA library.
      *
      * @return Transaction manager finder.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheNoopJtaManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheNoopJtaManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheNoopJtaManager.java
index 451357f..60e4102 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheNoopJtaManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheNoopJtaManager.java
@@ -31,7 +31,7 @@ public class CacheNoopJtaManager extends CacheJtaManagerAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public void createTmLookup(CacheConfiguration ccfg) throws IgniteCheckedException
{
+    @Override public void registerCache(CacheConfiguration<?, ?> cfg) {
         // No-op.
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
index 4097c4f..b983039 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java
@@ -62,9 +62,6 @@ public class VisorCacheConfiguration implements Serializable {
     /** Start size. */
     private int startSize;
 
-    /** Name of class implementing GridCacheTmLookup. */
-    private String tmLookupClsName;
-
     /** Off-heap max memory. */
     private long offHeapMaxMemory;
 
@@ -134,7 +131,6 @@ public class VisorCacheConfiguration implements Serializable {
         swapEnabled = ccfg.isSwapEnabled();
         invalidate = ccfg.isInvalidate();
         startSize = ccfg.getStartSize();
-        tmLookupClsName = ccfg.getTransactionManagerLookupClassName();
         offHeapMaxMemory = ccfg.getOffHeapMaxMemory();
         maxConcurrentAsyncOps = ccfg.getMaxConcurrentAsyncOperations();
         memoryMode = ccfg.getMemoryMode();
@@ -222,13 +218,6 @@ public class VisorCacheConfiguration implements Serializable {
     }
 
     /**
-     * @return Name of class implementing GridCacheTmLookup.
-     */
-    @Nullable public String transactionManagerLookupClassName() {
-        return tmLookupClsName;
-    }
-
-    /**
      * @return Off-heap max memory.
      */
     public long offsetHeapMaxMemory() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java
b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java
index 77d3905..f0d1af8 100644
--- a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java
+++ b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java
@@ -19,6 +19,7 @@ package org.apache.ignite.loadtests.hashmap;
 
 import org.apache.ignite.cache.store.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.cache.datastructures.*;
 import org.apache.ignite.internal.processors.cache.dr.*;
@@ -55,7 +56,8 @@ public class GridCacheTestContext<K, V> extends GridCacheContext<K,
V> {
                 new GridCacheDeploymentManager<K, V>(),
                 new GridCachePartitionExchangeManager<K, V>(),
                 new GridCacheIoManager(),
-                null
+                null,
+                new CacheNoopJtaManager()
             ),
             defaultCacheConfiguration(),
             CacheType.USER,
@@ -71,7 +73,6 @@ public class GridCacheTestContext<K, V> extends GridCacheContext<K,
V> {
             new CacheDataStructuresManager(),
             new GridCacheTtlManager(),
             new GridOsCacheDrManager(),
-            new CacheNoopJtaManager(),
             new CacheOsConflictResolutionManager<K, V>(),
             new CachePluginManager(ctx, new CacheConfiguration())
         );

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
index 6a1fd2b..0e2526e 100644
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
+++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.cache.hibernate;
 
 import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.hibernate.cache.*;
 import org.hibernate.cache.spi.*;
@@ -83,9 +84,14 @@ public class HibernateTransactionalDataRegion extends HibernateRegion implements
                     throw new CacheException("Hibernate TRANSACTIONAL access strategy must
have Ignite cache with " +
                         "'TRANSACTIONAL' atomicity mode: " + cache.name());
 
-                if (cache.configuration().getTransactionManagerLookupClassName() == null)
-                    throw new CacheException("Hibernate TRANSACTIONAL access strategy must
have Ignite cache with " +
-                        "TransactionManagerLookup configured: " + cache.name());
+                if (cache.configuration().getTransactionManagerLookupClassName() == null)
{
+                    TransactionConfiguration txCfg = ignite.configuration().getTransactionConfiguration();
+                    
+                    if (txCfg == null || txCfg.getTxManagerLookupClassName() == null)
+                        throw new CacheException("Hibernate TRANSACTIONAL access strategy
must have Ignite with " +
+                            "TransactionManagerLookup configured (see IgniteConfiguration."
+
+                            "getTransactionConfiguration().getTxManagerLookupClassName()):
" + cache.name());
+                }
 
                 return new HibernateTransactionalAccessStrategy(ignite, cache);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/jta/src/main/java/org/apache/ignite/cache/jta/CacheTmLookup.java
----------------------------------------------------------------------
diff --git a/modules/jta/src/main/java/org/apache/ignite/cache/jta/CacheTmLookup.java b/modules/jta/src/main/java/org/apache/ignite/cache/jta/CacheTmLookup.java
index c909c7c..5a38576 100644
--- a/modules/jta/src/main/java/org/apache/ignite/cache/jta/CacheTmLookup.java
+++ b/modules/jta/src/main/java/org/apache/ignite/cache/jta/CacheTmLookup.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.cache.jta;
 
 import org.apache.ignite.*;
+import org.apache.ignite.configuration.TransactionConfiguration;
 import org.jetbrains.annotations.*;
 
 import javax.transaction.*;
@@ -25,7 +26,7 @@ import javax.transaction.*;
 /**
  * Allows grid to use different transactional systems. Implement this interface
  * to look up native transaction manager within your environment. Transaction
- * manager lookup is configured via {@link org.apache.ignite.configuration.CacheConfiguration#getTransactionManagerLookupClassName()}
+ * manager lookup is configured via {@link TransactionConfiguration#getTxManagerLookupClassName()}
  * method.
  * <p>
  * The following implementations are provided out of the box:

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
----------------------------------------------------------------------
diff --git a/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
b/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
index 2a0d46d..09d856b 100644
--- a/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
+++ b/modules/jta/src/main/java/org/apache/ignite/internal/processors/cache/jta/CacheJtaManager.java
@@ -21,37 +21,60 @@ import org.apache.ignite.*;
 import org.apache.ignite.cache.jta.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.processors.cache.transactions.*;
+import org.apache.ignite.lifecycle.*;
 import org.jetbrains.annotations.*;
 
 import javax.transaction.*;
-import java.lang.ref.*;
-import java.util.*;
+import java.util.concurrent.atomic.*;
 
 /**
  * Implementation of {@link CacheJtaManagerAdapter}.
  */
 public class CacheJtaManager extends CacheJtaManagerAdapter {
     /** */
-    private static final Map<TransactionManager, ThreadLocal<WeakReference<GridCacheXAResource>>>
threadLocals =
-            new WeakHashMap<>();
+    private final ThreadLocal<GridCacheXAResource> xaRsrc = new ThreadLocal<>();
 
     /** */
     private volatile TransactionManager jtaTm;
 
     /** */
-    private ThreadLocal<WeakReference<GridCacheXAResource>> xaRsrc;
+    private final AtomicReference<CacheTmLookup> tmLookupRef = new AtomicReference<>();
 
-    /** */
-    private CacheTmLookup tmLookup;
+    /** {@inheritDoc} */
+    @Override protected void start0() throws IgniteCheckedException {
+        super.start0();
+
+        if (cctx.txConfig() != null) {
+            String txLookupClsName = cctx.txConfig().getTxManagerLookupClassName();
+            
+            if (txLookupClsName != null)
+                tmLookupRef.set(createTmLookup(txLookupClsName));
+        }
+    }
 
     /** {@inheritDoc} */
-    @Override public void createTmLookup(CacheConfiguration ccfg) throws IgniteCheckedException
{
-        assert ccfg.getTransactionManagerLookupClassName() != null;
+    @Override protected void stop0(boolean cancel) {
+        CacheTmLookup tmLookup = tmLookupRef.get();
+        
+        if (tmLookup instanceof LifecycleAware)
+            ((LifecycleAware)tmLookup).stop();
+    }
 
+    /**
+     * @throws IgniteCheckedException
+     */
+    private CacheTmLookup createTmLookup(String tmLookupClsName) throws IgniteCheckedException
{
         try {
-            Class<?> cls = Class.forName(ccfg.getTransactionManagerLookupClassName());
+            Class<?> cls = Class.forName(tmLookupClsName);
+
+            CacheTmLookup res = (CacheTmLookup)cls.newInstance();
 
-            tmLookup = (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);
@@ -60,82 +83,90 @@ public class CacheJtaManager extends CacheJtaManagerAdapter {
 
     /** {@inheritDoc} */
     @Override public void checkJta() throws IgniteCheckedException {
-        TransactionManager jtaTm = this.jtaTm;
-
         if (jtaTm == null) {
             try {
-                jtaTm = tmLookup.getTm();
-
-                if (jtaTm == null)
+                CacheTmLookup tmLookup = tmLookupRef.get();
+                
+                if (tmLookup == null)
                     return;
-
-                synchronized (threadLocals) {
-                    if (this.jtaTm != null)
-                        jtaTm = this.jtaTm;
-                    else {
-                        xaRsrc = threadLocals.get(jtaTm);
-
-                        if (xaRsrc == null) {
-                            xaRsrc = new ThreadLocal<>();
-
-                            threadLocals.put(jtaTm, xaRsrc);
-                        }
-
-                        this.jtaTm = jtaTm;
-                    }
-                }
+                
+                jtaTm = tmLookup.getTm();
             }
             catch (Exception e) {
                 throw new IgniteCheckedException("Failed to get transaction manager: " +
e, e);
             }
         }
 
-        WeakReference<GridCacheXAResource> rsrcRef = xaRsrc.get();
-
-        GridCacheXAResource rsrc = rsrcRef == null ? null : rsrcRef.get();
-
-        if (rsrc == null || rsrc.isFinished()) {
-            try {
-                Transaction jtaTx = jtaTm.getTransaction();
-
-                if (jtaTx != null) {
-                    IgniteInternalTx 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
-                        );
-                    }
+        if (jtaTm != null) {
+            GridCacheXAResource rsrc = xaRsrc.get();
+
+            if (rsrc == null || rsrc.isFinished()) {
+                try {
+                    Transaction jtaTx = jtaTm.getTransaction();
+
+                    if (jtaTx != null) {
+                        IgniteInternalTx 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 GridCacheXAResource(tx, cctx.kernalContext());
+                        rsrc = new GridCacheXAResource(tx, cctx.kernalContext());
 
-                    if (!jtaTx.enlistResource(rsrc))
-                        throw new IgniteCheckedException("Failed to enlist XA resource to
JTA user transaction.");
+                        if (!jtaTx.enlistResource(rsrc))
+                            throw new IgniteCheckedException("Failed to enlist XA resource
to JTA user transaction.");
 
-                    xaRsrc.set(new WeakReference<>(rsrc));
+                        xaRsrc.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);
                 }
             }
-            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);
+        }
+    }
+
+    /** {@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() + ']');
         }
     }
 
     /** {@inheritDoc} */
     @Nullable @Override public Object tmLookup() {
-        return tmLookup;
+        return tmLookupRef.get();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheJtaSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheJtaSelfTest.java
b/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheJtaSelfTest.java
index e1c8a77..29836ef 100644
--- a/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheJtaSelfTest.java
+++ b/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheJtaSelfTest.java
@@ -22,11 +22,14 @@ import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.jta.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.testframework.*;
 import org.apache.ignite.transactions.Transaction;
 import org.objectweb.jotm.*;
 
 import javax.transaction.*;
 
+import java.util.concurrent.*;
+
 import static org.apache.ignite.cache.CacheMode.*;
 import static org.apache.ignite.transactions.TransactionState.*;
 
@@ -65,18 +68,11 @@ public class GridCacheJtaSelfTest extends GridCacheAbstractSelfTest {
     }
 
     /** {@inheritDoc} */
-    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception
{
-        CacheConfiguration cfg = super.cacheConfiguration(gridName);
-
-        cfg.setTransactionManagerLookupClassName(TestTmLookup.class.getName());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
+        cfg.getTransactionConfiguration().setTxManagerLookupClassName(TestTmLookup.class.getName());
+        
         CacheConfiguration cfg1 = cacheConfiguration(gridName);
 
         CacheConfiguration cfg2 = cacheConfiguration(gridName);
@@ -100,6 +96,17 @@ public class GridCacheJtaSelfTest extends GridCacheAbstractSelfTest {
     }
 
     /**
+     *
+     */
+    @SuppressWarnings("PublicInnerClass")
+    public static class TestTmLookup2 implements CacheTmLookup {
+        /** {@inheritDoc} */
+        @Override public TransactionManager getTm() {
+            return null;
+        }
+    }
+
+    /**
      * JUnit.
      *
      * @throws Exception If failed.
@@ -185,4 +192,22 @@ public class GridCacheJtaSelfTest extends GridCacheAbstractSelfTest {
         assertEquals(1, (int)cache1.get("key"));
         assertEquals(1, (int)cache2.get("key"));
     }
+    
+    public void testUncompatibleTmLookup() {
+        final IgniteEx ignite = grid(0);
+        
+        final CacheConfiguration cacheCfg = new CacheConfiguration();
+        
+        cacheCfg.setName("Foo");
+        cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+        cacheCfg.setTransactionManagerLookupClassName(TestTmLookup2.class.getName());
+        
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws IgniteException {
+                ignite.createCache(cacheCfg);
+                
+                return null;
+            }
+        }, IgniteException.class, null);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridTmLookupLifecycleAwareSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridTmLookupLifecycleAwareSelfTest.java
b/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridTmLookupLifecycleAwareSelfTest.java
index 5465a91..261765b 100644
--- a/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridTmLookupLifecycleAwareSelfTest.java
+++ b/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/GridTmLookupLifecycleAwareSelfTest.java
@@ -23,6 +23,7 @@ import org.apache.ignite.cache.jta.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.lifecycle.*;
+import org.apache.ignite.resources.*;
 import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.testframework.junits.common.*;
 import org.jetbrains.annotations.*;
@@ -41,15 +42,24 @@ public class GridTmLookupLifecycleAwareSelfTest extends GridAbstractLifecycleAwa
     /** */
     private boolean near;
 
+    /** */
+    private boolean configureGlobalTmLookup;
+    
     /**
      */
     @SuppressWarnings("PublicInnerClass")
     public static class TestTxLookup extends GridAbstractLifecycleAwareSelfTest.TestLifecycleAware
         implements CacheTmLookup {
-        /**
-         */
-        public TestTxLookup() {
-            super(CACHE_NAME);
+
+        /** */
+        @IgniteInstanceResource
+        Ignite ignite;
+        
+        /** {@inheritDoc} */
+        @Override public void start() {
+            super.start();
+            
+            assertNotNull(ignite);
         }
 
         /** {@inheritDoc} */
@@ -74,7 +84,10 @@ public class GridTmLookupLifecycleAwareSelfTest extends GridAbstractLifecycleAwa
 
         ccfg.setName(CACHE_NAME);
 
-        ccfg.setTransactionManagerLookupClassName(TestTxLookup.class.getName());
+        if (configureGlobalTmLookup)
+            cfg.getTransactionConfiguration().setTxManagerLookupClassName(TestTxLookup.class.getName());
+        else
+            ccfg.setTransactionManagerLookupClassName(TestTxLookup.class.getName());
 
         cfg.setCacheConfiguration(ccfg);
 
@@ -99,4 +112,11 @@ public class GridTmLookupLifecycleAwareSelfTest extends GridAbstractLifecycleAwa
             super.testLifecycleAware();
         }
     }
+
+    /** {@inheritDoc} */
+    public void testLifecycleAwareGlobal() throws Exception {
+        configureGlobalTmLookup = true;
+
+        super.testLifecycleAware();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/006209c6/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
index 4c005af..90c2de0 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
@@ -833,8 +833,6 @@ object VisorCacheCommand {
         cacheT += ("Invalidate", bool2Str(cfg.invalidate()))
         cacheT += ("Start Size", cfg.startSize())
 
-        cacheT += ("Transaction Manager Lookup", safe(cfg.transactionManagerLookupClassName()))
-
         cacheT += ("Affinity Function", safe(affinityCfg.function()))
         cacheT += ("Affinity Backups", affinityCfg.partitionedBackups())
         cacheT += ("Affinity Partitions", safe(affinityCfg.partitions()))



Mime
View raw message