JBoss Native SVN: r2048 - trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/client.
by jbossnative-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-11-03 12:42:21 -0500 (Mon, 03 Nov 2008)
New Revision: 2048
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/client/RequestDriver.java
Log:
Rework session count tracking
Modified: trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/client/RequestDriver.java
===================================================================
--- trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/client/RequestDriver.java 2008-11-01 18:02:11 UTC (rev 2047)
+++ trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/client/RequestDriver.java 2008-11-03 17:42:21 UTC (rev 2048)
@@ -168,7 +168,7 @@
AtomicBoolean stopped)
{
this.request_url = request_url;
- this.destroy_url = destroy_url;
+ this.destroy_url = (request_url.equals(destroy_url)) ? null : destroy_url;
this.sessionLife = sessionLife * 1000;
this.sleepTime = sleepTime;
this.requests = requests;
@@ -195,14 +195,22 @@
stop = System.currentTimeMillis();
try
{
- if (cookie != null)
+ // Make an attempt to terminate any ongoing session
+ // Only bother if our destroy
+ if (cookie != null && destroy_url != null)
{
- executeRequest(destroy_url, false);
+ executeRequest(destroy_url);
}
}
catch (IOException e)
{
}
+ finally
+ {
+ // If we haven't already cleaned up this thread's
+ // session info, do so now
+ handleSessionTermination();
+ }
}
}
@@ -264,7 +272,7 @@
break;
}
- rc = executeRequest(request_url, false);
+ rc = executeRequest(request_url);
if (rc == 200)
{
successful_reads++;
@@ -278,14 +286,17 @@
}
}
- if (!failed) // if we failed, executeRequest destroyed session for us
+ if (!failed && destroy_url != null)
{
- executeRequest(destroy_url, true);
+ // Send invalidation request
+ executeRequest(destroy_url);
}
+
+ handleSessionTermination();
}
}
- private int executeRequest(URL url, boolean destroySession) throws IOException
+ private int executeRequest(URL url) throws IOException
{
InputStream input = null;
HttpURLConnection conn = null;
@@ -303,44 +314,33 @@
input.close(); // discard data
String handlerNode = conn.getHeaderField(Constants.NODE_HEADER);
- String tmp_cookie = conn.getHeaderField("set-cookie");
- if (tmp_cookie != null && cookie == null)
- {
- // New session
- cookie = tmp_cookie;
- modifyCount(handlerNode, sessions, true);
- }
modifyCount(handlerNode, requests, true);
- // If we failed over, decrement the previous handler's count
- if (!handlerNode.equals(lastHandler))
- {
- modifyCount(lastHandler, sessions, false);
- }
+ String tmp_cookie = conn.getHeaderField("set-cookie");
- int rc = conn.getResponseCode();
- if ((rc != 200 || destroySession) && cookie != null)
+ if (tmp_cookie != null && cookie == null)
{
- cookie = null;
- lastHandler = null;
- modifyCount(handlerNode, sessions, false);
- }
- else if (cookie != null)
- {
+ // New session -- track it and its handler
+ cookie = tmp_cookie;
+ modifyCount(handlerNode, sessions, true);
// Track this handler so we can decrement the session
// count in case of failover or error
lastHandler = handlerNode;
}
+ else if (lastHandler != null && !lastHandler.equals(handlerNode))
+ {
+ // Ongoing session has failed over in an unplanned way,
+ // so decrement the previous handler's count.
+ modifyCount(lastHandler, sessions, false);
+ lastHandler = null;
+ }
- return rc;
+ return conn.getResponseCode();
}
catch (Exception e)
{
- // Decrement the session count for whoever last handled a request
- cookie = null;
- modifyCount(lastHandler, sessions, false);
- lastHandler = null;
+ handleSessionTermination();
if (e instanceof IOException)
throw (IOException) e;
@@ -353,6 +353,25 @@
conn.disconnect();
}
}
+
+ private void invalidateSession()
+ {
+ if (!request_url.equals(destroy_url))
+ {
+ }
+ }
+
+ private void handleSessionTermination()
+ {
+ cookie = null;
+ String last = lastHandler;
+ lastHandler = null;
+ if (last != null)
+ {
+ // Decrement the session count for whoever last handled a request
+ modifyCount(last, sessions, false);
+ }
+ }
private static void modifyCount(String handlerNode, ConcurrentMap<String, AtomicInteger> map, boolean increment)
{
16 years, 2 months
JBoss Native SVN: r2047 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-11-01 14:02:11 -0400 (Sat, 01 Nov 2008)
New Revision: 2047
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Minor logic consolidation
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-11-01 01:15:18 UTC (rev 2046)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-11-01 18:02:11 UTC (rev 2047)
@@ -495,7 +495,7 @@
if (line.startsWith("Node:"))
{
String[] entries = line.split(",");
- String nodeId = this.parseId(entries[0]);
+ String nodeId = this.parseIds(entries[0])[0];
// We can skip the first entry
for (int i = 1; i < entries.length; ++i)
@@ -522,7 +522,7 @@
else if (line.startsWith("Vhost:"))
{
String[] entries = line.split(",");
- String[] ids = this.parseId(entries[0]).split(":");
+ String[] ids = this.parseIds(entries[0]);
if (ids.length != 3)
{
@@ -570,7 +570,7 @@
else if (line.startsWith("Context:"))
{
String[] entries = line.split(",");
- String[] ids = this.parseId(entries[0]).split(":");
+ String[] ids = this.parseIds(entries[0]);
if (ids.length != 3)
{
@@ -642,7 +642,7 @@
return result;
}
- private String parseId(String entry)
+ private String[] parseIds(String entry)
{
int start = entry.indexOf('[') + 1;
int end = entry.indexOf(']');
@@ -652,7 +652,9 @@
throw new IllegalArgumentException(entry);
}
- return entry.substring(start, end);
+ String ids = entry.substring(start, end);
+
+ return (ids.length() > 2) ? ids.split(":") : new String[] { ids };
}
/**
16 years, 2 months
JBoss Native SVN: r2046 - trunk/mod_cluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-31 21:15:18 -0400 (Fri, 31 Oct 2008)
New Revision: 2046
Removed:
trunk/mod_cluster/build-tomcat.xml
Log:
Obsolete
Deleted: trunk/mod_cluster/build-tomcat.xml
===================================================================
--- trunk/mod_cluster/build-tomcat.xml 2008-11-01 01:14:28 UTC (rev 2045)
+++ trunk/mod_cluster/build-tomcat.xml 2008-11-01 01:15:18 UTC (rev 2046)
@@ -1,59 +0,0 @@
-<?xml version="1.0"?>
-<!--
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * @author Jean-Frederic Clere
- * @version $Revision$
--->
-<project name="tomcat" default="all" basedir=".">
-
- <!-- See "build.properties.sample" in the top level directory for all -->
- <!-- property values you must customize for successful building!!! -->
- <property file="${user.home}/build.properties"/>
- <property file="build.properties"/>
-
- <property file="build.properties.default"/>
-
- <property name="out.dir" value="${basedir}/target/tomcat/"/>
- <property name="out.classes" value="${basedir}/target/tomcat/classes"/>
-
- <property name="compile.source" value="1.5"/>
-
- <target name="compile">
-
- <mkdir dir="${out.classes}"/>
-
- <!-- Compile -->
- <javac srcdir="src/tomcat" destdir="${out.classes}"
- debug="on" debuglevel="lines,vars,source"
- deprecation="${compile.deprecation}"
- source="${compile.source}"
- optimize="${compile.optimize}">
- <include name="org/jboss/logging/**" />
- </javac>
- </target>
-
- <target name="all" depends="compile">
- <jar destfile="${out.dir}/jbosslogging.jar">
- <fileset dir="${out.classes}"/>
- </jar>
- </target>
-</project>
16 years, 2 months