Announcement Announcement Module
Collapse
No announcement yet.
JamonPerformanceMonitorInterceptor changed in Spring 1.2? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JamonPerformanceMonitorInterceptor changed in Spring 1.2?

    Hi all,

    I've been happily using JamonPerformanceMonitorInterceptor in Spring 1.1.5, but today I upgraded to Spring 1.2.2 and am no longer seeing JAMon console output, and my intercepted methods are no longer being metered (I use a customized JAMonAdmin.jsp for display).

    I notice in the Spring 1.2 changelog that JamonPerformanceMonitorInterceptor was refactored:

    Code:
    Changes in version 1.2 final (13.5.2005)
    ----------------------------------------
    Package org.springframework.aop
    * introduced AbstractTraceInterceptor superclass for all trace interceptors, supporting a static or a dynamic logger
    * deprecated TraceInterceptor in favor of SimpleTraceInterceptor, which is a subclass of AbstractTraceInterceptor
    * reworked PerformanceMonitorInterceptor/JamonPerformanceMonitorInterceptor into subclasses of AbstractTraceInterceptor
    * reworked DebugInterceptor into a subclass of SimpleTraceInterceptor
    * added CustomizableTraceInterceptor, supporting pattern-based enter and exit messages with placeholders
    * all trace interceptors log at Commons Logging's "trace" level now, instead of "info" or "debug"
    * moved AopUtils' "getAllInterfaces" and "getAllInterfacesForClass" methods to org.springframework.util.ClassUtils
    It didn't look to me that I should do anything differently, but clearly something is awry. What am I missing?

    Here's my interceptor declaration:
    Code:
    <bean id="jamonPerformanceMonitorInterceptor" class="org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor"/>
    And here's my usage:
    Code:
    <!-- &#40;1&#41; Chain badgeService calls into its participating interceptors  -->
    <bean id="badgeService" class="org.springframework.aop.framework.ProxyFactoryBean">
    
        <property name="proxyInterfaces"><value>passport.service.BadgeService</value></property>
        <property name="interceptorNames">
            <list>
    
                <!-- Performance monitor -->
                <idref bean="jamonPerformanceMonitorInterceptor"/>
    
                <!-- Security check -->
                <idref bean="badgeServiceSecurity"/>
    
                <!-- Finally, the service implementation -->
                <idref local="badgeServiceHibernateInterceptorProxy"/>
    
            </list>
        </property>
    
    </bean>
    Thanks in advance,
    Scott

  • #2
    Scott,

    The JamonPerformanceMonitorInterceptor is built on the generic trace interceptor framework. This provides some level of control over whether or not the interceptor is enabled by only tracing when the log level is configured to trace. Take a look at the JavaDoc for AbstractTraceInterceptor for a little more detail on this.

    Rob

    Comment


    • #3
      Rob, thanks so much for the quick reply - that did the trick! The solution was to set useDynamicLogger to true:

      Code:
      	<bean id="jamonPerformanceMonitorInterceptor" class="org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor">
      		<property name="useDynamicLogger"><value>true</value></property>
      	</bean>
      Scott

      Comment


      • #4
        Quick note for anyone reading this later. I did end up needing more control over the JAMon metering when running in different environments and so ended up writing my own interceptor that's nearly identical to the Spring 1.1.5 version that doesn't derive from the trace interceptor framework.

        Comment


        • #5
          Scott,

          What features did you find you needed? I'm keen to try and make the tracing interceptors as flexible as possible. Perhaps we can build some of your features into the framework.

          Rob

          Comment


          • #6
            The main issue I kept running into was that since Websphere uses Commons Logging as its own internal provider, it's difficult to override default log levels without changing module loading sequences, which tends to create all sorts of other issues. So, although I could set the tracing interceptor log levels just fine when running my out-of-container tests, I couldn't set them (and thus activate them) while running in Websphere.

            Comment


            • #7
              Code?

              Scott,

              Could you please post your code and configuration? I am running a similar issue under WebSphere (WAS 5.1)...

              Nicolas

              Comment


              • #8
                Should work with Websphere 5.1...

                Code:
                 
                /*
                 * Copyright 2002-2004 the original author or authors.
                 *
                 * Licensed under the Apache License, Version 2.0 (the "License");
                 * you may not use this file except in compliance with the License.
                 * You may obtain a copy of the License at
                 *
                 *      http://www.apache.org/licenses/LICENSE-2.0
                 *
                 * Unless required by applicable law or agreed to in writing, software
                 * distributed under the License is distributed on an "AS IS" BASIS,
                 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                 * See the License for the specific language governing permissions and
                 * limitations under the License.
                 */
                package myApp.aop.interceptor;
                import java.io.Serializable;
                import org.aopalliance.intercept.MethodInterceptor;
                import org.aopalliance.intercept.MethodInvocation;
                import org.apache.commons.logging.Log;
                import org.apache.commons.logging.LogFactory;
                import com.jamonapi.Monitor;
                import com.jamonapi.MonitorFactory;
                /**
                 * Performance monitor interceptor that uses <b>JAMon</b> library
                 * to perfom the performance mesurment on the intercepted method
                 * and output the stats.
                 *
                 * <p>This code is inspired by Thierry Templier's blog.
                 *
                 * <p>We use a customized version because since Spring 1.2 this class extends a
                 * TraceInterceptor that doesn't work properly with Websphere's usage of Jakarta Commons</p>
                 *
                 * @author Dmitriy Kopylenko
                 * @author Juergen Hoeller
                 * @since 1.1.3
                 */
                public class JamonPerformanceMonitorInterceptor implements MethodInterceptor, Serializable {
                    /** Static to avoid serializing the logger */
                    protected static final Log logger = LogFactory.getLog(JamonPerformanceMonitorInterceptor.class);
                    public Object invoke(MethodInvocation invocation) throws Throwable {
                        String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName();
                        Monitor mon = MonitorFactory.start(name);
                        try {
                            return invocation.proceed();
                        }
                        finally {
                            mon.stop();
                            if (logger.isInfoEnabled()) {
                                logger.info("JAMon performance statistics for method [" + name + "]:\n" + mon);
                            }
                        }
                    }
                }
                Code:
                 
                <!-- ========================= PERFORMANCE MONITORING ========================= -->
                <!-- (Loaded before database and service beans) -->
                <!-- See http://www.springframework.org/docs/api/org/springframework/aop/interceptor/JamonPerformanceMonitorInterceptor.html -->
                <!-- and http://www.jamonapi.com for more information. -->
                <!-- *** We use a customized version because since Spring 1.2 this class extends a *** -->
                <!-- *** TraceInterceptor that doesn't work properly with Websphere's usage of Jakarta Commons *** -->
                <bean id="jamonPerformanceMonitorInterceptor" class="myApp.aop.interceptor.JamonPerformanceMonitorInterceptor" />

                Comment


                • #9
                  Thanks

                  Thank you Scott.

                  In the meantime, I had a look at the Spring 1.1.5 code and this looks very familiar. Your code works fine as well.

                  I spend quite a lot of time figuring out why it didn't work with WebSphere... Apparently it is something with Commons Logging and the fact that you can't override the default log level...? Am I right?

                  Nicolas

                  Comment


                  • #10
                    Yea, it's a well-documented (and bemoaned) problem with commons logging in the way it creates a JVM-wide instance based on a single config. Search around for "commons logging class loading problems" and you'll get quite an eye full. And since Websphere 5 uses its own commons-logging extension called TraceLog (or similar) that is instantiated upon server startup, applications that run within it find that commons logging is already loaded and configured, so they can't (easily) change the log level, redirect output, etc. without changing Websphere's module loading sequence to PARENT_LAST, which usually creates worse problems.

                    Comment


                    • #11
                      Well, actually we use the PARENT_LAST settings... Is there something I can do then?

                      Comment


                      • #12
                        Using Jakarta Commons Logging with WebSphere 5

                        See http://www-1.ibm.com/support/docview...id=swg27004610

                        Comment


                        • #13
                          Thanks for this pointer. This is actually the way to make it (JCL under WAS5.1) work. Quite a pain, isn't it?

                          Cheers!

                          Comment

                          Working...
                          X