Author: veithen
Date: Sun Oct 21 09:23:28 2012
New Revision: 1400609
URL: http://svn.apache.org/viewvc?rev=1400609&view=rev
Log:
Allow limiting the number of concurrently active sessions in the stand-alone
Axis server. This is important for integration tests because they potentially
create a large number of sessions.
Added:
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/LimitSessionManager.java
(with props)
Modified:
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/StandaloneAxisServer.java
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartServerMojo.java
Added:
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/LimitSessionManager.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/LimitSessionManager.java?rev=1400609&view=auto
==============================================================================
---
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/LimitSessionManager.java
(added)
+++
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/LimitSessionManager.java
Sun Oct 21 09:23:28 2012
@@ -0,0 +1,102 @@
+/*
+ * 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.axis.server.standalone;
+
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.mortbay.jetty.servlet.AbstractSessionManager;
+import org.mortbay.jetty.servlet.HashSessionManager;
+
+/**
+ * {@link HashSessionManager} extension that limits the number of concurrently
active session.
+ *
+ * @author Andreas Veithen
+ */
+public class LimitSessionManager extends HashSessionManager {
+ // This is only needed to get access to some protected methods/fields.
+ class Session extends HashSessionManager.Session {
+ private static final long serialVersionUID = -6648322281268846583L;
+
+ Session(HttpServletRequest request) {
+ super(request);
+ }
+
+ long accessed() {
+ return _accessed;
+ }
+
+ protected void timeout() {
+ super.timeout();
+ }
+ }
+
+ private final int maxSessions;
+ private Timer timer;
+ private TimerTask task;
+
+ public LimitSessionManager(int maxSessions) {
+ this.maxSessions = maxSessions;
+ }
+
+ public void doStart() throws Exception {
+ super.doStart();
+ timer = new Timer(true);
+ task = new TimerTask() {
+ public void run() {
+ scavenge();
+ }
+ };
+ timer.schedule(task, 5000L, 5000L);
+ }
+
+ protected AbstractSessionManager.Session newSession(HttpServletRequest
request) {
+ return new Session(request);
+ }
+
+ void scavenge() {
+ while (true) {
+ Session sessionToRemove = null;
+ synchronized (this) {
+ if (_sessions.size() <= maxSessions) {
+ break;
+ }
+ long minAccessed = Long.MAX_VALUE;
+ for (Iterator it = _sessions.values().iterator();
it.hasNext(); ) {
+ Session session = (Session)it.next();
+ long accessed = session.accessed();
+ if (accessed < minAccessed) {
+ minAccessed = accessed;
+ sessionToRemove = session;
+ }
+ }
+ }
+ sessionToRemove.timeout();
+ }
+ }
+
+ public void doStop() throws Exception {
+ task.cancel();
+ timer.cancel();
+ super.doStop();
+ }
+}
Propchange:
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/LimitSessionManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/StandaloneAxisServer.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/StandaloneAxisServer.java?rev=1400609&r1=1400608&r2=1400609&view=diff
==============================================================================
---
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/StandaloneAxisServer.java
(original)
+++
axis/axis1/java/trunk/axis-standalone-server/src/main/java/org/apache/axis/server/standalone/StandaloneAxisServer.java
Sun Oct 21 09:23:28 2012
@@ -30,7 +30,9 @@ import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.mortbay.jetty.Server;
+import org.mortbay.jetty.SessionManager;
import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.HashSessionManager;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.servlet.ServletMapping;
@@ -67,6 +69,12 @@ public class StandaloneAxisServer {
options.addOption(option);
}
+ {
+ Option option = new Option("m", true, "the maximum number of
concurrently active sessions");
+ option.setArgName("count");
+ options.addOption(option);
+ }
+
if (args.length == 0) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(StandaloneAxisServer.class.getName(), options);
@@ -85,6 +93,13 @@ public class StandaloneAxisServer {
int port = Integer.parseInt(cmdLine.getOptionValue("p"));
+ int maxSessions;
+ if (cmdLine.hasOption("m")) {
+ maxSessions = Integer.parseInt(cmdLine.getOptionValue("m"));
+ } else {
+ maxSessions = -1;
+ }
+
StandaloneAxisServlet servlet = new StandaloneAxisServlet();
List resources = new ArrayList();
@@ -110,7 +125,13 @@ public class StandaloneAxisServer {
server.setGracefulShutdown(1000);
Context context = new Context(server, "/axis");
context.setBaseResource(new
ResourceCollection((Resource[])resources.toArray(new
Resource[resources.size()])));
- context.setSessionHandler(new SessionHandler());
+ SessionManager sessionManager;
+ if (maxSessions == -1) {
+ sessionManager = new HashSessionManager();
+ } else {
+ sessionManager = new LimitSessionManager(maxSessions);
+ }
+ context.setSessionHandler(new SessionHandler(sessionManager));
QuitListener quitListener = new QuitListener();
context.setAttribute(QuitHandler.QUIT_LISTENER, quitListener);
ServletHandler servletHandler = context.getServletHandler();
Modified:
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartServerMojo.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartServerMojo.java?rev=1400609&r1=1400608&r2=1400609&view=diff
==============================================================================
---
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartServerMojo.java
(original)
+++
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartServerMojo.java
Sun Oct 21 09:23:28 2012
@@ -63,6 +63,13 @@ public class StartServerMojo extends Abs
private int port;
/**
+ * The maximum number of concurrently active sessions.
+ *
+ * @parameter default-value="100"
+ */
+ private int maxSessions;
+
+ /**
* A set of WSDD files for services to deploy. The WSDD files may be
deployment or undeployment
* requests. Undeployment requests will be processed when the server is
stopped. The primary use
* case for this is to test undeployment.
@@ -202,6 +209,8 @@ public class StartServerMojo extends Abs
args.add("-j");
args.add(StringUtils.join(jwsDirs, File.pathSeparator));
}
+ args.add("-m");
+ args.add(String.valueOf(maxSessions));
try {
AdminClient adminClient = new AdminClient(true);
adminClient.setTargetEndpointAddress(new URL("http://localhost:" +
actualPort + "/axis/services/AdminService"));