Version 2

    Threadbased Aspect

    This aspect is usable outside of JBoss Application Server

     

    What we want to accomplish with this aspect is that when you tag a field (static or member) as @ThreadBased, its value will behave as though it were stored in a java.lang.ThreadLocal.  Sure, you could use a ThreadLocal variable directly, but the problem with ThreadLocal is that it is untyped and you have to use "verbose" (ok, its not that verbose) get() and set() methods.  So, what we'll do here is create a typed ThreadLocal field.

     

    Using this new type would look like this:

     

    JDK 1.4

    import org.jboss.aspects.Threadbased;
    
    public class Foo
    {
       /**
        * @@org.jboss.aspects.Threadbased 
        */
       private int counter;
    }
    

     

    JDK 1.4 requires our AnnotationCompiler.

     

    JDK 5.0

    import org.jboss.aspects.Threadbased;
    
    public class Foo
    {
       @Threadbased private int counter;
    }
    

     

     

    To use outside of the JBoss Application Server you need this binding:

     

    jboss-aop.xml

    <aop>
       <aspect class="org.jboss.aspects.ThreadbasedAspect" scope="PER_JOINPOINT"></aspect>
       <bind pointcut="field(* *->@org.jboss.aspects.Threadbased)">
          <advice name="access" aspect="org.jboss.aspects.ThreadbasedAspect"></advice>
       </bind>
    </aop>