1 Reply Latest reply on May 2, 2018 8:00 AM by Galder Zamarreño

    How to configure and use pessimistic lock in Wildfly10/EAP7 cluster?

    Patrick Huang Newbie

      Hi guys,

       

      I am trying to configure infinispan cache to use it as a cluster lock. Here is my config:

      <cache-container name="mt-cluster-cache">

                      <transport lock-timeout="60000"/>

                      <distributed-cache name="doc-lock" jndi-name="infinispan/mt-cluster-cache/doc-lock" mode="SYNC" owners="2">

                          <transaction locking="PESSIMISTIC" mode="FULL_XA"/>

                      </distributed-cache>

                  </cache-container>

       

      I am using CDI so here is how I produce the cache:


      @Resource(lookup = "java:jboss/infinispan/container/mt-cluster-cache")

      private CacheContainer mtClusterCache;

       

      @Produces
      @ClusteredCache(DOC_PROCESS_CACHE)

      public Cache<DocumentProcessKey, Boolean> docProcessCache() {

         return mtClusterCache.getCache(DOC_PROCESS_CACHE);

      }

       

      @Produces
      @ClusteredCache(DOC_PROCESS_CACHE)

      public TransactionManager dockProcessCacheTransactionManager(

         @ClusteredCache(DOC_PROCESS_CACHE)

        Cache<DocumentProcessKey, Boolean> cache) {

         return cache.getAdvancedCache().getTransactionManager();

      }

       

      However when I try to use it the transaction manager is null.

      transactionManager.begin();

      // transaction.begin();
      docProcessCache.getAdvancedCache().lock(key);

       

      If I inject UserTransaction from the Wildfly/EAP container and use that instead, it will complain locking requires transaction etc. What did I do wrong here? Thanks.