3 Replies Latest reply on Mar 10, 2006 5:46 AM by kabirkhan

    Constructor Interception on Caller-Side?

    schaefera

      I just run into a snag when I tried to instrument Constructors. It seems that constructors are only instrumented on the Caller side meaning that a constructor is not instrumented when I do not instrument the caller's code for example using AOPC.
      I also do not understand why there are two ways to define the constructor interception (execution and call) when there is actually only one (call) way it is actually done. IMO it would be much better to drop the constructor definition on the callee side (execution) and only allow it for caller side (call).

      -Andy

        • 1. Re: Constructor Interception on Caller-Side?
          kabirkhan

          For constructor execution to occur we create a wrapper method in the target class which does the "magic", but we need to replace all the callers to use this method.

          As you say, for caller constructor execution we need to instrument the caller as well, however the way the interceptor chains are maintained has some slight differences.

          For "execution" transformation we use the target class's advisor

          For "caller" transformation we use the calling class's advisor

          • 2. Re: Constructor Interception on Caller-Side?
            schaefera

            Bottom line: it means that I cannot instrument a constructor which is either created by a non-instrumentable class (JBoss core) or by classes that were not instrumented.

            This is unfortunate because AspectJ does it actually as expected even though I cannot use around() advice (must use before and after).

            -Andy

            • 3. Re: Constructor Interception on Caller-Side?
              kabirkhan

              For this situation you could look at using the "construction" construct, where the mounting the interceptor chains takes place inside the constructor (after the main body.

              example:

              construction(POJO->new(int))

              Note that you can change the value of the jboss.aop.include system property to allow instrumentation of classes in packages under org.jboss. By default all of org.jboss apart from org.jboss.injbossaop is turned off.

              There are some classes however that we do not allow weaving of, these inclide classes whose fqn starts with:

              javassist.
              org.jboss.aop
              org.jboss.aop
              java.
              javax.
              sun.
              com.sun.
              jrockit.
              com.bea.vm.