svn commit: r628194 - in /lenya/trunk/src/modules-core/monitoring: config/sitemap-xmap/ java/src/org/apache/lenya/modules/monitoring/

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Fri Feb 15 14:49:18 2008
New Revision: 628194

URL: http://svn.apache.org/viewvc?rev=628194&view=rev
Log:
Adding SessionLimitAction

Added:
    lenya/trunk/src/modules-core/monitoring/config/sitemap-xmap/
    lenya/trunk/src/modules-core/monitoring/config/sitemap-xmap/sessionLimitAction.xmap
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionLimitAction.java
Modified:
    lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java

Added: lenya/trunk/src/modules-core/monitoring/config/sitemap-xmap/sessionLimitAction.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/monitoring/config/sitemap-xmap/sessionLimitAction.xmap?rev=628194&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/config/sitemap-xmap/sessionLimitAction.xmap (added)
+++ lenya/trunk/src/modules-core/monitoring/config/sitemap-xmap/sessionLimitAction.xmap Fri Feb 15 14:49:18 2008
@@ -0,0 +1,22 @@
+<?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.
+-->
+
+<xmap xpath="/sitemap/components/actions" unless="/sitemap/components/actions/action[@name = 'session-limit']"
+  xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+  <map:action name="session-limit" src="org.apache.lenya.modules.monitoring.SessionLimitAction" logger="lenya.sitemap.action.session-limit"/>
+</xmap>
\ No newline at end of file

Modified: 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=628194&r1=628193&r2=628194&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java (original)
+++ lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionCountLogger.java Fri Feb 15 14:49:18 2008
@@ -28,25 +28,28 @@
 public class SessionCountLogger implements HttpSessionListener {
 
     protected Logger log = Logger.getLogger(SessionCountLogger.class);
-
-    private int sessionCount;
+    private static Object LOCK = SessionCountLogger.class;
+    private static int sessionCount = 0;
 
     public SessionCountLogger() {
-        this.sessionCount = 0;
     }
 
     public void sessionCreated(HttpSessionEvent event) {
-        synchronized (this) {
-            this.sessionCount++;
+        synchronized (LOCK) {
+            sessionCount++;
         }
         log.info("Sessions: " + this.sessionCount);
     }
 
     public void sessionDestroyed(HttpSessionEvent event) {
-        synchronized (this) {
-            --this.sessionCount;
+        synchronized (LOCK) {
+            --sessionCount;
         }
         log.info("Sessions: " + this.sessionCount);
+    }
+    
+    public static int getSessionCount() {
+        return sessionCount;
     }
 
 }

Added: lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionLimitAction.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionLimitAction.java?rev=628194&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionLimitAction.java (added)
+++ lenya/trunk/src/modules-core/monitoring/java/src/org/apache/lenya/modules/monitoring/SessionLimitAction.java Fri Feb 15 14:49:18 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;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.acting.AbstractAction;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+
+/**
+ * The action returns an empty map if the current request has no session yet and the session limit
+ * is exceeded and <code>null</code> otherwise. The session limit is specified using the
+ * <em>limit</em> parameter.
+ */
+public class SessionLimitAction extends AbstractAction {
+
+    protected static final String PARAM_LIMIT = "limit";
+
+    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source,
+            Parameters parameters) throws Exception {
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        if (request.getSession(false) == null) {
+            long limit = parameters.getParameterAsLong(PARAM_LIMIT);
+            if (SessionCountLogger.getSessionCount() >= limit) {
+                getLogger().info("Session limit [" + limit + "] exceeded.");
+                return Collections.EMPTY_MAP;
+            }
+        }
+        return null;
+        
+    }
+
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.