4 Replies Latest reply on Jan 12, 2005 8:48 AM by Bill Burke

    Fix for PerInstanceAdvice.java

    Neil Avery Newbie

      It would repeatedly reinitialize itself on every invocation because the
      "initialized" flag wasnt being set. Net result was very slow performance when using PER_INSTANCE scoping.

      neil.
      ps. I wasnt sure where to put this.
      PerInstanceAdvice.java

      public Object invoke(Invocation invocation) throws Throwable
      {
      Object targetObject = invocation.getTargetObject();
      if (targetObject == null) return invocation.invokeNext(); // static method call or static field call

      Advised advised = (Advised)targetObject;
      ClassInstanceAdvisor advisor = (ClassInstanceAdvisor)advised._getInstanceAdvisor();
      Object aspect = advisor.getPerInstanceAspect(aspectDefinition);
      if (!initialized)
      {
      init(adviceName, aspect.getClass());
      >>>> initialized = true;
      }
      Method advice = resolveAdvice(invocation);
      Object[] args = {invocation};

      try
      {
      return advice.invoke(aspect, args);
      }
      catch (InvocationTargetException e)
      {
      throw e.getCause(); //To change body of catch statement use Options | File Templates.
      }
      }