cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r794104 - in /cocoon/cocoon3/trunk: cocoon-monitoring/ cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/ cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/ cocoon-monitoring/src/main/java/org/apache/cocoon/monit...
Date Tue, 14 Jul 2009 22:44:29 GMT
Author: reinhard
Date: Tue Jul 14 22:44:28 2009
New Revision: 794104

URL: http://svn.apache.org/viewvc?rev=794104&view=rev
Log:
COCOON3-38 
Monitoring of Servlet-Services, their connections and mount-paths.

Added:
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/Log4JReconfigurator.java
      - copied, changed from r780620, cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/Log4JReconfigurator.java
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/LoggingConfigurationResetter.java
      - copied, changed from r780620, cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/LoggingConfigurationResetter.java
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java
  (with props)
Removed:
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/Log4JReconfigurator.java
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/LoggingConfigurationResetter.java
Modified:
    cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
    cocoon/cocoon3/trunk/parent/pom.xml

Modified: cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml?rev=794104&r1=794103&r2=794104&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml Tue Jul 14 22:44:28 2009
@@ -44,6 +44,14 @@
       <artifactId>cocoon-spring-configurator</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-servlet-service-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
     </dependency>

Copied: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/Log4JReconfigurator.java
(from r780620, cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/Log4JReconfigurator.java)
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/Log4JReconfigurator.java?p2=cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/Log4JReconfigurator.java&p1=cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/Log4JReconfigurator.java&r1=780620&r2=794104&rev=794104&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/Log4JReconfigurator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/Log4JReconfigurator.java
Tue Jul 14 22:44:28 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.monitoring;
+package org.apache.cocoon.monitoring.log4j;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -53,7 +53,7 @@
 /**
  * This is a JMX MBean class that expose methods for log4j configuration.
  */
-@ManagedResource
+@ManagedResource(objectName = "org.apache.cocoon.monitoring:group=Log4J,name=Log4JReconfigurator")
 public class Log4JReconfigurator {
 
     private static final String[] EXTENSIONS = new String[] { "xml", "properties" };

Copied: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/LoggingConfigurationResetter.java
(from r780620, cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/LoggingConfigurationResetter.java)
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/LoggingConfigurationResetter.java?p2=cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/LoggingConfigurationResetter.java&p1=cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/LoggingConfigurationResetter.java&r1=780620&r2=794104&rev=794104&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/LoggingConfigurationResetter.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/log4j/LoggingConfigurationResetter.java
Tue Jul 14 22:44:28 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.monitoring;
+package org.apache.cocoon.monitoring.log4j;
 
 import java.util.Timer;
 import java.util.TimerTask;

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java?rev=794104&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java
Tue Jul 14 22:44:28 2009
@@ -0,0 +1,144 @@
+/*
+ * 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.cocoon.monitoring.servletservice;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+import org.apache.cocoon.servletservice.ServletServiceContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.aop.framework.Advised;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+/**
+ * JMX MBean class that expose base information about Servlet-Services.
+ */
+@ManagedResource
+public class ServletServiceMonitor {
+
+    private final Log logger = LogFactory.getLog(this.getClass());
+    private final Servlet servlet;
+
+    public ServletServiceMonitor(Servlet servlet) {
+        this.servlet = servlet;
+    }
+
+    /**
+     * Returns all ServletService init parameters, excluding null parameters.
+     *
+     * @return all ServletService init parameters
+     */
+    @ManagedAttribute(description = "Returns all ServletService init parameters")
+    public String[] getServiceServletInitParameters() {
+        ServletConfig config = this.servlet.getServletConfig();
+        @SuppressWarnings("unchecked")
+        Enumeration<String> initParameterNames = config.getInitParameterNames();
+        List<String> result = new ArrayList<String>();
+
+        while (initParameterNames.hasMoreElements()) {
+            String name = initParameterNames.nextElement();
+            String parameter = config.getInitParameter(name);
+            if (parameter != null) { // omit null parameters
+                result.add(name + " = " + parameter);
+            }
+        }
+
+        return result.toArray(new String[] {});
+    }
+
+    /**
+     * Returns list of connections for this Servlet-Service.
+     *
+     * @param servletServiceName
+     * @return <code>String</code> array of connections for this Servlet-Service
+     */
+    /*
+     * TODO This method uses a private accessor to access the connections field of the
+     * ServletServiceContext. The servlet-service-fw-impl > 1.2.0 will expose them.
+     */
+    @SuppressWarnings("unchecked")
+    @ManagedAttribute(description = "Returns list of connections for this Servlet-Service")
+    public final String[] getServletServiceConnections() {
+        ServletContext servletContext = this.servlet.getServletConfig().getServletContext();
+        ServletServiceContext servletServiceContext = (ServletServiceContext) servletContext;
+
+        Map<String, String> servletServiceConnections = null;
+        try {
+            Field connectionsField = servletServiceContext.getClass().getDeclaredField("connectionServiceNames");
+            connectionsField.setAccessible(true);
+            servletServiceConnections = (Map<String, String>) connectionsField.get(unpackProxy(servletServiceContext));
+        } catch (Exception e) {
+            this.logger.warn("Can't access the connections field of " + servletContext +
".", e);
+        }
+
+        if (servletServiceConnections != null) {
+            String connections[] = new String[servletServiceConnections.size()];
+            int i = 0;
+            for (String key : servletServiceConnections.keySet()) {
+                connections[i] = key + " = " + servletServiceConnections.get(key);
+                i++;
+            }
+            return connections;
+        } else {
+            return new String[] {};
+        }
+    }
+
+    /**
+     * Returns information about this Servlet-Service, such as author, version, and copyright.
+     *
+     * @param servletServiceName
+     * @return information about this Servlet-Service
+     */
+    @ManagedAttribute(description = "Returns information about this Servlet-Service")
+    public final String getServletServiceInfo() {
+        return this.servlet.getServletInfo();
+    }
+
+    /**
+     * Get Servlet-Services month path.
+     *
+     * @return month path
+     */
+    @ManagedAttribute(description = "Returns list of registered Servlet-Services with their
month paths")
+    public final String getServletServiceMountPaths() {
+        ServletContext servletContext = this.servlet.getServletConfig().getServletContext();
+        ServletServiceContext context = (ServletServiceContext) servletContext;
+        return context.getMountPath();
+    }
+
+    @SuppressWarnings("unchecked")
+    private static <T> T unpackProxy(T proxy) throws Exception {
+        if (proxy instanceof Advised) {
+            Advised advised = (Advised) proxy;
+            return (T) advised.getTargetSource().getTarget();
+        }
+
+        return proxy;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java?rev=794104&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java
Tue Jul 14 22:44:28 2009
@@ -0,0 +1,92 @@
+/*
+ * 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.cocoon.monitoring.servletservice;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+import org.apache.cocoon.servletservice.ServletServiceContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.jmx.export.MBeanExporter;
+
+public class ServletServiceMonitorInitializer {
+
+    private final Log logger = LogFactory.getLog(this.getClass());
+
+    public ServletServiceMonitorInitializer(Map<String, Servlet> servlets, MBeanExporter
exporter) {
+        List<String> servletNames = new ArrayList<String>();
+        for (Servlet servlet : servlets.values()) {
+            ServletConfig servletConfig = servlet.getServletConfig();
+
+            // get only ServletServices servlets
+            ServletContext servletContext = servletConfig.getServletContext();
+            if (!(servletContext instanceof ServletServiceContext)) {
+                break;
+            }
+
+            ServletServiceContext servletServiceContext = (ServletServiceContext) servletContext;
+            String servletName = servletConfig.getServletName();
+            ObjectName name = null;
+            String stringName = "org.apache.cocoon.monitoring:group=ServletServices,name="
+ servletName + " ["
+                    + this.getMountPath(servletServiceContext) + "]";
+            try {
+                name = new ObjectName(stringName);
+            } catch (MalformedObjectNameException e) {
+                String message = "The string passed as a parameter does not have the right
format.";
+                this.logger.error(message, e);
+                throw new RuntimeException(message, e);
+            } catch (NullPointerException e) {
+                String message = "Should never happened. Value of name parameter always is
different than null.";
+                this.logger.fatal(message, e);
+                throw new RuntimeException(message, e);
+            }
+
+            if (name == null) {
+                break;
+            }
+
+            ServletServiceMonitor serviceServletMonitor = new ServletServiceMonitor(servlet);
+            if (!servletNames.contains(stringName)) {
+                exporter.registerManagedResource(serviceServletMonitor, name);
+                servletNames.add(stringName);
+            }
+        }
+    }
+
+    private String getMountPath(ServletServiceContext servletServiceContext) {
+        String mountPath = servletServiceContext.getMountPath();
+        if (mountPath != null && !mountPath.startsWith("/")) {
+            return "/" + mountPath;
+        }
+
+        if (mountPath == null) {
+            return "not mounted";
+        }
+
+        return mountPath;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/servletservice/ServletServiceMonitorInitializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml?rev=794104&r1=794103&r2=794104&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
(original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
Tue Jul 14 22:44:28 2009
@@ -19,7 +19,9 @@
  -->
 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+  xmlns:configurator="http://cocoon.apache.org/schema/configurator"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+                      http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.xsd">
 
   <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
     <property name="assembler" ref="org.apache.cocoon.monitoring.assembler" />
@@ -27,9 +29,6 @@
     <property name="autodetect" value="true" />
   </bean>
 
-  <bean id="org.apache.cocoon.monitoring.jmxAttributeSource"
-    class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
-
   <bean id="org.apache.cocoon.monitoring.assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
     <property name="attributeSource" ref="org.apache.cocoon.monitoring.jmxAttributeSource"
/>
   </bean>
@@ -38,6 +37,20 @@
     <property name="attributeSource" ref="org.apache.cocoon.monitoring.jmxAttributeSource"
/>
   </bean>
   
-  <bean id="org.apache.cocoon.monitoring.Log4JReconfigurator"
-    class="org.apache.cocoon.monitoring.Log4JReconfigurator" scope="singleton" />
+  <bean id="org.apache.cocoon.monitoring.jmxAttributeSource"
+    class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
+  
+  <bean id="org.apache.cocoon.monitoring.log4j.Log4JReconfigurator"
+    class="org.apache.cocoon.monitoring.log4j.Log4JReconfigurator" scope="singleton">
+    <property name="settings" ref="org.apache.cocoon.configuration.Settings" />
+  </bean>
+
+  <bean id="org.apache.cocoon.monitoring.servletservice.ServletServiceMonitorInitializer"
+    class="org.apache.cocoon.monitoring.servletservice.ServletServiceMonitorInitializer"
>
+    <constructor-arg index="0">
+      <configurator:bean-map type="javax.servlet.Servlet" />
+    </constructor-arg>
+    <constructor-arg ref="exporter" index="1"/>
+  </bean>
+
 </beans>

Modified: cocoon/cocoon3/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/parent/pom.xml?rev=794104&r1=794103&r2=794104&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/parent/pom.xml (original)
+++ cocoon/cocoon3/trunk/parent/pom.xml Tue Jul 14 22:44:28 2009
@@ -113,6 +113,7 @@
       <dependency>
         <groupId>org.apache.cocoon</groupId>
         <artifactId>cocoon-servlet-service-impl</artifactId>
+        <!-- After upgrading to 1.2.1 fix the TODO in ServiceServletMonitor -->
         <version>1.2.0</version>
       </dependency>
       <dependency>



Mime
View raw message