[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...
Manik Surtani
msurtani at jboss.com
Thu Nov 2 04:28:03 EST 2006
User: msurtani
Date: 06/11/02 04:28:03
Modified: src/org/jboss/cache/marshall Tag:
Branch_JBossCache_1_4_0
ObjectSerializationFactory.java
Added: src/org/jboss/cache/marshall Tag:
Branch_JBossCache_1_4_0
JBossObjectStreamFactory.java
ObjectStreamFactory.java
JavaObjectStreamFactory.java
Removed: src/org/jboss/cache/marshall Tag:
Branch_JBossCache_1_4_0
JBossObjectInputStreamOverride.java
Log:
Object serialization factory improvements
Revision Changes Path
No revision
No revision
1.15.2.2 +15 -27 JBossCache/src/org/jboss/cache/marshall/ObjectSerializationFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ObjectSerializationFactory.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/ObjectSerializationFactory.java,v
retrieving revision 1.15.2.1
retrieving revision 1.15.2.2
diff -u -b -r1.15.2.1 -r1.15.2.2
--- ObjectSerializationFactory.java 31 Oct 2006 23:44:46 -0000 1.15.2.1
+++ ObjectSerializationFactory.java 2 Nov 2006 09:28:03 -0000 1.15.2.2
@@ -8,14 +8,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.invocation.MarshalledValueInputStream;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
-import java.lang.reflect.Constructor;
/**
* Factory class for creating object output and inut streams, switching between JDK defaults and JBoss Serialization classes.
@@ -28,45 +25,36 @@
static boolean useJBossSerialization = false;
private static Log log = LogFactory.getLog(ObjectSerializationFactory.class);
+ private static ObjectStreamFactory factory = new JavaObjectStreamFactory();
static
{
String useJBossSerializationStr = System.getProperty("serialization.jboss", "true");
useJBossSerialization = Boolean.valueOf(useJBossSerializationStr).booleanValue();
- }
- public static ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException
+ try
{
- //return useJBossSerialization ? new JBossObjectOutputStreamSharedTree(out) : new ObjectOutputStream(out);
-
if (useJBossSerialization)
{
- try
- {
- Constructor c = ObjectSerializationFactory.class.getClassLoader().loadClass("org.jboss.serial.io.JBossObjectOutputStreamSharedTree").getConstructor(new Class[]{OutputStream.class});
- return (ObjectOutputStream) c.newInstance(new Object[]{out});
+ factory = (ObjectStreamFactory) Class.forName("org.jboss.cache.marshall.JBossObjectStreamFactory").newInstance();
+ }
}
catch (Exception e)
{
- log.error("Unable to create instance of org.jboss.serial.io.JBossObjectOutputStreamSharedTree - perhaps the JBoss Serialization jar is not in your classpath?", e);
- log.warn("Falling back to using (slower) Java serialization.");
+ log.error("Unable to load JBossObjectStreamFactory. Perhaps jboss-serialization jar not loaded?", e);
+ log.error("Falling back to java serialization.");
+
}
}
- return new ObjectOutputStream(out);
+ public static ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException
+ {
+ return factory.createObjectOutputStream(out);
}
public static ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException
{
- ByteArrayInputStream in = new ByteArrayInputStream(bytes);
- if (useJBossSerialization)
- {
- return new JBossObjectInputStreamOverride(in);
- }
- else
- {
- return new MarshalledValueInputStream(in);
- }
+ return factory.createObjectInputStream(bytes);
}
public static boolean useJBossSerialization()
No revision
No revision
1.1.2.1 +55 -0 JBossCache/src/org/jboss/cache/marshall/Attic/JBossObjectStreamFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JBossObjectStreamFactory.java
===================================================================
RCS file: JBossObjectStreamFactory.java
diff -N JBossObjectStreamFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ JBossObjectStreamFactory.java 2 Nov 2006 09:28:03 -0000 1.1.2.1
@@ -0,0 +1,55 @@
+package org.jboss.cache.marshall;
+
+import org.jboss.serial.io.JBossObjectInputStreamSharedTree;
+import org.jboss.serial.io.JBossObjectOutputStreamSharedTree;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Clebert Suconic
+ * @since 1.4.1
+ */
+class JBossObjectStreamFactory implements ObjectStreamFactory
+{
+ static class JBossObjectInputStreamOverride extends JBossObjectInputStreamSharedTree
+ {
+
+ public JBossObjectInputStreamOverride(InputStream input) throws IOException
+ {
+ super(input);
+ }
+
+ public Object readObjectOverride() throws IOException, ClassNotFoundException
+ {
+ ClassLoader older = this.getClassLoader();
+ try
+ {
+ this.setClassLoader(Thread.currentThread().getContextClassLoader());
+ return super.readObjectOverride();
+ }
+ finally
+ {
+ this.setClassLoader(older);
+ }
+ }
+
+ }
+
+
+ public ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+ return new JBossObjectInputStreamOverride(in);
+ }
+
+ public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException
+ {
+ return new JBossObjectOutputStreamSharedTree(out);
+ }
+
+}
1.1.2.1 +17 -0 JBossCache/src/org/jboss/cache/marshall/Attic/ObjectStreamFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ObjectStreamFactory.java
===================================================================
RCS file: ObjectStreamFactory.java
diff -N ObjectStreamFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ObjectStreamFactory.java 2 Nov 2006 09:28:03 -0000 1.1.2.1
@@ -0,0 +1,17 @@
+package org.jboss.cache.marshall;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Clebert Suconic
+ * @since 1.4.1
+ */
+public interface ObjectStreamFactory
+{
+ public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException;
+
+ public ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException;
+}
1.1.2.1 +29 -0 JBossCache/src/org/jboss/cache/marshall/Attic/JavaObjectStreamFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JavaObjectStreamFactory.java
===================================================================
RCS file: JavaObjectStreamFactory.java
diff -N JavaObjectStreamFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ JavaObjectStreamFactory.java 2 Nov 2006 09:28:03 -0000 1.1.2.1
@@ -0,0 +1,29 @@
+package org.jboss.cache.marshall;
+
+import org.jboss.invocation.MarshalledValueInputStream;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Clebert Suconic
+ * @since 1.4.1
+ */
+class JavaObjectStreamFactory implements ObjectStreamFactory
+{
+
+ public ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+ return new MarshalledValueInputStream(in);
+ }
+
+ public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException
+ {
+ return new ObjectOutputStream(out);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list