dev@glassfish.java.net

[Fwd: svn commit: r22137 - trunk/v3/web/admin: . src/main/java/org/glassfish/web/admin/monitor/connector src/main/java/org/glassfish/web/admin/monitor/te...]

From: Sahoo <sahoo_at_sun.com>
Date: Fri, 29 Aug 2008 01:19:08 +0530

Hi pa100654,

Can you explain why you overwrote the changes I had done to
web/admin/pom.xml. Immediately after cleaning up nearly 100 pom.xmls, I
sent a note to dev alias asking people to configure OSGi metadata using
osgi.bundle file. Why did you decide to configure the plugin in pom.xml
instead of using osgi.bundle file?

Thanks,
Sahoo

attached mail follows:



Author: pa100654
Date: 2008-08-26 23:29:58+0000
New Revision: 22137

Added:
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/connector/
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/connector/BootstrapWebMonitor.java
Modified:
   trunk/v3/web/admin/pom.xml
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JVMMemoryStatsTelemetry.java
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JspStatsTelemetry.java
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ServletStatsTelemetry.java
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/SessionStatsTelemetry.java
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ThreadPoolTelemetry.java
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebMonitorStartup.java
   trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebRequestTelemetry.java

Log:
Issue: 5648
Monitoring should be active only when
1) monitoring level is turned on
2) when web container/Grizzly is up
3) Also should not listen to the Probe infrastructure thus not incurring the overhead.

QL passed.


Modified: trunk/v3/web/admin/pom.xml
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/pom.xml?view=diff&rev=22137&p1=trunk/v3/web/admin/pom.xml&p2=trunk/v3/web/admin/pom.xml&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/pom.xml (original)
+++ trunk/v3/web/admin/pom.xml 2008-08-26 23:29:58+0000
@@ -59,6 +59,58 @@
         </developer>
     </developers>
     <build>
+ <plugins>
+ <!-- Configure maven-bundle-plugin to generate OSGi manifest.
+ Please note: we use the manifest goal only and not the bundle goal.
+ The bundle goal can lead to very surprising results if the
+ package names are not correctly specified. So,
+ we use the jar plugin to generate the jar.-->
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <!-- Enable the plugin for hk2-jar packaging type -->
+ <supportedProjectTypes>
+ <supportedProjectType>hk2-jar</supportedProjectType>
+ <supportedProjectType>jar</supportedProjectType>
+ <supportedProjectType>bundle</supportedProjectType>
+ </supportedProjectTypes>
+ <instructions>
+ <!-- _include does not work. See Felix-620.
+ <_include>osgi.bundle</_include>
+ -->
+ <Export-Package>
+ org.glassfish.web.admin.cli,
+ org.glassfish.web.admin.monitor,
+ org.glassfish.web.admin.monitor.telemetry
+ </Export-Package>
+ <Bundle-Activator>
+ org.glassfish.web.admin.monitor.telemetry.WebMonitorStartup
+ </Bundle-Activator>
+ </instructions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>bundle-manifest</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.sun.enterprise</groupId>
+ <artifactId>hk2-maven-plugin</artifactId>
+ <version>${hk2.plugin.version}</version>
+ <configuration>
+ <archive>
+ <!-- Use the manifest.mf produced by maven-bundle-plugin:manifest -->
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
         <resources>
             <resource>
                 <directory>src/main/java</directory>
@@ -77,7 +129,6 @@
     </build>
     
     <dependencies>
-
          <dependency>
             <groupId>org.glassfish.flashlight</groupId>
             <artifactId>flashlight-framework</artifactId>
@@ -128,6 +179,12 @@
             <artifactId>amx-api</artifactId>
             <version>10.0-SNAPSHOT</version>
         </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi_R4_core</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
     </dependencies>
 </project>
 

Added: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/connector/BootstrapWebMonitor.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/connector/BootstrapWebMonitor.java?view=auto&rev=22137
==============================================================================
--- (empty file)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/connector/BootstrapWebMonitor.java 2008-08-26 23:29:58+0000
@@ -0,0 +1,62 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+package org.glassfish.web.admin.monitor.connector;
+
+import org.glassfish.api.Startup;
+import org.jvnet.hk2.annotations.Scoped;
+import org.jvnet.hk2.annotations.Service;
+import org.jvnet.hk2.component.PostConstruct;
+import org.jvnet.hk2.component.Singleton;
+
+/**
+ * @author Prashanth Abbagani
+ * Date: Aug 15, 2008
+ */
+_at_Service
+_at_Scoped(Singleton.class)
+public class BootstrapWebMonitor
+ implements Startup, PostConstruct {
+
+ public Lifecycle getLifecycle() {
+ // This service stays running for the life of the app server, hence SERVER.
+ //System.out.println("[Monitor]In the Bootstrap Web Monitor Lifecycle ************");
+ return Lifecycle.SERVER;
+ }
+
+ public void postConstruct() {
+ //System.out.println("[Monitor]In the Bootstrap Web Monitor post construct ************");
+ }
+}

Modified: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JVMMemoryStatsTelemetry.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JVMMemoryStatsTelemetry.java?view=diff&rev=22137&p1=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JVMMemoryStatsTelemetry.java&p2=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JVMMemoryStatsTelemetry.java&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JVMMemoryStatsTelemetry.java (original)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JVMMemoryStatsTelemetry.java 2008-08-26 23:29:58+0000
@@ -57,13 +57,9 @@
     private MemoryUsage heapUsage;
     private MemoryUsage nonheapUsage;
     private MemoryMXBean bean;
- private static final String BYTE_UNITS = "monitor.stats.byte_units";
- private static final StringManager localStrMgr =
- StringManager.getManager(JVMMemoryStatsTelemetry.class);
-
     private Counter commitHeapSize = CounterFactory.createCount();
- private boolean jvmMonitoringEnabled;
     private Logger logger;
+ private boolean isEnabled = true;
     
     /** Creates a new instance of JVMMemoryStatsTelemetry */
     public JVMMemoryStatsTelemetry(TreeNode server, boolean jvmMonitoringEnabled, Logger logger) {
@@ -114,10 +110,10 @@
         }
     }
     
- public void enableMonitoring(boolean isEnabled) {
- if (isEnabled != jvmMonitoringEnabled) {
- jvmMonitoringEnabled = isEnabled;
- jvmNode.setEnabled(jvmMonitoringEnabled);
+ public void enableMonitoring(boolean flag) {
+ if (isEnabled != flag) {
+ isEnabled = flag;
+ jvmNode.setEnabled(flag);
         }
     }
     
@@ -125,6 +121,10 @@
         commitHeapSize.setCount(heapUsage.getCommitted());
         return commitHeapSize;
     }
+
+ public boolean isEnabled() {
+ return isEnabled;
+ }
     
     /*
     public Counter getCommittedNonHeapSize() {

Modified: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JspStatsTelemetry.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JspStatsTelemetry.java?view=diff&rev=22137&p1=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JspStatsTelemetry.java&p2=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JspStatsTelemetry.java&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JspStatsTelemetry.java (original)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/JspStatsTelemetry.java 2008-08-26 23:29:58+0000
@@ -60,9 +60,12 @@
     private String moduleName;
     private String vsName;
     private Logger logger;
+ private boolean isEnabled = true;
+ private TreeNode jspNode = null;
     
     public JspStatsTelemetry(TreeNode parent, String moduleName, String vsName,
            boolean webMonitoringEnabled, Logger logger) {
+ jspNode = parent;
         this.logger = logger;
         this.moduleName = moduleName;
         this.vsName = vsName;
@@ -79,15 +82,21 @@
     private Counter maxJspsLoadedCount = CounterFactory.createCount();
     private Counter totalJspsLoadedCount = CounterFactory.createCount();
 
- public void enableMonitoring(boolean isEnable) {
+ public void enableMonitoring(boolean flag) {
         //loop through the handles for this node and enable/disable the listeners
         //delegate the request to the child nodes
+ if (isEnabled != flag) {
+ for (ProbeClientMethodHandle handle : handles) {
+ if (flag == true)
+ handle.enable();
+ else
+ handle.disable();
+ }
+ jspNode.setEnabled(flag);
+ isEnabled = flag;
+ }
     }
     
- public void enableMonitoringForSubElements(boolean isEnable) {
- //loop through the children and enable/disable all
- }
-
     @ProbeListener("web:jsp::jspLoadedEvent")
     public void jspLoadedEvent(
         @ProbeParam("jsp") Servlet jsp,
@@ -133,7 +142,11 @@
             webMonitoringEnabled = isEnabled;
             tuneProbeListenerHandles(webMonitoringEnabled);
         }
- }
+ }
+
+ public boolean isEnabled() {
+ return isEnabled;
+ }
     
     private void tuneProbeListenerHandles(boolean shouldEnable) {
         //disable handles

Modified: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ServletStatsTelemetry.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ServletStatsTelemetry.java?view=diff&rev=22137&p1=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ServletStatsTelemetry.java&p2=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ServletStatsTelemetry.java&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ServletStatsTelemetry.java (original)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ServletStatsTelemetry.java 2008-08-26 23:29:58+0000
@@ -58,10 +58,13 @@
     private boolean webMonitoringEnabled;
     private String moduleName;
     private String vsName;
- private Logger logger;
+ private Logger logger;
+ private boolean isEnabled = true;
+ private TreeNode servletNode = null;
     
     public ServletStatsTelemetry(TreeNode parent, String moduleName, String vsName,
                                     boolean webMonitoringEnabled, Logger logger) {
+ servletNode = parent;
         this.logger = logger;
         this.moduleName = moduleName;
         this.vsName = vsName;
@@ -78,15 +81,21 @@
     private Counter maxServletsLoadedCount = CounterFactory.createCount();
     private Counter totalServletsLoadedCount = CounterFactory.createCount();
 
- public void enableMonitoring(boolean isEnable) {
+ public void enableMonitoring(boolean flag) {
         //loop through the handles for this node and enable/disable the listeners
         //delegate the request to the child nodes
+ if (isEnabled != flag) {
+ for (ProbeClientMethodHandle handle : handles) {
+ if (flag == true)
+ handle.enable();
+ else
+ handle.disable();
+ }
+ servletNode.setEnabled(flag);
+ isEnabled = flag;
+ }
     }
     
- public void enableMonitoringForSubElements(boolean isEnable) {
- //loop through the children and enable/disable all
- }
-
     @ProbeListener("web:servlet::servletInitializedEvent")
     public void servletInitializedEvent(
                     @ProbeParam("servlet") Servlet servlet,
@@ -135,7 +144,11 @@
             webMonitoringEnabled = isEnabled;
             tuneProbeListenerHandles(webMonitoringEnabled);
         }
- }
+ }
+
+ public boolean isEnabled() {
+ return isEnabled;
+ }
     
     private void tuneProbeListenerHandles(boolean shouldEnable) {
         //disable handles

Modified: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/SessionStatsTelemetry.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/SessionStatsTelemetry.java?view=diff&rev=22137&p1=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/SessionStatsTelemetry.java&p2=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/SessionStatsTelemetry.java&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/SessionStatsTelemetry.java (original)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/SessionStatsTelemetry.java 2008-08-26 23:29:58+0000
@@ -58,16 +58,17 @@
 public class SessionStatsTelemetry{
     private String moduleName;
     private String vsName;
- private TreeNode sessionTM;
- private TreeNode sessionChildren[];
+ private TreeNode sessionNode = null;
 
     private Logger logger;
     //Logger logger = LogDomains.getLogger(this.getClass().getName());
     private Collection<ProbeClientMethodHandle> handles;
     private boolean webMonitoringEnabled;
+ private boolean isEnabled = true;
     
     public SessionStatsTelemetry(TreeNode parent, String moduleName, String vsName,
                                     boolean webMonitoringEnabled, Logger logger) {
+ sessionNode = parent;
         this.logger = logger;
         this.moduleName = moduleName;
         this.vsName = vsName;
@@ -100,13 +101,19 @@
     private Counter activatedSessionsTotal = CounterFactory.createCount();
     
 
- public void enableMonitoring(boolean isEnable) {
+ public void enableMonitoring(boolean flag) {
         //loop through the handles for this node and enable/disable the listeners
         //delegate the request to the child nodes
- }
-
- public void enableMonitoringForSubElements(boolean isEnable) {
- //loop through the children and enable/disable all
+ if (isEnabled != flag) {
+ for (ProbeClientMethodHandle handle : handles) {
+ if (flag == true)
+ handle.enable();
+ else
+ handle.disable();
+ }
+ sessionNode.setEnabled(flag);
+ isEnabled = flag;
+ }
     }
     
     @ProbeListener("web:session::sessionCreatedEvent")
@@ -262,6 +269,10 @@
         activeSessionsCurrent.decrement();
         passivatedSessionsTotal.increment();
     }
+
+ public boolean isEnabled() {
+ return isEnabled;
+ }
     
     private void incrementActiveSessionsCurrent() {
         activeSessionsCurrent.increment();

Modified: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ThreadPoolTelemetry.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ThreadPoolTelemetry.java?view=diff&rev=22137&p1=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ThreadPoolTelemetry.java&p2=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ThreadPoolTelemetry.java&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ThreadPoolTelemetry.java (original)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/ThreadPoolTelemetry.java 2008-08-26 23:29:58+0000
@@ -38,14 +38,12 @@
 import java.util.Collection;
 import org.glassfish.flashlight.client.ProbeClientMethodHandle;
 import org.glassfish.flashlight.statistics.*;
-import org.glassfish.flashlight.statistics.factory.CounterFactory;
 import org.glassfish.flashlight.datatree.TreeNode;
 import org.glassfish.flashlight.datatree.factory.*;
 import org.glassfish.flashlight.client.ProbeListener;
 import org.glassfish.flashlight.provider.annotations.ProbeParam;
 import org.glassfish.flashlight.provider.annotations.*;
 import java.util.logging.Logger;
-import java.util.logging.Level;
 
 /**
  * Provides the monitoring data at the Web container level
@@ -56,7 +54,8 @@
     private TreeNode threadpoolNode;
     private Collection<ProbeClientMethodHandle> handles;
     private boolean threadpoolMonitoringEnabled;
- private Logger logger;
+ private Logger logger;
+ private boolean isEnabled = true;
 
 
     /* We would like to measure the following */
@@ -129,37 +128,22 @@
     
     public void setProbeListenerHandles(Collection<ProbeClientMethodHandle> handles) {
         this.handles = handles;
- if (!threadpoolMonitoringEnabled){
- //disable handles
- tuneProbeListenerHandles(threadpoolMonitoringEnabled);
- }
     }
     
- public void enableProbeListenerHandles(boolean isEnabled) {
- if (isEnabled != threadpoolMonitoringEnabled) {
- threadpoolMonitoringEnabled = isEnabled;
- tuneProbeListenerHandles(threadpoolMonitoringEnabled);
- }
+ public boolean isEnabled() {
+ return isEnabled;
     }
     
- private void tuneProbeListenerHandles(boolean shouldEnable) {
- //disable handles
+ public void enableMonitoring(boolean flag) {
+ //loop through the handles for this node and enable/disable the listeners
+ //delegate the request to the child nodes
         for (ProbeClientMethodHandle handle : handles) {
- if (shouldEnable)
+ if (flag == true)
                 handle.enable();
             else
                 handle.disable();
         }
-
- }
-
- public void enableMonitoring(boolean isEnable) {
- //loop through the handles for this node and enable/disable the listeners
- //delegate the request to the child nodes
+ //threadpoolNode.setEnabled(flag);
+ isEnabled = flag;
     }
-
- public void enableMonitoringForSubElements(boolean isEnable) {
- //loop through the children and enable/disable all
- }
-
 }

Modified: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebMonitorStartup.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebMonitorStartup.java?view=diff&rev=22137&p1=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebMonitorStartup.java&p2=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebMonitorStartup.java&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebMonitorStartup.java (original)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebMonitorStartup.java 2008-08-26 23:29:58+0000
@@ -9,7 +9,7 @@
  * may not use this file except in compliance with the License. You can obtain
  * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
  * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
- * language governing permissions and limitations under the License.
+ * language governing permissions and limitations udfnder the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
@@ -38,10 +38,16 @@
 import org.jvnet.hk2.annotations.Inject;
 import org.jvnet.hk2.annotations.Scoped;
 import org.jvnet.hk2.annotations.Service;
-import org.jvnet.hk2.component.PostConstruct;
 import org.jvnet.hk2.component.Singleton;
+/*
+import org.jvnet.hk2.component.PostConstruct;
 import org.glassfish.api.Startup;
+ */
 import org.glassfish.api.Startup.Lifecycle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
 import org.glassfish.flashlight.provider.ProbeProviderListener;
 import org.glassfish.flashlight.provider.ProbeProviderEventManager;
 import org.glassfish.flashlight.client.ProbeClientMediator;
@@ -59,6 +65,8 @@
 import org.jvnet.hk2.config.ConfigListener;
 import java.util.logging.Logger;
 import java.util.logging.Level;
+import org.osgi.framework.Bundle;
+import org.glassfish.internal.api.Globals;
 
 /**
  * Provides for bootstarpping web telemetry during startup and
@@ -66,10 +74,15 @@
  *
  * @author Sreenivas Munnangi
  */
-_at_Service
-_at_Scoped(Singleton.class)
-public class WebMonitorStartup implements
- Startup, PostConstruct, ProbeProviderListener, ConfigListener {
+//_at_Service
+//_at_Scoped(Singleton.class)
+public class WebMonitorStartup implements //Startup, PostConstruct,
+ BundleActivator, BundleListener, ProbeProviderListener, ConfigListener {
+ private boolean requestProviderRegistered = false;
+ private boolean servletProviderRegistered = false;
+ private boolean jspProviderRegistered = false;
+ private boolean sessionProviderRegistered = false;
+ private boolean probeProviderListenerRegistered = false;
     
     // default values are set to true which can be changed thru
     // GUI or set command
@@ -77,17 +90,24 @@
     private boolean httpServiceMonitoringEnabled = true;
     private boolean jvmMonitoringEnabled = true;
     private boolean webMonitoringEnabled = true;
+ private boolean isWebTreeBuilt = false;
 
- @Inject
- private ProbeProviderEventManager ppem;
- @Inject
- private ProbeClientMediator pcm;
+ //_at_Inject
+ private ProbeProviderEventManager ppem =
+ Globals.getDefaultHabitat().getComponent(ProbeProviderEventManager.class);
+ //_at_Inject
+ private ProbeClientMediator pcm =
+ Globals.getDefaultHabitat().getComponent(ProbeClientMediator.class);;
+
+ //_at_Inject
+ private ModuleMonitoringLevels mml =
+ Globals.getDefaultHabitat().getComponent(ModuleMonitoringLevels.class);
 
- @Inject
- private ModuleMonitoringLevels mml;
-
- @Inject
- Logger logger;
+ private boolean grizzlyModuleLoaded = false;
+ private boolean webContainerLoaded = false;
+
+ //_at_Inject
+ Logger logger = Globals.getDefaultHabitat().getComponent(Logger.class);
 
     private WebRequestTelemetry webRequestTM = null;
     private WebModuleTelemetry moduleTM = null;
@@ -100,10 +120,11 @@
     private ThreadPoolTelemetry threadPoolTM = null;
     private JVMMemoryStatsTelemetry jvmMemoryTM = null;
     
- @Inject
- private static Domain domain;
- @Inject
- private MonitoringRuntimeDataRegistry mrdr;
+ //_at_Inject
+ private static Domain domain = Globals.getDefaultHabitat().getComponent(Domain.class);
+ //_at_Inject
+ private MonitoringRuntimeDataRegistry mrdr =
+ Globals.getDefaultHabitat().getComponent(MonitoringRuntimeDataRegistry.class);
     private TreeNode serverNode;
     private TreeNode httpServiceNode;
     private TreeNode webNode;
@@ -114,32 +135,101 @@
     
     private Level dbgLevel = Level.FINEST;
     private Level defaultLevel;
-
- public void postConstruct() {
- logger.finest("In the Web Monitor startup ************");
-
+ BundleContext myBundleContext;
+ private static String WEB_CORE_PACKAGE = "org.glassfish.web.web-core";
+ private static String GRIZZLY_PACKAGE = "org.glassfish.external.grizzly-module";
+
+ protected static class logger {
+ public void finest(String str) {
+ System.out.println(str);
+ }
+ }
+ public void start(BundleContext bCtx) {
         // to set log level, uncomment the following
         // remember to comment it before checkin
         // remove this once we find a proper solution
- /*
         defaultLevel = logger.getLevel();
- if (dbgLevel.intValue() < defaultLevel.intValue()) {
+ /*
+ if ((defaultLevel == null) || (dbgLevel.intValue() < defaultLevel.intValue())) {
             logger.setLevel(dbgLevel);
         }
- */
- logger.finest("In the Web Monitor startup ************");
+ */
+ logger.finest("[Monitor]In the Web Monitor startup ************");
 
- // buildWebMonitoringConfigTree should happen before
- // ppem.registerProbeProviderListener
- buildWebMonitoringConfigTree();
+ this.myBundleContext = bCtx;
+ logger.finest("[Monitor]BootstrapAdminMonitor started");
+
+ //Load monitoring levels
+ loadMonitoringLevels();
+
+ //Build the top level monitoring tree
+ buildTopLevelMonitoringTree();
+
+ //check if the monitoring level for JVM is 'on' and enable appropriately
+ buildJVMMonitoringTree();
+
+ //check if the monitoring level for Threadpool is 'on' and
+ // if Grizzly module is loaded, then register the ProveProviderListener
+ if (threadpoolMonitoringEnabled && isGrizzlyModuleLoaded()) {
+ registerProbeProviderListener();
+ }
 
- // ppem.registerProbeProviderListener should be called only after
- // buildWebMonitoringConfigTree is invoked because of dependency
- ppem.registerProbeProviderListener(this);
+ //check if the monitoring level for web-container is 'on' and
+ // if Web Container is loaded, then register the ProveProviderListener
+ if (!probeProviderListenerRegistered && webMonitoringEnabled &&
+ isWebContainerLoaded() ) {
+ registerProbeProviderListener();
+ }
 
- //Construct the JVMMemoryStatsTelemetry
- jvmMemoryTM =
- new JVMMemoryStatsTelemetry(serverNode, jvmMonitoringEnabled, logger);
+ bCtx.addBundleListener(this);
+ }
+
+ public void stop(BundleContext bCtx) {
+ logger.finest("[Monitor]BootstrapAdminMonitor stopped");
+ bCtx.removeBundleListener(this);
+ }
+
+ public void bundleChanged(BundleEvent event) {
+ if (event.getBundle().getSymbolicName().equals(WEB_CORE_PACKAGE) &&
+ (event.getType() == BundleEvent.STARTED)){
+ logger.finest("[Monitor]BundleEvent.getBundle() = " + event.getBundle().getSymbolicName());
+ logger.finest("[Monitor]BundleEvent.getType() = " + event.getType());
+ webContainerLoaded = true;
+ if (webMonitoringEnabled) {
+ if (!probeProviderListenerRegistered) {
+ registerProbeProviderListener();
+ } else {
+ //ProbeProviderListener already registered (as part of other container),
+ // see if the providers are already registered
+ buildWebMonitoringTree();
+ if (!isWebTreeBuilt){
+ logger.finest("[Monitor]Web Monitoring tree is not built for some reason though the Web Container started event is fired");
+ return;
+ }
+ if (sessionProviderRegistered)
+ buildSessionTelemetry();
+ if (jspProviderRegistered)
+ buildJspTelemetry();
+ if (servletProviderRegistered)
+ buildServletTelemetry();
+ if (requestProviderRegistered)
+ buildWebRequestTelemetry();
+ }
+ }
+ }
+ else if (event.getBundle().getSymbolicName().equals(GRIZZLY_PACKAGE) &&
+ (event.getType() == BundleEvent.STARTED)){
+ logger.finest("[Monitor]BundleEvent.getBundle() = " + event.getBundle().getSymbolicName());
+ logger.finest("[Monitor]BundleEvent.getType() = " + event.getType());
+ grizzlyModuleLoaded = true;
+ if (threadpoolMonitoringEnabled) {
+ if (!probeProviderListenerRegistered) {
+ registerProbeProviderListener();
+ } else {
+ buildThreadpoolMonitoringTree();
+ }
+ }
+ }
     }
 
     public Lifecycle getLifecycle() {
@@ -150,89 +240,39 @@
     public void providerRegistered(String moduleName, String providerName, String appName) {
         try {
             
- logger.finest("Provider registered event received - providerName = " +
+ logger.finest("[Monitor]Provider registered event received - providerName = " +
                                 providerName + " : module name = " + moduleName +
                                 " : appName = " + appName);
             if (providerName.equals("session")){
- logger.finest("and it is Web session");
- if (webSessionsTM == null) {
- webSessionsTM = new SessionStatsTelemetry(webSessionNode,
- null, null, webMonitoringEnabled, logger);
- Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webSessionsTM);
- webSessionsTM.setProbeListenerHandles(handles);
- }
- if (vsSessionTMs == null) {
- vsSessionTMs = new ArrayList<SessionStatsTelemetry>();
- TreeNode appsNode = serverNode.getNode("applications");
- Collection<TreeNode> appNodes = appsNode.getChildNodes();
- for (TreeNode appNode : appNodes){
- //Get all virtual servers
- Collection<TreeNode> vsNodes = appNode.getChildNodes();
- for (TreeNode vsNode : vsNodes) {
- //Create sessionTM for each vsNode
- SessionStatsTelemetry vsSessionTM =
- new SessionStatsTelemetry(vsNode,
- appNode.getName(), vsNode.getName(),
- webMonitoringEnabled, logger);
- vsSessionTMs.add(vsSessionTM);
-
- }
- }
+ logger.finest("[Monitor]and it is Web session");
+ buildWebMonitoringTree();
+ if (!isWebTreeBuilt){
+ logger.finest("[Monitor]Web Monitoring tree is not built for some reason though the provider registered event is fired");
+ sessionProviderRegistered = true;
+ return;
                 }
+ buildSessionTelemetry();
             }
             if (providerName.equals("servlet")){
- logger.finest("and it is Web servlet");
- if (webServletsTM == null) {
- webServletsTM = new ServletStatsTelemetry(webServletNode, null,
- null, webMonitoringEnabled, logger);
- Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webServletsTM);
- webServletsTM.setProbeListenerHandles(handles);
- }
- if (vsServletTMs == null) {
- vsServletTMs = new ArrayList<ServletStatsTelemetry>();
- TreeNode appsNode = serverNode.getNode("applications");
- Collection<TreeNode> appNodes = appsNode.getChildNodes();
- for (TreeNode appNode : appNodes){
- //Get all virtual servers
- Collection<TreeNode> vsNodes = appNode.getChildNodes();
- for (TreeNode vsNode : vsNodes) {
- //Create sessionTM for each vsNode
- ServletStatsTelemetry vsServletTM =
- new ServletStatsTelemetry(vsNode,
- appNode.getName(), vsNode.getName(),
- webMonitoringEnabled, logger);
- vsServletTMs.add(vsServletTM);
-
- }
- }
+ logger.finest("[Monitor]and it is Web servlet");
+ buildWebMonitoringTree();
+ if (!isWebTreeBuilt){
+ logger.finest("[Monitor]Web Monitoring tree is not built for some reason though the provider registered event is fired");
+ servletProviderRegistered = true;
+ return;
                 }
+ buildServletTelemetry();
             }
 
             if (providerName.equals("jsp")){
- logger.finest("and it is Web jsp");
- if (webJspTM == null) {
- webJspTM = new JspStatsTelemetry(webJspNode, null, null, webMonitoringEnabled, logger);
- Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webJspTM);
- webJspTM.setProbeListenerHandles(handles);
- }
- if (vsJspTMs == null) {
- vsJspTMs = new ArrayList<JspStatsTelemetry>();
- TreeNode appsNode = serverNode.getNode("applications");
- Collection<TreeNode> appNodes = appsNode.getChildNodes();
- for (TreeNode appNode : appNodes){
- //Get all virtual servers
- Collection<TreeNode> vsNodes = appNode.getChildNodes();
- for (TreeNode vsNode : vsNodes) {
- //Create sessionTM for each vsNode
- JspStatsTelemetry vsJspTM =
- new JspStatsTelemetry(vsNode,
- appNode.getName(), vsNode.getName(),
- webMonitoringEnabled, logger);
- vsJspTMs.add(vsJspTM);
-
- }
- }
+ logger.finest("[Monitor]and it is Web jsp");
+ buildWebMonitoringTree();
+ if (!isWebTreeBuilt){
+ logger.finest("[Monitor]Web Monitoring tree is not built for some reason though the provider registered event is fired");
+ jspProviderRegistered = true;
+ return;
                 }
+ buildJspTelemetry();
             }
             /* Need to fix module, decide where it should go
             if (providerName.equals("webmodule")){
@@ -245,28 +285,26 @@
             }
             */
             if (providerName.equals("request")){
- logger.finest("and it is Web request");
- if (webRequestTM == null) {
- webRequestTM = new WebRequestTelemetry(webRequestNode, webMonitoringEnabled, logger);
- Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webRequestTM);
- webRequestTM.setProbeListenerHandles(handles);
+ logger.finest("[Monitor]and it is Web request");
+ buildWebMonitoringTree();
+ if (!isWebTreeBuilt){
+ logger.finest("[Monitor]Web Monitoring tree is not built for some reason though the provider registered event is fired");
+ requestProviderRegistered = true;
+ return;
                 }
+ buildWebRequestTelemetry();
             }
             if (providerName.equals("threadpool")){
- logger.finest("and it is threadpool");
+ logger.finest("[Monitor]and it is threadpool");
                 if (threadPoolTM == null) {
- // Where do I add this? Looks like the thread pools are already created.
- // Now I need to register the listeners, but which one to register?
- threadPoolTM = new ThreadPoolTelemetry(httpServiceNode, threadpoolMonitoringEnabled, logger);
- Collection<ProbeClientMethodHandle> handles = pcm.registerListener(threadPoolTM);
- threadPoolTM.setProbeListenerHandles(handles);
+ buildThreadpoolMonitoringTree();
                 }
             }
              //Decide now if I need to enable or disable the nodes (for first time use)
         }catch (Exception e) {
             //Never throw an exception as the Web container startup will have a problem
             //Show warning
- logger.finest("WARNING: Exception in WebMonitorStartup : " +
+ logger.finest("[Monitor]WARNING: Exception in WebMonitorStartup : " +
                                     e.getLocalizedMessage());
             e.printStackTrace();
         }
@@ -276,56 +314,38 @@
         
     }
 
- /**
- * Tree Structure, names in () are dynamic nodes
- *
- * Server
- * | applications
- * | | web-module
- * | | application
- * | | j2ee-application
- * | | | (app-name)
- * | | | | (virtual-server)
- * | | | | | (servlet)
- * | web-container
- * | http-service
- * | | http-listener
- * | | connection-pool
- * | | (server-name)
- * | | | (request)
- * | thread-pools
- * | | (thread-pool)
- */
- private void buildWebMonitoringConfigTree() {
- /*
+ private void loadMonitoringLevels() {
         if (mml != null) {
             if ("OFF".equals(mml.getWebContainer())){
                 webMonitoringEnabled = false;
- logger.finest("Disabling webContainer");
+ logger.finest("[Monitor]Disabling webContainer");
             } else {
                 webMonitoringEnabled = true;
             }
             if ("OFF".equals(mml.getJvm())){
                 jvmMonitoringEnabled = false;
- logger.finest("Disabling jvmMonitoring");
+ logger.finest("[Monitor]Disabling jvmMonitoring");
             } else {
                 jvmMonitoringEnabled = true;
             }
             if ("OFF".equals(mml.getHttpService())){
                 httpServiceMonitoringEnabled = false;
- logger.finest("Disabling httpServiceMonitoring");
+ logger.finest("[Monitor]Disabling httpServiceMonitoring");
             } else {
                 httpServiceMonitoringEnabled = true;
             }
             if ("OFF".equals(mml.getThreadPool())){
                 threadpoolMonitoringEnabled = false;
- logger.finest("Disabling threadpoolMonitoring");
+ logger.finest("[Monitor]Disabling threadpoolMonitoring");
             } else {
                 threadpoolMonitoringEnabled = true;
             }
- logger.finest("mml.getWebContainer() = " + mml.getWebContainer());
+ logger.finest("[Monitor]mml.getWebContainer() = " + mml.getWebContainer());
         }
- */
+ }
+
+ //builds the top level tree
+ private void buildTopLevelMonitoringTree() {
         // server
         Server srvr = null;
         List<Server> ls = domain.getServers().getServer();
@@ -337,6 +357,305 @@
         }
         serverNode = TreeNodeFactory.createTreeNode("server", null, "server");
         mrdr.add("server", serverNode);
+ }
+
+ private void registerProbeProviderListener() {
+ // ppem.registerProbeProviderListener should be called only after
+ // buildWebMonitoringConfigTree is invoked because of dependency???
+ ppem.registerProbeProviderListener(this);
+ probeProviderListenerRegistered = true;
+ }
+
+ private void buildJspTelemetry() {
+ if (webJspTM == null) {
+ webJspTM = new JspStatsTelemetry(webJspNode, null, null, webMonitoringEnabled, logger);
+ Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webJspTM);
+ webJspTM.setProbeListenerHandles(handles);
+ } else { //Make sure you turn them on
+ if (!webJspTM.isEnabled())
+ webJspTM.enableMonitoring(true);
+ }
+ if (vsJspTMs == null) {
+ vsJspTMs = new ArrayList<JspStatsTelemetry>();
+ TreeNode appsNode = serverNode.getNode("applications");
+ Collection<TreeNode> appNodes = appsNode.getChildNodes();
+ for (TreeNode appNode : appNodes){
+ //Get all virtual servers
+ Collection<TreeNode> vsNodes = appNode.getChildNodes();
+ for (TreeNode vsNode : vsNodes) {
+ //Create sessionTM for each vsNode
+ JspStatsTelemetry vsJspTM =
+ new JspStatsTelemetry(vsNode,
+ appNode.getName(), vsNode.getName(),
+ webMonitoringEnabled, logger);
+ vsJspTMs.add(vsJspTM);
+
+ }
+ }
+ }else { //Make sure you turn them on
+ for (JspStatsTelemetry jspTM : vsJspTMs) {
+ if (!jspTM.isEnabled())
+ jspTM.enableMonitoring(true);
+ }
+ }
+ }
+
+ private void buildServletTelemetry() {
+ if (webServletsTM == null) {
+ webServletsTM = new ServletStatsTelemetry(webServletNode, null,
+ null, webMonitoringEnabled, logger);
+ Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webServletsTM);
+ webServletsTM.setProbeListenerHandles(handles);
+ } else { //Make sure you turn them on
+ if (webServletsTM.isEnabled())
+ webServletsTM.enableMonitoring(true);
+ }
+ if (vsServletTMs == null) {
+ vsServletTMs = new ArrayList<ServletStatsTelemetry>();
+ TreeNode appsNode = serverNode.getNode("applications");
+ Collection<TreeNode> appNodes = appsNode.getChildNodes();
+ for (TreeNode appNode : appNodes){
+ //Get all virtual servers
+ Collection<TreeNode> vsNodes = appNode.getChildNodes();
+ for (TreeNode vsNode : vsNodes) {
+ //Create sessionTM for each vsNode
+ ServletStatsTelemetry vsServletTM =
+ new ServletStatsTelemetry(vsNode,
+ appNode.getName(), vsNode.getName(),
+ webMonitoringEnabled, logger);
+ vsServletTMs.add(vsServletTM);
+
+ }
+ }
+ } else { //Make sure you turn them on
+ for (ServletStatsTelemetry servletTM : vsServletTMs) {
+ if (!servletTM.isEnabled())
+ servletTM.enableMonitoring(true);
+ }
+ }
+ }
+
+ private void buildSessionTelemetry() {
+ if (webSessionsTM == null) {
+ webSessionsTM = new SessionStatsTelemetry(webSessionNode,
+ null, null, webMonitoringEnabled, logger);
+ Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webSessionsTM);
+ webSessionsTM.setProbeListenerHandles(handles);
+ } else { //Make sure you turn them on
+ if (!webSessionsTM.isEnabled())
+ webSessionsTM.enableMonitoring(true);
+ }
+ if (vsSessionTMs == null) {
+ vsSessionTMs = new ArrayList<SessionStatsTelemetry>();
+ TreeNode appsNode = serverNode.getNode("applications");
+ Collection<TreeNode> appNodes = appsNode.getChildNodes();
+ for (TreeNode appNode : appNodes){
+ //Get all virtual servers
+ Collection<TreeNode> vsNodes = appNode.getChildNodes();
+ for (TreeNode vsNode : vsNodes) {
+ //Create sessionTM for each vsNode
+ SessionStatsTelemetry vsSessionTM =
+ new SessionStatsTelemetry(vsNode,
+ appNode.getName(), vsNode.getName(),
+ webMonitoringEnabled, logger);
+ vsSessionTMs.add(vsSessionTM);
+
+ }
+ }
+ } else { //Make sure you turn them on
+ for (SessionStatsTelemetry sessionTM : vsSessionTMs) {
+ if (!sessionTM.isEnabled())
+ sessionTM.enableMonitoring(true);
+ }
+ }
+ }
+
+ private void buildWebRequestTelemetry() {
+ if (webRequestTM == null) {
+ webRequestTM = new WebRequestTelemetry(webRequestNode, webMonitoringEnabled, logger);
+ Collection<ProbeClientMethodHandle> handles = pcm.registerListener(webRequestTM);
+ webRequestTM.setProbeListenerHandles(handles);
+ } else { // Make sure you turn it on
+ if (!webRequestTM.isEnabled())
+ webRequestTM.enableMonitoring(true);
+ }
+ }
+
+ /**
+ * Handle config changes for monitoring levels
+ * Add code for handling deployment changes like deploy/undeploy
+ */
+ public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
+ for (PropertyChangeEvent event : events) {
+ String propName = event.getPropertyName();
+ String mLevel = null;
+ if ("http-service".equals(propName)) {
+ mml = (ModuleMonitoringLevels) event.getSource();
+ mLevel = event.getNewValue().toString();
+ logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + httpServiceMonitoringEnabled);
+ if (httpServiceMonitoringEnabled == getEnabledValue(mLevel)) {
+ //Maintain status QUO
+ return null;
+ } else {
+ httpServiceMonitoringEnabled = getEnabledValue(mLevel);
+ /* TODO
+ if (httpServiceMonitoringEnabled) {//Turned from OFF to ON
+ this.buildHTTPServiceMonitoringTree();
+ } else { //Turned from ON to OFF
+ if (this.httpServiceTM.isEnabled())
+ httpServiceTM.enableMonitoring(false);
+ }
+ */
+ }
+ } else if ("jvm".equals(propName)) {
+ mml = (ModuleMonitoringLevels) event.getSource();
+ mLevel = event.getNewValue().toString();
+ if (jvmMonitoringEnabled == getEnabledValue(mLevel)) {
+ //Maintain status QUO
+ return null;
+ } else {
+ jvmMonitoringEnabled = getEnabledValue(mLevel);
+ if (jvmMonitoringEnabled) {//Turned from OFF to ON
+ this.buildJVMMonitoringTree();
+ } else { //Turned from ON to OFF
+ if (jvmMemoryTM.isEnabled())
+ jvmMemoryTM.enableMonitoring(false);
+ }
+ }
+ logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + jvmMonitoringEnabled);
+ // set corresponding tree node enabled flag
+ // handle proble listener event by registering/unregistering
+ //jvmMemoryTM.enableMonitoring(enabled);
+ } else if ("thread-pool".equals(propName)) {
+ mml = (ModuleMonitoringLevels) event.getSource();
+ mLevel = event.getNewValue().toString();
+ logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + threadpoolMonitoringEnabled);
+ if (threadpoolMonitoringEnabled == getEnabledValue(mLevel)) {
+ //Maintain status QUO
+ return null;
+ } else {
+ threadpoolMonitoringEnabled = getEnabledValue(mLevel);
+ if (threadpoolMonitoringEnabled) {//Turned from OFF to ON
+ buildThreadpoolMonitoringTree();
+ } else { //Turned from ON to OFF
+ if (threadPoolTM.isEnabled())
+ threadPoolTM.enableMonitoring(false);
+ }
+ }
+ // set corresponding tree node enabled flag
+ // handle proble listener event by registering/unregistering
+ //threadpoolTM.enableMonitoring(enabled);
+ } else if ("web-container".equals(propName)) {
+ mml = (ModuleMonitoringLevels) event.getSource();
+ mLevel = event.getNewValue().toString();
+ if (webMonitoringEnabled == getEnabledValue(mLevel)) {
+ //Maintain status QUO
+ return null;
+ } else {
+ webMonitoringEnabled = getEnabledValue(mLevel);
+ if (webMonitoringEnabled) { //Turned from OFF to ON
+ buildWebMonitoringTree();
+ if (!isWebTreeBuilt){
+ logger.finest("[Monitor]Web Monitoring tree is not built for some reason though the Web Container started event is fired");
+ return null;
+ }
+ if (sessionProviderRegistered)
+ buildSessionTelemetry();
+ if (jspProviderRegistered)
+ buildJspTelemetry();
+ if (servletProviderRegistered)
+ buildServletTelemetry();
+ if (requestProviderRegistered)
+ buildWebRequestTelemetry();
+ } else { //Turned from ON to OFF
+ disableWebMonitoring();
+ }
+
+ }
+ logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + webMonitoringEnabled);
+ }
+ }
+ return null;
+ }
+
+ private void buildJVMMonitoringTree() {
+ //Construct the JVMMemoryStatsTelemetry
+ if (jvmMonitoringEnabled)
+ jvmMemoryTM = new JVMMemoryStatsTelemetry(serverNode,
+ jvmMonitoringEnabled, logger);
+ }
+
+ private void buildThreadpoolMonitoringTree() {
+ //Construct the ThreadpoolStatsTelemetry
+ if (threadpoolMonitoringEnabled && grizzlyModuleLoaded){
+ if (threadPoolTM == null) {
+ // Where do I add this? Looks like the thread pools are already created.
+ // Now I need to register the listeners, but which one to register?
+ threadPoolTM = new ThreadPoolTelemetry(httpServiceNode, threadpoolMonitoringEnabled, logger);
+ Collection<ProbeClientMethodHandle> handles = pcm.registerListener(threadPoolTM);
+ threadPoolTM.setProbeListenerHandles(handles);
+ } else { //Make sure you turn them ON
+ if (!threadPoolTM.isEnabled())
+ threadPoolTM.enableMonitoring(true);
+ }
+
+ }
+ }
+
+ private void disableWebMonitoring() {
+ //Disable session telemetry
+ if (webSessionsTM.isEnabled())
+ webSessionsTM.enableMonitoring(false);
+ for (SessionStatsTelemetry sessionTM : vsSessionTMs) {
+ if (sessionTM.isEnabled())
+ sessionTM.enableMonitoring(false);
+ }
+
+ //Disable Servlet telemetry
+ if (webServletsTM.isEnabled())
+ webServletsTM.enableMonitoring(false);
+ for (ServletStatsTelemetry servletTM : vsServletTMs) {
+ if (servletTM.isEnabled())
+ servletTM.enableMonitoring(false);
+ }
+
+ //Disable JSP telemetry
+ if (webJspTM.isEnabled())
+ webJspTM.enableMonitoring(false);
+ for (JspStatsTelemetry jspTM : vsJspTMs) {
+ if (jspTM.isEnabled())
+ jspTM.enableMonitoring(false);
+ }
+
+ //Disable Request telemetry
+ if (webRequestTM.isEnabled())
+ webRequestTM.enableMonitoring(false);
+ }
+
+ /**
+ * Tree Structure, names in () are dynamic nodes
+ *
+ * Server
+ * | web
+ * | applications
+ * | | web-module
+ * | | application
+ * | | j2ee-application
+ * | | | (app-name)
+ * | | | | (virtual-server)
+ * | | | | | (servlet)
+ **/
+ private void buildWebMonitoringTree() {
+ if (isWebTreeBuilt || !webMonitoringEnabled || !webContainerLoaded)
+ return;
+ Server srvr = null;
+ List<Server> ls = domain.getServers().getServer();
+ for (Server sr : ls) {
+ if ("server".equals(sr.getName())) {
+ srvr = sr;
+ break;
+ }
+ }
         
         // web
         webNode = TreeNodeFactory.createTreeNode("web", null, "web");
@@ -378,49 +697,40 @@
             applications.addChild(app);
             addVirtualServers(srvr, app, wm.getName());
         }
- // get server-config
- Config sConfig = null;
- List<Config> lcfg = domain.getConfigs().getConfig();
- for (Config cfg : lcfg) {
- if ("server-config".equals(cfg.getName())) {
- sConfig = cfg;
- break;
- }
+ isWebTreeBuilt = true;
+ }
+
+ private boolean getEnabledValue(String enabledStr) {
+ if ("OFF".equals(enabledStr)) {
+ return false;
         }
- // http-service
- HttpService httpS = sConfig.getHttpService();
- httpServiceNode = TreeNodeFactory.createTreeNode("http-service", null, "web");
- serverNode.addChild(httpServiceNode);
- // virtual server(s)
- for (VirtualServer vServer : httpS.getVirtualServer()) {
- TreeNode vs = TreeNodeFactory.createTreeNode(vServer.getId(), null, "web");
- httpServiceNode.addChild(vs);
- // http-listener(s)
- String httpL = vServer.getHttpListeners();
- if (httpL != null) {
- for (String str : httpL.split(",")) {
- TreeNode httpListener = TreeNodeFactory.createTreeNode(str, null, "web");
- vs.addChild(httpListener);
- }
+ return true;
+ }
+
+ private boolean isGrizzlyModuleLoaded() {
+ Bundle[] bundles = myBundleContext.getBundles();
+ for (Bundle bndl : bundles){
+ if (bndl.getSymbolicName().equals(GRIZZLY_PACKAGE) &&
+ (bndl.getState() == Bundle.ACTIVE)) {
+ logger.finest("[Monitor]Bundle " + GRIZZLY_PACKAGE + " is loaded");
+ grizzlyModuleLoaded = true;
+ return true;
             }
         }
- // http-listener
- for (HttpListener htl : httpS.getHttpListener()) {
- TreeNode httpListener = TreeNodeFactory.createTreeNode(htl.getId(), null, "web");
- httpServiceNode.addChild(httpListener);
+ return false;
+ }
+
+ private boolean isWebContainerLoaded() {
+ Bundle[] bundles = myBundleContext.getBundles();
+ for (Bundle bndl : bundles){
+ if (bndl.getSymbolicName().equals(WEB_CORE_PACKAGE) &&
+ (bndl.getState() == Bundle.ACTIVE)) {
+ logger.finest("[Monitor]Bundle " + WEB_CORE_PACKAGE + " is loaded");
+ webContainerLoaded = true;
+ return true;
+ }
         }
- // connection-pool
- ConnectionPool cp = httpS.getConnectionPool();
- TreeNode connectionPool = TreeNodeFactory.createTreeNode("connection-pool", null, "web");
- httpServiceNode.addChild(connectionPool);
- // web-container
- WebContainer wc = sConfig.getWebContainer();
- TreeNode webContainer = TreeNodeFactory.createTreeNode("web-container", null, "web");
- serverNode.addChild(webContainer);
- // thread-pools
- ThreadPools tps = sConfig.getThreadPools();
- TreeNode threadPools = TreeNodeFactory.createTreeNode("thread-pools", null, "web");
- serverNode.addChild(threadPools);
+ return false;
     }
 
     private void addVirtualServers(Server server, TreeNode tn, String appName) {
@@ -443,7 +753,6 @@
         }
     }
 
-
     public static String getAppName(String contextRoot) {
         // first check in web modules
         List<WebModule> lm = domain.getApplications().getModules(WebModule.class);
@@ -463,57 +772,84 @@
     }
 
     /**
- * Handle config changes for monitoring levels
- * Add code for handling deployment changes like deploy/undeploy
+ * Tree Structure, names in () are dynamic nodes
+ *
+ * Server
+ * | applications
+ * | | web-module
+ * | | application
+ * | | j2ee-application
+ * | | | (app-name)
+ * | | | | (virtual-server)
+ * | | | | | (servlet)
+ * | web-container
+ * | http-service
+ * | | http-listener
+ * | | connection-pool
+ * | | (server-name)
+ * | | | (request)
+ * | thread-pools
+ * | | (thread-pool)
      */
- public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
- for (PropertyChangeEvent event : events) {
- String propName = event.getPropertyName();
- String mLevel = null;
- if ("http-service".equals(propName)) {
- mml = (ModuleMonitoringLevels) event.getSource();
- mLevel = event.getNewValue().toString();
- boolean enabled = getEnabledValue(mLevel);
- logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + enabled);
- // set corresponding tree node enabled flag
- // handle proble listener event by registering/unregistering
- } else if ("jvm".equals(propName)) {
- mml = (ModuleMonitoringLevels) event.getSource();
- mLevel = event.getNewValue().toString();
- boolean enabled = getEnabledValue(mLevel);
- logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + enabled);
- // set corresponding tree node enabled flag
- // handle proble listener event by registering/unregistering
- //jvmMemoryTM.enableMonitoring(enabled);
- } else if ("thread-pool".equals(propName)) {
- mml = (ModuleMonitoringLevels) event.getSource();
- mLevel = event.getNewValue().toString();
- boolean enabled = getEnabledValue(mLevel);
- logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + enabled);
- // set corresponding tree node enabled flag
- // handle proble listener event by registering/unregistering
- //threadpoolTM.enableMonitoring(enabled);
- } else if ("web-container".equals(propName)) {
- mml = (ModuleMonitoringLevels) event.getSource();
- mLevel = event.getNewValue().toString();
- boolean enabled = getEnabledValue(mLevel);
- logger.finest("[TM] Config change event - propName = " + propName + " : enabled=" + enabled);
- // set corresponding tree node enabled flag
- // handle proble listener event by registering/unregistering
-
- //webTM.enableMonitoring(enabled);
- //webRequestTM.enableMonitoring(enabled);
- //moduleTM.enableMonitoring(enabled);
- //sessionsTM.enableMonitoring(enabled);
+ /*
+ private void buildWebMonitoringConfigTree() {
+
+ // get server-config
+ Config sConfig = null;
+ List<Config> lcfg = domain.getConfigs().getConfig();
+ for (Config cfg : lcfg) {
+ if ("server-config".equals(cfg.getName())) {
+ sConfig = cfg;
+ break;
             }
         }
- return null;
- }
-
- private boolean getEnabledValue(String enabledStr) {
- if ("OFF".equals(enabledStr)) {
- return false;
+ // http-service
+ HttpService httpS = sConfig.getHttpService();
+ httpServiceNode = TreeNodeFactory.createTreeNode("http-service", null, "web");
+ serverNode.addChild(httpServiceNode);
+ // virtual server(s)
+ for (VirtualServer vServer : httpS.getVirtualServer()) {
+ TreeNode vs = TreeNodeFactory.createTreeNode(vServer.getId(), null, "web");
+ httpServiceNode.addChild(vs);
+ // http-listener(s)
+ String httpL = vServer.getHttpListeners();
+ if (httpL != null) {
+ for (String str : httpL.split(",")) {
+ TreeNode httpListener = TreeNodeFactory.createTreeNode(str, null, "web");
+ vs.addChild(httpListener);
+ }
+ }
         }
- return true;
+ // http-listener
+ for (HttpListener htl : httpS.getHttpListener()) {
+ TreeNode httpListener = TreeNodeFactory.createTreeNode(htl.getId(), null, "web");
+ httpServiceNode.addChild(httpListener);
+ }
+ // connection-pool
+ ConnectionPool cp = httpS.getConnectionPool();
+ TreeNode connectionPool = TreeNodeFactory.createTreeNode("connection-pool", null, "web");
+ httpServiceNode.addChild(connectionPool);
+ // web-container
+ WebContainer wc = sConfig.getWebContainer();
+ TreeNode webContainer = TreeNodeFactory.createTreeNode("web-container", null, "web");
+ serverNode.addChild(webContainer);
+ // thread-pools
+ ThreadPools tps = sConfig.getThreadPools();
+ TreeNode threadPools = TreeNodeFactory.createTreeNode("thread-pools", null, "web");
+ serverNode.addChild(threadPools);
+ }
+*/
+ /*
+ public void postConstruct() {
+
+ // buildWebMonitoringConfigTree should happen before
+ // ppem.registerProbeProviderListener
+ buildWebMonitoringConfigTree();
+
+ // ppem.registerProbeProviderListener should be called only after
+ // buildWebMonitoringConfigTree is invoked because of dependency
+ ppem.registerProbeProviderListener(this);
+
     }
+*/
 }

Modified: trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebRequestTelemetry.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebRequestTelemetry.java?view=diff&rev=22137&p1=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebRequestTelemetry.java&p2=trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebRequestTelemetry.java&r1=22136&r2=22137
==============================================================================
--- trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebRequestTelemetry.java (original)
+++ trunk/v3/web/admin/src/main/java/org/glassfish/web/admin/monitor/telemetry/WebRequestTelemetry.java 2008-08-26 23:29:58+0000
@@ -69,16 +69,16 @@
     //Provides the cumulative value of the error count. The error count represents
     //the number of cases where the response code was greater than or equal to 400.
     private Counter errorCount = CounterFactory.createCount();
-
+ private TreeNode webRequestNode = null;
     private TimeStats requestProcessTime = TimeStatsFactory.createTimeStatsMilli();
     private Collection<ProbeClientMethodHandle> handles;
- private boolean webMonitoringEnabled;
- private Logger logger;
+ private Logger logger;
+ private boolean isEnabled = true;
     
     public WebRequestTelemetry(TreeNode parent, boolean webMonitoringEnabled, Logger logger) {
         try {
             this.logger = logger;
- this.webMonitoringEnabled = webMonitoringEnabled;
+ webRequestNode = parent;
             //add maxTime attribute
             Method m1 = requestProcessTime.getClass().getMethod("getMaximumTime", (Class[]) null);
             TreeNode maxTime = TreeNodeFactory.createMethodInvoker("maxTime", requestProcessTime, "request", m1);
@@ -102,15 +102,12 @@
         }
     }
 
- ThreadLocal<Long> entry = new ThreadLocal<Long>();
-
     @ProbeListener("web:request::requestStartEvent")
     public void requestStartEvent(
         @ProbeParam("request") HttpServletRequest request,
         @ProbeParam("response") HttpServletResponse response) {
         logger.finest("[TM]requestStartEvent received - request = " +
                             request + ": response = " + response);
- //entry.set(System.currentTimeMillis());
         requestProcessTime.entry();
     }
 
@@ -124,15 +121,11 @@
         if (statusCode > 400)
             errorCount.increment();
         
- //long timeTaken = System.currentTimeMillis() - entry.get();
-
         logger.finest("[TM]requestEndEvent received - request = " +
                             request + ": response = " + response +
                             " :Response code = " + statusCode +
                             " :Response time = " + requestProcessTime.getTime());
 
- //entry.set(null); //Not sure if we need this
-
     }
     
     public long getProcessTime() {
@@ -142,37 +135,24 @@
     
     public void setProbeListenerHandles(Collection<ProbeClientMethodHandle> handles) {
         this.handles = handles;
- if (!webMonitoringEnabled){
- //disable handles
- tuneProbeListenerHandles(webMonitoringEnabled);
- }
     }
     
- public void enableProbeListenerHandles(boolean isEnabled) {
- if (isEnabled != webMonitoringEnabled) {
- webMonitoringEnabled = isEnabled;
- tuneProbeListenerHandles(webMonitoringEnabled);
- }
+ public boolean isEnabled() {
+ return isEnabled;
     }
     
- private void tuneProbeListenerHandles(boolean shouldEnable) {
- //disable handles
- for (ProbeClientMethodHandle handle : handles) {
- if (shouldEnable)
- handle.enable();
- else
- handle.disable();
- }
-
- }
-
- public void enableMonitoring(boolean isEnable) {
+ public void enableMonitoring(boolean flag) {
         //loop through the handles for this node and enable/disable the listeners
         //delegate the request to the child nodes
+ if (isEnabled != flag) {
+ for (ProbeClientMethodHandle handle : handles) {
+ if (flag == true)
+ handle.enable();
+ else
+ handle.disable();
+ }
+ webRequestNode.setEnabled(flag);
+ isEnabled = flag;
+ }
     }
-
- public void enableMonitoringForSubElements(boolean isEnable) {
- //loop through the children and enable/disable all
- }
-
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe_at_glassfish-svn.dev.java.net
For additional commands, e-mail: commits-help_at_glassfish-svn.dev.java.net