[Jboss-cvs] JBossAS SVN: r56444 - trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 30 10:48:46 EDT 2006
Author: hmesha
Date: 2006-08-30 10:48:44 -0400 (Wed, 30 Aug 2006)
New Revision: 56444
Added:
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/SessionSerializationFactory.java
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/JBossCacheService.java
Log:
JBAS-2921
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/JBossCacheService.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/JBossCacheService.java 2006-08-30 14:08:53 UTC (rev 56443)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/JBossCacheService.java 2006-08-30 14:48:44 UTC (rev 56444)
@@ -21,9 +21,10 @@
*/
package org.jboss.web.tomcat.tc6.session;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@@ -51,10 +52,9 @@
import org.jboss.cache.aop.PojoCacheMBean;
import org.jboss.cache.transaction.BatchModeTransactionManager;
import org.jboss.invocation.MarshalledValue;
-import org.jboss.invocation.MarshalledValueInputStream;
-import org.jboss.invocation.MarshalledValueOutputStream;
import org.jboss.logging.Logger;
import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.serial.io.MarshalledObject;
/**
* A wrapper class to JBossCache. This is currently needed to handle various operations such as
@@ -290,10 +290,12 @@
Thread.currentThread().setContextClassLoader(manager_.getWebappClassLoader());
try
{
- ByteArrayInputStream bais = new ByteArrayInputStream(sessionBytes);
+ // JBAS-2921 - replaced MarshalledValue calls with SessionSerializationFactory calls
+ // ByteArrayInputStream bais = new ByteArrayInputStream(sessionBytes);
// Use MarshalledValueInputStream instead of superclass ObjectInputStream
// or else there are problems finding classes with scoped loaders
- MarshalledValueInputStream input = new MarshalledValueInputStream(bais);
+ // MarshalledValueInputStream input = new MarshalledValueInputStream(bais);
+ ObjectInputStream input = SessionSerializationFactory.createObjectInputStream(sessionBytes);
toLoad.readExternal(input);
input.close();
}
@@ -1017,12 +1019,30 @@
// {
try
{
- MarshalledValue mv = new MarshalledValue(value);
- if (log_.isTraceEnabled())
+ // JBAS-2921 - replaced MarshalledValue calls with SessionSerializationFactory calls
+ // to allow for switching between JBossSerialization and JavaSerialization using
+ // system property -D=session.serialization.jboss=true / false
+ // MarshalledValue mv = new MarshalledValue(value);
+ if (SessionSerializationFactory.useJBossSerialization())
{
- log_.trace("marshalled object to size " + mv.size() + " bytes");
+ MarshalledObject mo = SessionSerializationFactory.createMarshalledObject(value);
+ if (log_.isTraceEnabled())
+ {
+ log_.trace("JBoss Marshalled Object to size ");
+ }
+ return mo;
+
}
- return mv;
+ else
+ {
+ MarshalledValue mv = SessionSerializationFactory.createMarshalledValue(value);
+ if (log_.isTraceEnabled())
+ {
+ log_.trace("marshalled object to size " + mv.size() + " bytes");
+ }
+ return mv;
+ }
+
}
catch (IOException e)
{
@@ -1050,7 +1070,18 @@
Thread.currentThread().setContextClassLoader(manager_.getWebappClassLoader());
try
{
- return ((MarshalledValue) mv).get();
+ // JBAS-2921 - replaced MarshalledValue calls with SessionSerializationFactory calls
+ // to allow for switching between JBossSerialization and JavaSerialization using
+ // system property -D=session.serialization.jboss=true / false
+
+ if (SessionSerializationFactory.useJBossSerialization())
+ {
+ return ((MarshalledObject)mv).get();
+ }
+ else
+ {
+ return ((MarshalledValue) mv).get();
+ }
}
catch (IOException e)
{
@@ -1077,7 +1108,14 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Use MarshalledValueOutputStream instead of superclass ObjectOutputStream
// or else there are problems finding classes with scoped loaders
- MarshalledValueOutputStream oos = new MarshalledValueOutputStream(baos);
+
+ // JBAS-2921 - replaced MarshalledValue calls with SessionSerializationFactory calls
+ // to allow for switching between JBossSerialization and JavaSerialization using
+ // system property -D=session.serialization.jboss=true / false
+
+ // MarshalledValueOutputStream oos = new MarshalledValueOutputStream(baos);
+
+ ObjectOutputStream oos = SessionSerializationFactory.createObjectOutputStream(baos);
session.writeExternal(oos);
oos.close(); // flushes bytes to baos
@@ -1085,7 +1123,7 @@
if (log_.isTraceEnabled())
{
- log_.trace("marshalled object to size " + bytes.length + " bytes");
+ log_.trace("Serialized Object to size " + bytes.length + " bytes");
}
return bytes;
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/SessionSerializationFactory.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/SessionSerializationFactory.java 2006-08-30 14:08:53 UTC (rev 56443)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/SessionSerializationFactory.java 2006-08-30 14:48:44 UTC (rev 56444)
@@ -0,0 +1,101 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This 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.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.web.tomcat.tc6.session;
+
+import org.jboss.invocation.MarshalledValueInputStream;
+import org.jboss.invocation.MarshalledValueOutputStream;
+import org.jboss.invocation.MarshalledValue;
+import org.jboss.logging.Logger;
+import org.jboss.serial.io.JBossObjectInputStreamSharedTree;
+import org.jboss.serial.io.JBossObjectOutputStreamSharedTree;
+import org.jboss.serial.io.MarshalledObject;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+/**
+ * Factory class for creating object output and input streams,
+ * switching between JDK Serialization and JBoss Serialization classes.
+ * Using MarshalledValue to replace Serializable used inside different
+ * web app class loader context. Assuming that the caller classes are already
+ * handling the switch between web app class loader context.
+ *
+ *
+ * @author <a href="hmesha at novell.com">Hany Mesha</a>
+ */
+public class SessionSerializationFactory
+{
+ static Logger log_ = Logger.getLogger(SessionSerializationFactory.class);
+ static boolean useJBossSerialization = false;
+
+ static
+ {
+ String useJBossSerializationStr = System.getProperty("session.serialization.jboss", "true");
+ useJBossSerialization = Boolean.valueOf(useJBossSerializationStr).booleanValue();
+ }
+
+ public static ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException
+ {
+ if (log_.isDebugEnabled())
+ {
+ log_.debug("createObjectOutputStream using JBossSerialization = " + useJBossSerialization);
+ }
+ return useJBossSerialization ? new JBossObjectOutputStreamSharedTree(out) : new MarshalledValueOutputStream(out);
+ }
+
+ public static ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException
+ {
+ if (log_.isDebugEnabled())
+ {
+ log_.debug("createObjectInputStream using JBossSerialization = " + useJBossSerialization);
+ }
+ ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+ return useJBossSerialization ? new JBossObjectInputStreamSharedTree(in) : new MarshalledValueInputStream(in);
+ }
+
+ public static MarshalledValue createMarshalledValue(Object o) throws IOException
+ {
+ if (log_.isDebugEnabled())
+ {
+ log_.debug("createMarshalledValue using JBossSerialization = " + useJBossSerialization);
+ }
+ return new MarshalledValue (o);
+ }
+
+ public static MarshalledObject createMarshalledObject(Object o) throws IOException
+ {
+ if (log_.isDebugEnabled())
+ {
+ log_.debug("createMarshalledObject using JBossSerialization = " + useJBossSerialization);
+ }
+ return new MarshalledObject(o);
+ }
+
+ public static boolean useJBossSerialization()
+ {
+ return useJBossSerialization;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list