5 Replies Latest reply on May 14, 2006 10:12 PM by ben.wang

    A problem with Java 1.5 enum replication

    roginsky

      I have two unrelated questions, the "enum question" much more pressing.
      We have a class with some enum fields. And a clustered AOP cache. Across WAN, not sure if it matters. When the value of the enum field changes (through simple assignment), the change is reflected in the local cache, but not replicated to the other node in the cluster. Other fields are replicated without problems. We tried both synchronous and asynchronous replication. Is there anything I need to know about enums? The class where this field lives, is Serializable. The enum itself is not explicitly desclared Serializable, but Enum interface in Java 1.5 is.

      Second question:
      I get this message when the server starts up:
      WARN [TreeCache] No transaction manager lookup class has been defined. Transactions can not be used.
      I define the lookup class in the cache config file as shown below:

      
      <!-- Configure the TransactionManager -->
       <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
      


      My transactions actually do seem to work, but the log still worries me. What am I doing wrong?
      I get my transaciton like this:
      .
       Properties prop = new Properties();
       prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
      UserTransaction tx=(UserTransaction)new InitialContext(prop).lookup("UserTransaction");
      


      Thanks for your help!
      Renata.

        • 1. Re: A problem with Java 1.5 enum replication

          To answer you questions:

          1. Enum is a Java class that we are not supposed to instrument and intercept. So I need to think of a solution when we support 1.5 officially in release 1.3. Can you please open up an Jira issue (jira.jboss.com) under JBCACHE (with component aop)?

          2. If you are using DummyTX, then you can also change the Manager class to DummyTransactionManagerClass.

          -Ben

          • 2. Re: A problem with Java 1.5 enum replication
            roginsky

            Thank you Ben!
            1) Before I go to JIRA, let me make sure we understand each other. I forgot to clearly mention in my previous e-mail that we don't instrument our classes currently. They are just Serializable. So in this case does the fact that you are not intercepting the enum field itself still matter?
            Also, the change is reflected correctly in the local cache, it's just the replication to the other node in the cluster that doesn't happen.

            2) Actually I want to use JBossTransactionManagerLookup, but I didn't find any examples in the docs how should I create my transaction in this case.
            By the way, do I really need to use JBossTransactionManagerLookup? What would you recommend?

            Again, many thanks for all your help.

            Renata.

            • 3. Re: A problem with Java 1.5 enum replication

              OK, so if you are not instrumenting your Pojos that mean you are not using TreeCacheAop. In that case, you will need to do an explicit cache.put(...) after each modification for it to replicate. This is way to do it in plain cache.

              -Ben

              • 4. Re: A problem with Java 1.5 enum replication
                jpyorre

                Any progress on enum replication so far?

                I am currently using a quick fix on "CachedType.java", because enums didn't work when I loaded them back using a cache loader. The fix simply considers enumerators as immediates (added code in bold):

                 public static boolean isImmediate(Class clazz)
                 {
                 return immediates.contains(clazz) || isEnumerator(clazz);
                 }
                 
                 public static boolean isEnumerator(Class clazz) {
                 return Enum.class.isAssignableFrom(clazz);
                 }
                



                Seems to work fine at least locally (I have not tested cluster-wide replication).

                I have no idea how enums are serialized, but if its just the ordinal thats serialized then this solution should always work and in that case there is no point in instrumenting the enum anyhow.


                Regards,

                Jussi Pyörre

                • 5. Re: A problem with Java 1.5 enum replication

                  Enumerator is Serialzable so you should not have to patch CachedType though?

                  I have created a Jira:
                  http://jira.jboss.com/jira/browse/JBCACHE-619
                  You can subscribe to watch it.

                  I am scheduling it for 2.0 which is about 3 months away.