4 Replies Latest reply on Nov 4, 2004 12:40 PM by Bill Burke

    Unbound field advice binding

    Szczepan Kuzniarz Newbie

      Hi,

      I try tu use dependency injection pattern to provide InitialContext reference to some class. The marker annotation looks like this:

      @Target( ElementType.FIELD )
      @Retention( RetentionPolicy.RUNTIME )
      public @interface Injection {
      }


      and the target class:

      public class DAOFactoryImpl implements DAOFactory {
       @Injection private InitialContext initialContext;
      
       public DAOFactoryImpl() {
       try {
       DataSource dataSource = (DataSource)initialContext.lookup( "java:jdbc/DB" );
       ...
       }
       catch( NamingException e ) {
       ...
       }
       }
      
       ...
      }


      The XML binding:

      <aop>
      
       <aspect class="InitialContextAspect" scope="PER_JOINPOINT"/>
      
       <bind pointcut="get(javax.naming.InitialContext *->@Injection)">
       <advice name="get" aspect="InitialContextAspect"/>
       </bind>
      
      </aop>


      and the aspect class itself:

      public class InitialContextAspect {
       public Object get( FieldReadInvocation invocation ) throws Throwable {
       Field field = invocation.getField();
       if( field.getType().isAssignableFrom( InitialContext.class ) ) {
       ...
       }
       return fieldReadInvocation.invokeNext();
       }
      }
      


      When I deploy classes and aspects into JBoss 4.0 everything seems ok (no errors in log), but web console displays my advice in 'Unbound bindings' node:

      file:/C:/Java/jboss-4.0.0/server/tomcat5/tmp/deploy/tmp23014jboss-aop.xml0
      
      Advice Binding
      
      Pointcut Expression: get(javax.naming.InitialContext *->@Injection)



      Best regards,

      Szczepan Kuzniarz

        • 1. Re: Unbound field advice binding
          Bill Burke Master

          The console is a little weird...

          It will only show bindings for LOADED classes. If you execute the code, you should see the bindings.

          If you execute the code, and the aspect is is UNBOUND in the webconsole, then there is a bug in the webconsole.


          ANOTHER THING:

          By default, class load time transformations are turned off, so your aspect may not be instrumenting the code. Either use the precompiler or read this doco:

          http://docs.jboss.org/aop/aspect-framework/reference/en/html/running.html#jboss

          I suggest using the precompiler because currently, load-time transformation is a HUGE memory hog.

          Let me know if any of these fix the problem

          Regards

          Bill

          • 2. Re: Unbound field advice binding
            Szczepan Kuzniarz Newbie

             

            Bill Burke wrote:
            It will only show bindings for LOADED classes. If you execute the code, you should see the bindings.

            You are right, my advice is bound when I instantiate a class and everything works as expected.

            Bill Burke wrote:
            I suggest using the precompiler because currently, load-time transformation is a HUGE memory hog.

            I see. Is this memory used only during transformation and then released? Or once allocated is never freed?

            BTW: I'm really impressed by JBossAOP / JDK 1.5 / Annotations combination :-)


            Best regards,

            Szczepan Kuzniarz

            • 3. Re: Unbound field advice binding
              kevinconner Newbie

               

              I suggest using the precompiler because currently, load-time transformation is a HUGE memory hog.


              I'm nearly finished an alternative load-time which has a much better memory footprint. I've been working on a different version of the classpool that doesn't store the same information.

              Kev


              • 4. Re: Unbound field advice binding
                Bill Burke Master

                The memory is not released. What is created is Javassist data structures. I can't release the memory because class transformation happens at class load time. A class may be transformed, then another class that references that transformed class may have joinpoints affected by that transformation.

                Bill