[richfaces-svn-commits] JBoss Rich Faces SVN: r12083 - in trunk/framework/jsf-test: src/main/java/org/richfaces/test/staging and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Dec 31 17:33:21 EST 2008


Author: alexsmirnov
Date: 2008-12-31 17:33:20 -0500 (Wed, 31 Dec 2008)
New Revision: 12083

Modified:
   trunk/framework/jsf-test/pom.xml
   trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
   trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
Log:
Implement multy-session server for a concurrent request tests.

Modified: trunk/framework/jsf-test/pom.xml
===================================================================
--- trunk/framework/jsf-test/pom.xml	2008-12-31 11:56:58 UTC (rev 12082)
+++ trunk/framework/jsf-test/pom.xml	2008-12-31 22:33:20 UTC (rev 12083)
@@ -67,6 +67,12 @@
 			<groupId>net.sourceforge.nekohtml</groupId>
 			<artifactId>nekohtml</artifactId>
 			<version>1.9.9</version>
+			<exclusions>
+				<exclusion>
+					<groupId>xml-apis</groupId>
+					<artifactId>xml-apis</artifactId>
+				</exclusion>
+			</exclusions>
 		</dependency>
 		<dependency>
 			<groupId>javax.el</groupId>
@@ -103,6 +109,12 @@
 			<groupId>xalan</groupId>
 			<artifactId>xalan</artifactId>
 			<version>2.7.0</version>
+			<exclusions>
+				<exclusion>
+					<groupId>xml-apis</groupId>
+					<artifactId>xml-apis</artifactId>
+				</exclusion>
+			</exclusions>
 		</dependency>
 		<dependency>
 			<groupId>de.berlios.jsunit</groupId>

Modified: trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
===================================================================
--- trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java	2008-12-31 11:56:58 UTC (rev 12082)
+++ trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java	2008-12-31 22:33:20 UTC (rev 12083)
@@ -148,7 +148,7 @@
 	 */
 	public void invalidate() {
 		checkValid();
-		unboundAttributes();
+		destroy();
 		this.valid=false;
 
 	}

Modified: trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
===================================================================
--- trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java	2008-12-31 11:56:58 UTC (rev 12082)
+++ trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java	2008-12-31 22:33:20 UTC (rev 12083)
@@ -92,9 +92,12 @@
 
 	private ServletContext contextProxy;
 
-	private ServerHttpSession session = null;
+	private HttpSession currentSession = null;
+	
+	private ThreadLocal<HttpSession> sessions = new ThreadLocal<HttpSession>();
+	
+	private boolean sessionPerThread = false;
 
-	private HttpSession sessionProxy = null;
 
 	private boolean initialised = false;
 
@@ -261,6 +264,12 @@
 						}
 					});
 		}
+		
+		@Override
+		public void invalidate() {
+			super.invalidate();
+			setCurrentSession(null);
+		}
 	}
 
 	/**
@@ -274,6 +283,8 @@
 				invoker.invoke((T) listener);
 			}
 		}
+		
+		
 	}
 
 	/**
@@ -607,6 +618,32 @@
 
 	}
 
+	public boolean isSessionPerThread() {
+		return sessionPerThread;
+	}
+
+	public void setSessionPerThread(boolean sessionPerThread) {
+		this.sessionPerThread = sessionPerThread;
+	}
+	
+	
+	HttpSession getCurrentSession() {
+		if (isSessionPerThread()) {
+			return sessions.get();
+		} else {
+			return currentSession;
+		}
+	}
+	
+	void setCurrentSession(HttpSession session) {
+		if (isSessionPerThread()) {
+			sessions.set(session);
+		} else {
+			this.currentSession=session;
+		}
+		
+	}
+
 	/**
 	 * Get virtual server session object. Create new one if necessary.
 	 * 
@@ -644,18 +681,20 @@
 		if (!initialised) {
 			throw new TestException("Staging server have not been initialised");
 		}
-		if (null == this.session && create) {
-			this.session = new ServerHttpSession();
+		HttpSession httpSession = this.getCurrentSession();
+		if (null == httpSession && create) {
+			ServerHttpSession sessionImpl = new ServerHttpSession();
 			// Create proxy objects.
 			ClassLoader loader = Thread.currentThread().getContextClassLoader();
 			if (null == loader) {
 				loader = this.getClass().getClassLoader();
 			}
-			this.sessionProxy = (HttpSession) Proxy.newProxyInstance(loader,
+			httpSession = (HttpSession) Proxy.newProxyInstance(loader,
 					new Class[] { HttpSession.class },
-					getInvocationHandler(session));
+					getInvocationHandler(sessionImpl));
+			setCurrentSession(httpSession);
 			// inform session listeners.
-			final HttpSessionEvent event = new HttpSessionEvent(session);
+			final HttpSessionEvent event = new HttpSessionEvent(httpSession);
 			fireEvent(SESSION_LISTENER_CLASS,
 					new EventInvoker<HttpSessionListener>() {
 						public void invoke(HttpSessionListener listener) {
@@ -663,7 +702,7 @@
 						}
 					});
 		}
-		return sessionProxy;
+		return httpSession;
 	}
 
 	/**
@@ -722,7 +761,9 @@
 		}
 		this.initialised = false;
 		// Destroy session
-		if (null != this.session) {
+		// TODO - destroy all threads.
+		HttpSession session = getCurrentSession();
+		if (null != session) {
 			// inform session listeners.
 			final HttpSessionEvent event = new HttpSessionEvent(session);
 			fireEvent(SESSION_LISTENER_CLASS,
@@ -731,8 +772,8 @@
 							listener.sessionDestroyed(event);
 						}
 					});
-			session.destroy();
-			session = null;
+			session.invalidate();
+			setCurrentSession(null);
 		}
 		// Inform listeners
 		final ServletContextEvent event = new ServletContextEvent(context);




More information about the richfaces-svn-commits mailing list