5 Replies Latest reply on Jan 6, 2006 10:54 PM by Ben Wang

    Annotating an interface for TreeCacheAOP in Java 1.5

    Joe Reger Newbie

      Quick question about annotating a POJO in Java 1.5. This is my annotation interface.

      package reger.cache.jboss;
      
      import java.lang.annotation.Target;
      import java.lang.annotation.ElementType;
      
      @Target({ElementType.TYPE})
      public @interface Cacheable {
      }


      I'm then annotating a POJO like this:

      package reger.mypackage;
      
      import reger.cache.jboss.Cacheable;
      
      @Cacheable
      public class MyClass{
      ...
      }


      I'm sure this works for POJOs. But what about interfaces?

      package reger.mypackage;
      
      import reger.cache.jboss.Cacheable;
      
      @Cacheable
      public interface MyInterface{
      ...
      }


      Is this the proper syntax? And if so will this automatically annotate all implementing classes?

      Thanks.

      Joe

        • 1. Re: Annotating an interface for TreeCacheAOP in Java 1.5
          Ben Wang Master

          How do you assoicate the annotation with Aop declaration?

          -Ben

          • 2. Re: Annotating an interface for TreeCacheAOP in Java 1.5
            Joe Reger Newbie

            I compile with apoc and a jboss-aop.xml that looks like:

            <aop>
             <prepare expr="field(*$instanceof{@reger.cache.jboss.Cacheable}->*)"/>
            </aop>


            • 3. Re: Annotating an interface for TreeCacheAOP in Java 1.5
              Ben Wang Master

              Yes, "instanceof" declares all sub-types will be instrumented as well.

              -Ben

              • 4. Re: Annotating an interface for TreeCacheAOP in Java 1.5
                Joe Reger Newbie

                Thanks to the help on the forum I've been able to continue to narrow down my issue. It's not a network issue. The debug output below shows that jgroups is connecting and creating a cluster (viewAccepted()). But then it complains about my class Log. This is not a log4j class or a logger of any kind... just a POJO:

                32344 [Thread-17] INFO org.jboss.cache.TreeCache - viewAccepted(): [192.168.1.101:3621|1] [192.168.1.101:3621, 192.168.1.103:1580]
                32391 [Thread-17] INFO org.jboss.cache.TreeCache - locking the tree to return the in-memory (transient) state
                32500 [Thread-17] ERROR org.jboss.cache.TreeCache - failed getting the in-memory (transient) state
                java.io.NotSerializableException: reger.Log
                 at java.io.ObjectOutputStream.writeObject0(Unknown Source)
                 at java.io.ObjectOutputStream.writeArray(Unknown Source)
                 at java.io.ObjectOutputStream.writeObject0(Unknown Source)
                 at java.io.ObjectOutputStream.writeObject(Unknown Source)
                 at java.util.HashMap.writeObject(Unknown Source)


                I've annotated it in much the same way as I have a number of other POJOs that seem to be accepted by TreeCacheAOP. But this Log class always kicks out the NotSerializableException. It implements an interface, which prompted my question about how to annotate interfaces... and whether I even need to if I annotate all of the implementing classes manually.

                The only thing I can find potentially complex about Log is that one of its properties is an array (fields). But it's an array defined by an interface... in other words FieldType is an interface.

                @Cacheable
                public class Log implements NestedNavItem {
                
                 private int logid;
                 private FieldType[] fields = new FieldType[0];
                
                ...
                
                }


                So I annotated all classes that implement FieldType as @Cacheable. And I've done the same for NestedNavItem. No luck yet.

                If a class isn't annotated TreeCacheAOP will try to serialize it, correct? So maybe the issue is that aopc isn't able to properly annotate Log which eventually causes my cache to fail.

                Grasping at straws a bit here... but I'm sure I'll figure it out! Thanks for any help you can offer.

                Best,

                Joe

                • 5. Re: Annotating an interface for TreeCacheAOP in Java 1.5
                  Ben Wang Master

                  Joe,

                  Looks like you are getting there. :-)

                  1. If the POJO is not aspectized, TreeCacheAop will try to serialize it. Then the POJO needs to implement *Serializable* interface.

                  2. To debug your problem, try to run TreeCacheAop in local mode with just your Log class. Use the beanshell in tutorial page in 1.2.4 distro, for example.

                  -Ben