4 Replies Latest reply on Feb 9, 2005 6:05 PM by Tom Baeyens

    configuration problem

    Tom Baeyens Master

      this is a beginners user question. let me know if it doesn't belong here.

      first of all congrats to all involved ! great project.

      i can't seem to manage configuration of the interceptor objects on a per instance basis. can you spot what i'm doing wrong ? any pointer to what part of the FM i should R is appreciated.

      test

      public void testAop() {
       new Token().start();
       new Token().signal();
       }


      interceptor
      public class LogInterceptor implements Interceptor {
      
       String method;
      
       public void setMethod(String method) {
       this.method = method;
       }
      
       public String getName() {
       return "logging aspect";
       }
      
       public Object invoke(Invocation invocation) throws Throwable {
       Object returnValue = null;
       try {
       System.out.println("before '"+method+"'");
       returnValue = invocation.invokeNext();
       } finally {
       System.out.println("after '"+method+"'");
       }
       return returnValue;
       }
      }


      my token class
      public class Token {
      
       public void start() {
       System.out.println("start");
       }
      
       public void signal() {
       System.out.println("signal");
       }
      }


      jboss-aop.xml
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <aop>
       <bind pointcut="execution(public void org.jbpmaop.Token->start())">
       <interceptor class="org.jbpmaop.LogInterceptor" scope="PER_INSTANCE">
       <attribute name="method">start</attribute>
       </interceptor>
       </bind>
       <bind pointcut="execution(public void org.jbpmaop.Token->signal())">
       <interceptor class="org.jbpmaop.LogInterceptor" scope="PER_INSTANCE">
       <attribute name="method">signal</attribute>
       </interceptor>
       </bind>
      </aop>


      i get output
      before 'start'
      start
      after 'start'
      before 'start'
      signal
      after 'start'


      but i expected output
      before 'start'
      start
      after 'start'
      before 'signal'
      signal
      after 'signal'



        • 1. Re: configuration problem
          Kabir Khan Master

          Hmm yeah,

          it only injects stuff once, when the object is created. In the example given this will be on first access to each instance of Token (scope: PER_INSTANCE). Maybe I should make it fail more noisily if the XML implies injection more than once?

          Are you trying to just log the name of the method in which case you could cast the Invocation to a MethodInvocation and then call getMethod()?

          Or do you want to do something more advanced?

          • 2. Re: configuration problem
            Tom Baeyens Master

            i want something more advanced, i'm afraid.

            the scoping is not the issue for me. it's more the configuration of the interceptor objects.

            you say "XML implies injection". do you mean the configuration of the interceptor with this ? if yes, i don't think it should lead to noisy failure. but instead you should apply differently configured interceptors to the different pointcuts, right ?

            are the interceptor objects pooled ? per classname ? is that the reason why the configuration ends up in the wrong interceptor ?

            regards, tom.

            • 3. Re: configuration problem
              Kabir Khan Master

              Hi,

              You can give the interceptors a name and they will be "pooled" by their name. If you do not give them a name, the name of the class will be used as the name internally, so they will effectively be pooled by class name.

              So, the following should work

              <aop>
               <interceptor name="startInt" class="org.jbpmaop.LogInterceptor" scope="PER_INSTANCE">
               <attribute name="method">start</attribute>
               </interceptor>
               <interceptor name="signalInt" class="org.jbpmaop.LogInterceptor" scope="PER_INSTANCE">
               <attribute name="method">signal</attribute>
               </interceptor>
               <bind pointcut="execution(public void org.jbpmaop.Token->start())">
               <interceptor-ref name="startInt"/>
               </bind>
               <bind pointcut="execution(public void org.jbpmaop.Token->signal())">
               <interceptor-ref name="signalInt"/>
               </bind>
              </aop>
              

              Or the equivalent:
              <aop>
               <bind pointcut="execution(public void org.jbpmaop.Token->start())">
               <interceptor name="startInt" class="org.jbpmaop.LogInterceptor" scope="PER_INSTANCE">
               <attribute name="method">start</attribute>
               </interceptor>
               </bind>
               <bind pointcut="execution(public void org.jbpmaop.Token->signal())">
               <interceptor name="signalInt" class="org.jbpmaop.LogInterceptor" scope="PER_INSTANCE">
               <attribute name="method">signal</attribute>
               </interceptor>
               </bind>
              </aop>
              



              I prefer the first option, since it kind of splits the definition and usage of the interceptors.

              Cheers,

              Kabir

              • 4. Re: configuration problem
                Tom Baeyens Master

                fabulous !

                thanks a lot, kabir.

                see you soon.

                regards, tom.