incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1138159 - in /sling/trunk: bundles/engine/ bundles/engine/src/main/java/org/apache/sling/engine/impl/ bundles/engine/src/main/java/org/apache/sling/engine/jmx/ launchpad/builder/src/main/bundles/
Date Tue, 21 Jun 2011 20:09:37 GMT
Author: justin
Date: Tue Jun 21 20:09:37 2011
New Revision: 1138159

URL: http://svn.apache.org/viewvc?rev=1138159&view=rev
Log:
SLING-1476 - adding initial stats MBean to engine bundle

Added:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessor.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessorMBean.java
Modified:
    sling/trunk/bundles/engine/pom.xml
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
    sling/trunk/launchpad/builder/src/main/bundles/list.xml

Modified: sling/trunk/bundles/engine/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/pom.xml?rev=1138159&r1=1138158&r2=1138159&view=diff
==============================================================================
--- sling/trunk/bundles/engine/pom.xml (original)
+++ sling/trunk/bundles/engine/pom.xml Tue Jun 21 20:09:37 2011
@@ -61,7 +61,8 @@
                     <instructions>
                         <Export-Package>
                             org.apache.sling.engine;version=2.1,
-                            org.apache.sling.engine.servlets;version=2.0.6
+                            org.apache.sling.engine.servlets;version=2.0.6,
+                            org.apache.sling.engine.jmx;version=1.0
                         </Export-Package>
                         <Private-Package>
                             org.apache.sling.engine.impl,
@@ -69,7 +70,8 @@
                         </Private-Package>
                         <Import-Package>
                             org.osgi.service.useradmin;
-                            javax.portlet;resolution:=optional,
+                            javax.portlet;
+                            org.apache.commons.math.*;resolution:=optional,
                             *
                         </Import-Package>
                         <Embed-Dependency>
@@ -141,6 +143,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math</artifactId>
+            <version>2.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=1138159&r1=1138158&r2=1138159&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Tue Jun 21 20:09:37 2011
@@ -56,6 +56,8 @@ import org.apache.sling.engine.impl.log.
 import org.apache.sling.engine.impl.parameters.ParameterSupport;
 import org.apache.sling.engine.impl.request.RequestData;
 import org.apache.sling.engine.impl.request.RequestHistoryConsolePlugin;
+import org.apache.sling.engine.jmx.RequestProcessorMBean;
+import org.apache.sling.engine.jmx.RequestProcessor;
 import org.apache.sling.engine.servlets.ErrorHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -341,6 +343,17 @@ public class SlingMainServlet extends Ge
                 "Unable to register web console request recorder plugin.", t);
         }
 
+        try {
+            Dictionary<String, String> mbeanProps = new Hashtable<String, String>();
+            mbeanProps.put("jmx.objectname", "org.apache.sling:type=engine,service=RequestProcessor");
+
+            RequestProcessor mbean = new RequestProcessor();
+            bundleContext.registerService(RequestProcessorMBean.class.getName(), mbean, mbeanProps);
+            requestProcessor.setMBean(mbean);
+        } catch (Throwable t) {
+            log.debug("Unable to register mbean");
+        }
+
         // provide the SlingRequestProcessor service
         Hashtable<String, String> srpProps = new Hashtable<String, String>();
         srpProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java?rev=1138159&r1=1138158&r2=1138159&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
Tue Jun 21 20:09:37 2011
@@ -57,6 +57,7 @@ import org.apache.sling.engine.impl.log.
 import org.apache.sling.engine.impl.request.ContentData;
 import org.apache.sling.engine.impl.request.RequestData;
 import org.apache.sling.engine.impl.request.RequestHistoryConsolePlugin;
+import org.apache.sling.engine.jmx.RequestProcessor;
 import org.apache.sling.engine.servlets.ErrorHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -78,6 +79,8 @@ public class SlingRequestProcessorImpl i
 
     private ServletFilterManager filterManager;
 
+    private RequestProcessor mbean;
+
     // ---------- helper setters
 
     void setServerInfo(final String serverInfo) {
@@ -118,6 +121,10 @@ public class SlingRequestProcessorImpl i
         this.filterManager = filterManager;
     }
 
+    void setMBean(final RequestProcessor mbean) {
+        this.mbean = mbean;
+    }
+
     // ---------- SlingRequestProcessor interface
 
     public void processRequest(final HttpServletRequest servletRequest,
@@ -138,6 +145,8 @@ public class SlingRequestProcessorImpl i
             requestLogger.logRequestEntry(request, response);
         }
 
+        long startTimestamp = System.currentTimeMillis();
+
         try {
             final ServletResolver sr = this.servletResolver;
 
@@ -233,6 +242,10 @@ public class SlingRequestProcessorImpl i
             handleError(t, request, response);
 
         } finally {
+            long elapsed = System.currentTimeMillis() - startTimestamp;
+            if (mbean != null) {
+                mbean.addRequestDuration(elapsed);
+            }
 
             // request exit log
             if (requestLogger != null) {

Added: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessor.java?rev=1138159&view=auto
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessor.java
(added)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessor.java
Tue Jun 21 20:09:37 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.sling.engine.jmx;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.math.stat.descriptive.SynchronizedSummaryStatistics;
+
+/**
+ * This is the implementation of the management interface for the RequestProcessor.
+ */
+public class RequestProcessor implements RequestProcessorMBean {
+
+    private final SynchronizedSummaryStatistics durationStatistics;
+    
+    private final ExecutorService operationExecutor;
+
+    public RequestProcessor() {
+        this.durationStatistics = new SynchronizedSummaryStatistics();
+        this.operationExecutor = Executors.newSingleThreadExecutor();
+    }
+
+    public void addRequestDuration(final long value) {
+        operationExecutor.execute(new Runnable() {
+
+            public void run() {
+                durationStatistics.addValue(value);
+            }
+        });
+    }
+
+    public long getCount() {
+        return durationStatistics.getN();
+    }
+    
+    public double getMeanRequestDuration() {
+        return durationStatistics.getMean();
+    }
+    
+    public void resetStatistics() {
+        operationExecutor.execute(new Runnable() {
+            
+            public void run() {
+                durationStatistics.clear();
+                
+            }
+        });
+    }
+
+}

Added: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessorMBean.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessorMBean.java?rev=1138159&view=auto
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessorMBean.java
(added)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/jmx/RequestProcessorMBean.java
Tue Jun 21 20:09:37 2011
@@ -0,0 +1,31 @@
+/*
+ * 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.sling.engine.jmx;
+
+/**
+ * This is the management interface for the SlingRequestProcessor.
+ *
+ */
+public interface RequestProcessorMBean {
+
+    long getCount();
+    
+    double getMeanRequestDuration();
+    
+    void resetStatistics();
+
+}

Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=1138159&r1=1138158&r2=1138159&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Tue Jun 21 20:09:37 2011
@@ -23,6 +23,11 @@
             <version>2.5</version>
         </bundle>
         <bundle>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math</artifactId>
+            <version>2.2</version>
+        </bundle>
+        <bundle>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.osgi</artifactId>
             <version>2.0.6</version>
@@ -71,7 +76,7 @@
         <bundle>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.engine</artifactId>
-            <version>2.2.2</version>
+            <version>2.2.5-SNAPSHOT</version>
         </bundle>
         <bundle>
             <groupId>org.apache.sling</groupId>



Mime
View raw message