You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2008/02/15 17:45:47 UTC

svn commit: r628114 - in /lenya/trunk/src/modules-core/monitoring: ./ config/ config/web-xml/ java/ java/src/ java/src/org/ java/src/org/apache/ java/src/org/apache/lenya/ java/src/org/apache/lenya/modules/ java/src/org/apache/lenya/modules/monitoring/

Author: andreas
Date: Fri Feb 15 08:45:46 2008
New Revision: 628114

URL: http://svn.apache.org/viewvc?rev=628114&view=rev
Log:
Adding monitoring module

Added:
    lenya/trunk/src/modules-core/monitoring/
    lenya/trunk/src/modules-core/monitoring/config/
    lenya/trunk/src/modules-core/monitoring/config/module.xml
    lenya/trunk/src/modules-core/monitoring/config/web-xml/
    lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionCountLogger.xweb
    lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionListener.xweb
    lenya/trunk/src/modules-core/monitoring/java/
    lenya/trunk/src/modules-core/monitoring/java/src/
    lenya/trunk/src/modules-core/monitoring/java/src/org/
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionListener.java

Added: lenya/trunk/src/modules-core/monitoring/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/monitoring/config/module.xml?rev=628114&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/config/module.xml (added)
+++ lenya/trunk/src/modules-core/monitoring/config/module.xml Fri Feb 15 08:45:46 2008
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<module xmlns="http://apache.org/lenya/module/1.0">
+  <id>org.apache.lenya.modules.monitoring</id>
+  <export package="org.apache.lenya.modules.monitoring"/>
+  <package>org.apache.lenya.modules</package>
+  <version>0.0.3</version>
+  <name>Monitoring</name>
+  <lenya-version>@lenya.version@</lenya-version>
+  <description>Tools to monitor a Lenya application.</description>
+</module> 

Added: lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionCountLogger.xweb
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionCountLogger.xweb?rev=628114&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionCountLogger.xweb (added)
+++ lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionCountLogger.xweb Fri Feb 15 08:45:46 2008
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<xweb xpath="/web-app"
+  unless="listener[normalize-space(listener-class) = 'org.apache.lenya.modules.monitoring.SessionCountLogger']"
+  insert-before="node()[1]">
+  <listener>
+    <listener-class>org.apache.lenya.modules.monitoring.SessionCountLogger</listener-class>
+  </listener>
+</xweb>
+

Added: lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionListener.xweb
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionListener.xweb?rev=628114&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionListener.xweb (added)
+++ lenya/trunk/src/modules-core/monitoring/config/web-xml/sessionListener.xweb Fri Feb 15 08:45:46 2008
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<xweb xpath="/web-app"
+  unless="listener[normalize-space(listener-class) = 'org.apache.lenya.modules.monitoring.SessionListener']"
+  insert-before="node()[1]">
+  <listener>
+    <listener-class>org.apache.lenya.modules.monitoring.SessionListener</listener-class>
+  </listener>
+</xweb>
+

Added: lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java?rev=628114&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java (added)
+++ lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java Fri Feb 15 08:45:46 2008
@@ -0,0 +1,52 @@
+/*
+ * 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.lenya.modules.monitoring;
+
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Logs session information.
+ */
+public class SessionCountLogger implements HttpSessionListener {
+
+    protected Logger log = Logger.getLogger(SessionCountLogger.class);
+
+    private int sessionCount;
+
+    public SessionCountLogger() {
+        this.sessionCount = 0;
+    }
+
+    public void sessionCreated(HttpSessionEvent event) {
+        synchronized (this) {
+            this.sessionCount++;
+        }
+        log.info("Sessions: " + this.sessionCount);
+    }
+
+    public void sessionDestroyed(HttpSessionEvent event) {
+        synchronized (this) {
+            --this.sessionCount;
+        }
+        log.info("Sessions: " + this.sessionCount);
+    }
+
+}

Added: lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionListener.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionListener.java?rev=628114&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionListener.java (added)
+++ lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionListener.java Fri Feb 15 08:45:46 2008
@@ -0,0 +1,53 @@
+/*
+ * 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.lenya.modules.monitoring;
+
+/**
+ * A Listener which store the session object in a HashMap on creation and 
+ * remove it if the session is destroyed.
+ * 
+ * @version $Id: SessionListener.java 473861 2006-11-12 03:51:14Z gregor $
+ */
+
+import javax.servlet.http.*;
+import java.util.WeakHashMap;
+
+public class SessionListener implements HttpSessionListener {
+
+	private static WeakHashMap allSessions = new WeakHashMap();
+
+	public void sessionCreated(HttpSessionEvent se) {
+
+		HttpSession session = se.getSession();
+		String sessionID = session.getId();
+		allSessions.put(sessionID,session);				
+	}
+
+	public void sessionDestroyed(HttpSessionEvent se) {
+		HttpSession session = se.getSession();
+		String sessionID = session.getId();
+		if (allSessions.containsKey(sessionID)) {
+			allSessions.remove(sessionID);
+		}
+	}
+
+	public WeakHashMap getAllSessions() {
+		return allSessions;
+	}	
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org