commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r721657 [3/3] - in /commons/sandbox/monitoring/branches/modules: core/src/ core/src/main/ core/src/main/java/ core/src/main/java/org/ core/src/main/java/org/apache/ core/src/main/java/org/apache/commons/ core/src/main/java/org/apache/common...
Date Sat, 29 Nov 2008 09:08:44 GMT
Added: commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/CategorizedMonitoringFilter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/CategorizedMonitoringFilter.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/CategorizedMonitoringFilter.java
(added)
+++ commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/CategorizedMonitoringFilter.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.instrumentation.servlet;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+
+/**
+ * Select the category to use for a requested URI by searching a matching pattern
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class CategorizedMonitoringFilter
+    extends MonitoringFilter
+    implements Filter
+{
+    /**
+     * Ordered Map of patterns that defines categories. First pattern matching the requested
URI define the category
+     */
+    Map<Pattern, String> categories = new LinkedHashMap<Pattern, String>();
+
+    public void registerCategoryForPattern( String pattern, String category )
+    {
+        categories.put( Pattern.compile( pattern ), category );
+    }
+
+    @Override
+    protected String getCategory( String uri )
+    {
+        for ( Map.Entry<Pattern, String> entry : categories.entrySet() )
+        {
+            Pattern pattern = entry.getKey();
+            if ( pattern.matcher( uri ).matches() )
+            {
+                return entry.getValue();
+            }
+        }
+        return super.getCategory( uri );
+    }
+
+    @Override
+    public void init( FilterConfig config )
+        throws ServletException
+    {
+        super.init( config );
+        // TODO get patterns from configuration
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/MonitoringFilter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/MonitoringFilter.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/MonitoringFilter.java
(added)
+++ commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/MonitoringFilter.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,113 @@
+package org.apache.commons.monitoring.instrumentation.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.StopWatch;
+
+public class MonitoringFilter
+{
+
+    private Repository repository;
+    private String subsystem;
+    private String category;
+
+    public MonitoringFilter()
+    {
+        super();
+    }
+
+    /**
+     * Delegates to Http based doFilter. {@inheritDoc}
+     *
+     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
+     *      javax.servlet.FilterChain)
+     */
+    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain
)
+        throws IOException, ServletException
+    {
+        if ( request instanceof HttpServletRequest )
+        {
+            HttpServletRequest httpRequest = (HttpServletRequest) request;
+            HttpServletResponse httpResponse = (HttpServletResponse) response;
+            doFilter( httpRequest, httpResponse, chain );
+        }
+        else
+        {
+            // Not an HTTP request...
+            chain.doFilter( request, response );
+        }
+    }
+
+    public void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain
chain )
+        throws IOException, ServletException
+    {
+        String uri = getRequestedUri( request );
+        String category = getCategory( uri );
+        Monitor monitor = repository.getMonitor( uri, category, subsystem );
+
+        StopWatch stopWatch = repository.start( monitor );
+        try
+        {
+            chain.doFilter( request, response );
+        }
+        finally
+        {
+            stopWatch.stop();
+        }
+    }
+
+    /**
+     * @param request
+     * @return
+     */
+    protected String getRequestedUri( HttpServletRequest request )
+    {
+        String uri = request.getRequestURI();
+        String context = request.getContextPath();
+        uri = uri.substring( context.length() );
+        return uri;
+    }
+
+    /**
+     * @param uri
+     * @return
+     */
+    protected String getCategory( String uri )
+    {
+        return category;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+     */
+    public void init( FilterConfig config )
+        throws ServletException
+    {
+        subsystem = config.getInitParameter( "subsystem" );
+        category = config.getInitParameter( "category" );
+        repository = ServletContextUtil.getRepository( config.getServletContext() );
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see javax.servlet.Filter#destroy()
+     */
+    public void destroy()
+    {
+        // Nop
+    }
+
+}
\ No newline at end of file

Added: commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/ServletContextUtil.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/ServletContextUtil.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/ServletContextUtil.java
(added)
+++ commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/ServletContextUtil.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.instrumentation.servlet;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.repositories.DefaultRepository;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class ServletContextUtil
+{
+    /** key for Repository as ServletContext attribute */
+    public static final String REPOSITORY_KEY = Repository.class.getName();
+
+    public static synchronized Repository getRepository( ServletContext context )
+        throws ServletException
+    {
+        Object attribute = context.getAttribute( REPOSITORY_KEY );
+        if ( attribute != null )
+        {
+            if ( attribute instanceof Repository )
+            {
+                return (Repository) attribute;
+            }
+            else
+            {
+                throw new ServletException( "Attribute " + REPOSITORY_KEY + " in servletContext
is not a Repository" );
+            }
+        }
+        else
+        {
+            Repository repository = new DefaultRepository();
+            context.setAttribute( REPOSITORY_KEY, repository );
+            return repository;
+        }
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTag.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTag.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTag.java
(added)
+++ commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTag.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.instrumentation.servlet.jsp;
+
+import static org.apache.commons.monitoring.instrumentation.servlet.jsp.TagUtils.getScope;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.StopWatch;
+
+/**
+ * A JSP tag to monitor JSP rendering performances
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class StartTag
+    extends TagSupport
+{
+    private String id;
+
+    private String scope;
+
+    private String name;
+
+    private String category;
+
+    private String subsystem;
+
+    protected String repository;
+
+
+    /**
+     * @param id the id to set
+     */
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
+     */
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        Repository repo = TagUtils.getRepository( pageContext, repository );
+
+        StopWatch stopWatch = repo.start( repo.getMonitor( name, category, subsystem ) );
+        if (scope != null)
+        {
+            pageContext.setAttribute( id, stopWatch, getScope( scope ) );
+        }
+        else
+        {
+            pageContext.setAttribute( id, stopWatch );
+        }
+        return EVAL_PAGE;
+    }
+
+    /**
+     * @param scope the scope to set
+     */
+    public void setScope( String scope )
+    {
+        this.scope = scope;
+    }
+
+    /**
+     * @param name the name to set
+     */
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    /**
+     * @param category the category to set
+     */
+    public void setCategory( String category )
+    {
+        this.category = category;
+    }
+
+    /**
+     * @param subsystem the subsystem to set
+     */
+    public void setSubsystem( String subsystem )
+    {
+        this.subsystem = subsystem;
+    }
+
+    public void setRepository( String repository )
+    {
+        this.repository = repository;
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTagTei.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTagTei.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTagTei.java
(added)
+++ commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StartTagTei.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.instrumentation.servlet.jsp;
+
+import javax.servlet.jsp.tagext.TagData;
+import javax.servlet.jsp.tagext.TagExtraInfo;
+import javax.servlet.jsp.tagext.VariableInfo;
+
+import org.apache.commons.monitoring.StopWatch;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class StartTagTei
+    extends TagExtraInfo
+{
+    /**
+     * {@inheritDoc}
+     *
+     * @see javax.servlet.jsp.tagext.TagExtraInfo#getVariableInfo(javax.servlet.jsp.tagext.TagData)
+     */
+    @Override
+    public VariableInfo[] getVariableInfo( TagData data )
+    {
+        VariableInfo info =
+            new VariableInfo( data.getAttributeString( "id" ), StopWatch.class.getName(),
true, VariableInfo.AT_END );
+        return new VariableInfo[] { info };
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StopTag.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StopTag.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StopTag.java
(added)
+++ commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/StopTag.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.instrumentation.servlet.jsp;
+
+import static org.apache.commons.monitoring.instrumentation.servlet.jsp.TagUtils.getScope;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.monitoring.StopWatch;
+
+/**
+ * A JSP tag to monitor JSP rendering performances
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class StopTag
+    extends TagSupport
+{
+    private String id;
+
+    private String scope;
+
+    /**
+     * @param id the id to set
+     */
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
+     */
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        StopWatch stopWatch;
+        if (scope != null)
+        {
+            stopWatch = (StopWatch) pageContext.getAttribute( id, getScope( scope ) );
+        }
+        else
+        {
+            stopWatch = (StopWatch) pageContext.getAttribute( id );
+        }
+        if (stopWatch == null)
+        {
+            throw new JspException( "No StopWatch under ID " + id + " and scope " + scope
);
+        }
+        stopWatch.stop();
+        return EVAL_PAGE;
+    }
+
+    /**
+     * @param scope the scope to set
+     */
+    public void setScope( String scope )
+    {
+        this.scope = scope;
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/TagUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/TagUtils.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/TagUtils.java
(added)
+++ commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/servlet/jsp/TagUtils.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.instrumentation.servlet.jsp;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.commons.monitoring.Repository;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class TagUtils
+{
+    /** Maps JSP scope names to PageContext constants */
+    private static final Map<String, Integer> scopes = new HashMap<String, Integer>();
+
+    static
+    {
+        scopes.put( "page", new Integer( PageContext.PAGE_SCOPE ) );
+        scopes.put( "request", new Integer( PageContext.REQUEST_SCOPE ) );
+        scopes.put( "session", new Integer( PageContext.SESSION_SCOPE ) );
+        scopes.put( "application", new Integer( PageContext.APPLICATION_SCOPE ) );
+    }
+
+    /**
+     * Converts the scope name into its corresponding PageContext constant.
+     *
+     * @param scopeName Can be "page", "request", "session", or "application".
+     * @return The constant representing the scope (ie. PageContext.*_SCOPE).
+     */
+    public static int getScope( String scopeName )
+    {
+        return scopes.get( scopeName.toLowerCase() );
+    }
+
+    /**
+     * @param out
+     * @param name TODO
+     * @param value TODO
+     */
+    public static void setAttribute( StringBuffer out, String name, String value )
+    {
+        if ( value != null )
+        {
+            out.append( " " ).append( name ).append( "='" ).append( value ).append( "'" );
+        }
+    }
+
+    public static Repository getRepository( PageContext pageContext, String key)
+        throws JspException
+    {
+        if ( key != null )
+        {
+            Repository repo = (Repository) pageContext.getAttribute( key );
+            if ( repo == null )
+            {
+                throw new JspException( "No repository on pageContext for key " + key );
+            }
+        }
+        return null; //Monitoring.getRepository();
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/AspectJMonitoringAutoProxyCreator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/AspectJMonitoringAutoProxyCreator.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/AspectJMonitoringAutoProxyCreator.java
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/AspectJMonitoringAutoProxyCreator.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.spring;
+
+import org.springframework.aop.aspectj.AspectJExpressionPointcut;
+
+/**
+ * Creates monitored proxies for beans that match an aspectJ expression.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class AspectJMonitoringAutoProxyCreator
+    extends PointcutMonitoringAutoProxyCreator
+{
+    /**
+     * Set the AspectJ expression to be used to select beans / methods to get monitored
+     */
+    public void setExpression( String expression )
+    {
+        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
+        pointcut.setExpression( expression );
+        setPointcut( pointcut );
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.spring;
+
+import org.aopalliance.aop.Advice;
+import org.apache.commons.monitoring.instrumentation.aop.MonitorNameExtractor;
+import org.apache.commons.monitoring.spring.MonitoringAdviceFactory.MonitoringConfigSource;
+import org.springframework.aop.TargetSource;
+import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
+
+/**
+ * Creates monitored proxies for beans that match a naming pattern.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class BeanNameMonitoringAutoProxyCreator
+    extends BeanNameAutoProxyCreator implements MonitoringConfigSource
+{
+    private String category;
+
+    private String subsystem;
+
+    private MonitorNameExtractor monitorNameExtractor;
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator#getAdvicesAndAdvisorsForBean(java.lang.Class,
+     * java.lang.String, org.springframework.aop.TargetSource)
+     */
+    @Override
+    protected Object[] getAdvicesAndAdvisorsForBean( Class beanClass, String beanName, TargetSource
targetSource )
+    {
+        if ( super.getAdvicesAndAdvisorsForBean( beanClass, beanName, targetSource ) != DO_NOT_PROXY
)
+        {
+            Advice advice = MonitoringAdviceFactory.getAdvice( this );
+            return new Object[] { advice };
+        }
+        return DO_NOT_PROXY;
+    }
+
+    /**
+     * @param category the category to set
+     */
+    public void setCategory( String category )
+    {
+        this.category = category;
+    }
+
+    /**
+     * @param subsystem the subsystem to set
+     */
+    public void setSubsystem( String subsystem )
+    {
+        this.subsystem = subsystem;
+    }
+
+    /**
+     * @param monitorNameExtractor the monitorNameExtractor to set
+     */
+    public void setMonitorNameExtractor( MonitorNameExtractor monitorNameExtractor )
+    {
+        this.monitorNameExtractor = monitorNameExtractor;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see org.apache.commons.monitoring.spring.MonitoringConfigSource#getCategory()
+     */
+    public String getCategory()
+    {
+        return category;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see org.apache.commons.monitoring.spring.MonitoringConfigSource#getSubsystem()
+     */
+    public String getSubsystem()
+    {
+        return subsystem;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see org.apache.commons.monitoring.spring.MonitoringConfigSource#getMonitorNameExtractor()
+     */
+    public MonitorNameExtractor getMonitorNameExtractor()
+    {
+        return monitorNameExtractor;
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringAdviceFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringAdviceFactory.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringAdviceFactory.java
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringAdviceFactory.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.spring;
+
+import org.aopalliance.aop.Advice;
+import org.apache.commons.monitoring.instrumentation.aop.AopaliancePerformanceInterceptor;
+import org.apache.commons.monitoring.instrumentation.aop.MonitorNameExtractor;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class MonitoringAdviceFactory
+{
+
+    public static Advice getAdvice( MonitoringConfigSource source )
+    {
+        AopaliancePerformanceInterceptor interceptor = new AopaliancePerformanceInterceptor();
+        if ( source.getCategory() != null )
+        {
+            interceptor.setCategory( source.getCategory() );
+        }
+        if ( source.getSubsystem() != null )
+        {
+            interceptor.setSubsystem( source.getSubsystem() );
+        }
+        if ( source.getMonitorNameExtractor() != null )
+        {
+            interceptor.setMonitorNameExtractor( source.getMonitorNameExtractor() );
+        }
+        return interceptor;
+    }
+
+    public interface MonitoringConfigSource
+    {
+        /**
+         * @return the category
+         */
+        public abstract String getCategory();
+
+        /**
+         * @return the subsystem
+         */
+        public abstract String getSubsystem();
+
+        /**
+         * @return the monitorNameExtractor
+         */
+        public abstract MonitorNameExtractor getMonitorNameExtractor();
+
+    }
+
+}

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringNamespaceHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringNamespaceHandler.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringNamespaceHandler.java
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringNamespaceHandler.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.spring;
+
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class MonitoringNamespaceHandler
+    extends NamespaceHandlerSupport
+{
+
+    /**
+     * {@inheritDoc}
+     * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
+     */
+    public void init()
+    {
+//        registerBeanDefinitionParser( "auto-proxy", new AutoProxyDefinitionParser());
+    }
+
+}

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.monitoring.spring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.aopalliance.aop.Advice;
+import org.apache.commons.monitoring.instrumentation.aop.MonitorNameExtractor;
+import org.apache.commons.monitoring.spring.MonitoringAdviceFactory.MonitoringConfigSource;
+import org.springframework.aop.Advisor;
+import org.springframework.aop.Pointcut;
+import org.springframework.aop.PointcutAdvisor;
+import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator;
+import org.springframework.aop.support.DefaultPointcutAdvisor;
+
+/**
+ * Creates monitored proxies for beans that match a pointcut.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class PointcutMonitoringAutoProxyCreator
+    extends AbstractAdvisorAutoProxyCreator
+    implements MonitoringConfigSource
+{
+    private String category;
+
+    private String subsystem;
+
+    private MonitorNameExtractor monitorNameExtractor;
+
+    private Pointcut pointcut;
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator#findCandidateAdvisors()
+     */
+    @Override
+    protected List<Advisor> findCandidateAdvisors()
+    {
+        List<Advisor> adivisors = new ArrayList<Advisor>( 1 );
+
+        PointcutAdvisor adivsor = createPointcutAdvisor( MonitoringAdviceFactory.getAdvice(
this ) );
+
+        adivisors.add( adivsor );
+        return adivisors;
+    }
+
+    /**
+     * @param interceptor
+     * @return
+     */
+    protected PointcutAdvisor createPointcutAdvisor( Advice advice )
+    {
+        return new DefaultPointcutAdvisor( pointcut, advice );
+    }
+
+    /**
+     * @param category the category to set
+     */
+    public void setCategory( String category )
+    {
+        this.category = category;
+    }
+
+    /**
+     * @param subsystem the subsystem to set
+     */
+    public void setSubsystem( String subsystem )
+    {
+        this.subsystem = subsystem;
+    }
+
+    /**
+     * @param monitorNameExtractor the monitorNameExtractor to set
+     */
+    public void setMonitorNameExtractor( MonitorNameExtractor monitorNameExtractor )
+    {
+        this.monitorNameExtractor = monitorNameExtractor;
+    }
+
+    /**
+     * @param pointcut the pointcut to set
+     */
+    public void setPointcut( Pointcut pointcut )
+    {
+        this.pointcut = pointcut;
+    }
+
+    /**
+     * @return the category
+     */
+    public String getCategory()
+    {
+        return category;
+    }
+
+    /**
+     * @return the subsystem
+     */
+    public String getSubsystem()
+    {
+        return subsystem;
+    }
+
+    /**
+     * @return the monitorNameExtractor
+     */
+    public MonitorNameExtractor getMonitorNameExtractor()
+    {
+        return monitorNameExtractor;
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.handlers
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.handlers?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.handlers
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.handlers
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+http\://commons.apache.org/monitoring = org.apache.commons.monitoring.spring.MonitoringNamespaceHandler
\ No newline at end of file

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.schemas
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.schemas?rev=721657&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.schemas
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/resources/META-INF/spring.schemas
Sat Nov 29 01:08:42 2008
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+http\://commons.apache.org/monitoring = monitoring.xsd
\ No newline at end of file



Mime
View raw message