5 Replies Latest reply on Nov 22, 2004 2:18 PM by Bela Ban

    multiple treecaches - TransactionManagers

    Peter Lindquist Newbie

      Ok. I got this SharedStoreCacheLoader, but I have little problems with using it. It has strange constructor, so it cannot be plugged directly by using XML conf file. Any help with this, please?

      Next thing:
      about shared cache loader.

      Correct me if my assumptions are wrong:
      -I want to have shared DB
      -want to use lazy loading (my custom implementation) from DB
      -so I start cache with several nodes
      -aop tree is empty
      -after that, the tree has one element, loaded with my custom: Map get(Fqn fqn) method
      -I _thought_ from now on, in case every _other_ node wants "/customers/first" it will be given by cache
      -but: from other nodes method: Map get(Fqn) is still executed. So, basically: there is no cache ? :/

      Here is my configuration:
      -FetchStateOnStartup: TRUE

      -CacheLoader: MyCustomLoader
      -CacheLoaderShared: TRUE
      -CacheLoaderPreload: empty -because I want to lazy load all data
      -CacheLoaderFetchTransientState: TRUE
      -CacheLoaderFetchPersistenceState: FALSE

      I think sth might be wrong with implementation of my CacheLoader. Because I think FileBased and Bdbje work correct.

      Any comment?


        • 1. 3856639
          Bela Ban Master

          Couple suggestions:

          1. Like Norbert mentioned, use tx now. There is a known problem in locking when tx is not used. We are fixing that in release 1.2.

          2. If you are using TreeCacheAop, I'd suggest you try the latest pre-1.2 release in jboss-head. I have done some refactoring and bug fixing on the aop part.

          3. If you still are seeing the problem, the best way to help me out to troubleshoot is to write a JUnit test case. That can cut down the time that I need to generate one by myself. Besides, I can check in your test case in the src tree as well. :-)



          • 2. Re: multiple treecaches - TransactionManagers
            Bela Ban Master

            getInstance() doesn't fail, it just throws a NamingException. That's fine you can simply ignore it.

            So you can do this programmatically:
            TreeCache c;
            DummyTxMgr mgr=DummyTxManager.getInstance();

            or via XML


            • 3. Re: multiple treecaches - TransactionManagers
              Peter Lindquist Newbie

              Hmmm.. fair enough. Thank you, though I'm having trouble connecting the TreeCache to the TransactionManager. I'm quite sure it's my fault for not understanding it well enough.

              There doesn't appear to be a TreeCache.setTransactionManager(..) method as implied by your snippet. Distilling from many examples of how to use the factory I get the following (code abbreviated for legibility):

              String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
              Properties properties = new Properties();
              properties.put(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
              DummyTransactionManager transactionManager = DummyTransactionManager.getInstance();
              org.jboss.cache.TreeCache tc = new org.jboss.cache.TreeCache();
              PropertyConfigurator config = new PropertyConfigurator();
              config.configure(tc, "Private-TreeCache.xml");

              And the Lookup class is in the xml:

              <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>

              Then during use most examples call for the something akin to the following, but the lookup always gives me a null.

              UserTransaction tx = (UserTransaction) new InitialContext(properties).lookup("UserTransaction");
              //UserTransaction tx = new DummyUserTransaction(transactionManager);
              tc.put(node, key, value);

              Your pseudo-code snippet implies that there is an easier way for the default case?

              Thank you very much..

              • 4. Re: multiple treecaches - TransactionManagers
                Peter Lindquist Newbie

                On a side note, I do seem to get the safe behavior I want with a SERIALIZABLE IsolationLevel and access code like (other code from above is unchanged):

                //UserTransaction tx = (UserTransaction) new InitialContext(properties).lookup("UserTransaction");
                //UserTransaction tx = new DummyUserTransaction(transactionManager);
                TreeCacheProvider.tc.put(node, key, value);

                Though I would assume that's just because of the SERIALIZABLE spec.

                • 5. Re: multiple treecaches - TransactionManagers
                  Norbert von Truchsess Newbie

                  There's an Interface TransactionManagerLookup that you may implement. Your TransactionManagerLookup-class simply returns the TransactionManager of your choice.

                  Than you let TreeCache use this transactionmanagerlookup-class to make use of the assigned transactionmanager by either passing an instance to TreeCache via setTransactionManagerLookup(TransactionManagerLookup transactionmanagerlookupinstance), or you specify the className via setTransactionManagerLookupClass(String classname)

                  You may want to look into the sources of org.jboss.cache.DummyTransactionManagerLookup to have a working example.