7 Replies Latest reply on May 21, 2006 6:52 AM by gshriki

    Using JBoss cache to replicate object between machines

    gshriki

      Hi there.

      I'm trying to replicate java objects between two machines, using JBoss Cache. The object is pretty simple one.
      The strange thing is that the first time I?m inserting the object with putObject, it is duplicated in to the other machine, but when I?m updating it, the cache does not intercept the changes, and I?m still have the original values in the second machine.

      The scenario:
      1. Machine A and machine B starts and sets up a cluster between them.
      2. Machine A creates an object and inserts it to the cache (putObject).
      3. Machine B prints the values of the object.
      4. Machine A updates the values of the object
      5. Machine B prints the values of the object

      The results are that in 3 and 5, machine B prints same values (the original values).

      Am I missing something?

      Help is appreciated?

      Gilad.

      The object:

      public class Node implements Serializable {
       private static final long serialVersionUID = 1L;
       protected String pStr1;
       protected String pStr2;
       protected int pNumber;
      
       public String getPStr1() {return pStr1;}
       public void setPStr1(String str1) {this.pStr1 = str1;}
       public String getPStr2() {return pStr2;}
       public int getPNumber() {return pNumber;}
       public void setPStr2(String str2) {this.pStr2 = str2;}
       public void setPNumber(int num) {this.pNumber = num;}
      
       public Node(String s1,String s2,int num)
       {
       pStr1 = s1;
       pStr2 = s2;
       pNumber = num;
       }
      }


        • 1. Re: Using JBoss cache to replicate object between machines

          Has your Node class been instrumented already, e.g., running thru aopc? Since it is Serializable, it still can be used by putObject, but PojoCache won't intercept it if it is not instrumented beforehand.

          To test your enviornment, you can also run thru the examples that came with JBossCache making sure those PojoCache (aop) examples work first.

          • 2. Re: Using JBoss cache to replicate object between machines
            gshriki

            Hi,

            First, I would like to thank you for the answer.

            I'm trying to declare the object with annotation:

            @org.jboss.cache.aop.annotation.InstanceOfPojoCacheable
            public class Node implements Serializable {
            ...


            But I still haven't figured out how can I instrument the class using the load-time method... How do I use the special class loader mentioned in the documentation?

            Thanks!

            • 3. Re: Using JBoss cache to replicate object between machines
              gshriki

              BTW - when I'm trying to remove the implements Serializable on the Node declaration, I get:

              java.lang.IllegalArgumentException: TreeCacheAop.putObject():
              Object type is neither aspectized nor Serializable nor an array of primitives.
              Object class name is Node


              Any idea why?

              Gilad

              • 4. Re: Using JBoss cache to replicate object between machines

                Yes, the IllegalArgumentException indicates that your POJO is not instrumented properly.

                Under the distro example, there are examples for load-time and compile-time options. So please run it through first and I think you will get the idea.

                • 5. Re: Using JBoss cache to replicate object between machines
                  gshriki

                  Hi,

                  I'm trying to run the examples, distributed with the JBossCache, within Eclipse, but it looks like I'm missing something. I keep getting the following exception...

                  "java.lang.IllegalArgumentException: TreeCacheAop.putObject(): Object type is neither aspectized nor Serializable nor an array of primitives. Object class name is examples.Student"


                  Anything I need to do, except from simply loading the source into the Eclipse?

                  Thanks!

                  Gilad

                  • 6. Re: Using JBoss cache to replicate object between machines

                    Did you get it to run under commnad line first? If yo want to run it under Eclipse, you will need to either 1) use the aop classloader (see the ant target), or 2) use aopc first to instrument the pojo (also ant target).

                    • 7. Re: Using JBoss cache to replicate object between machines
                      gshriki

                      Hi,

                      OK. After running the class loader:

                      java org.jboss.aop.hook.GenerateInstrumentedClassLoader /opt/JBC1/bin/classloader/


                      I've tried to run my Main class:
                      java -Xbootclasspath/p:/opt/JBC1/bin/classloader -Djboss.aop.path=/opt/JBC1/bin/META-INF/jboss-aodp.xml Main


                      I got the following error:
                      Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/aop/AspectManager
                       at java.lang.ClassLoader.defineClass(ClassLoader.java)
                       at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
                       at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
                       at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
                       at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
                       at java.security.AccessController.doPrivileged(Native Method)
                       at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
                       at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
                       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
                       at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
                       at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)


                      Any idea why?

                      BTW - I found the same problem in
                      http://www.jboss.org/index.html?module=bb&op=viewtopic&t=62831&view=previous
                      But there's no answer.

                      Thanks.