[jboss-cvs] JBossAS SVN: r72876 - projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 29 18:26:33 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-04-29 18:26:32 -0400 (Tue, 29 Apr 2008)
New Revision: 72876
Added:
projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/MarshalledValueObjectStreamSource.java
Modified:
projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/SimpleCachableMarshalledValue.java
Log:
[JBCLUSTER-198] JBoss Serialization support for SimpleCachableMarshalledValue
Added: projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/MarshalledValueObjectStreamSource.java
===================================================================
--- projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/MarshalledValueObjectStreamSource.java (rev 0)
+++ projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/MarshalledValueObjectStreamSource.java 2008-04-29 22:26:32 UTC (rev 72876)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ha.framework.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.OutputStream;
+
+import org.jboss.ha.framework.interfaces.ObjectStreamSource;
+import org.jboss.util.stream.MarshalledValueInputStream;
+import org.jboss.util.stream.MarshalledValueOutputStream;
+
+/**
+ * {@link ObjectStreamSource} implementation that provides
+ * {@link MarshalledValueInputStream} and {@link MarshalledValueOutputStream}.
+ *
+ * @author Brian Stansberry
+ */
+public class MarshalledValueObjectStreamSource implements ObjectStreamSource
+{
+
+ public ObjectInput getObjectInput(InputStream source) throws IOException
+ {
+ return new MarshalledValueInputStream(source);
+ }
+
+ public ObjectOutput getObjectOutput(OutputStream target) throws IOException
+ {
+ return new MarshalledValueOutputStream(target);
+ }
+
+}
Modified: projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/SimpleCachableMarshalledValue.java
===================================================================
--- projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/SimpleCachableMarshalledValue.java 2008-04-29 21:26:53 UTC (rev 72875)
+++ projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/SimpleCachableMarshalledValue.java 2008-04-29 22:26:32 UTC (rev 72876)
@@ -30,8 +30,7 @@
import java.util.Arrays;
import org.jboss.ha.framework.interfaces.CachableMarshalledValue;
-import org.jboss.util.stream.MarshalledValueInputStream;
-import org.jboss.util.stream.MarshalledValueOutputStream;
+import org.jboss.ha.framework.interfaces.ObjectStreamSource;
/**
* Variation on the standard JBoss <code>org.jboss.invocation.MarshalledValue</code>
@@ -56,6 +55,8 @@
private Serializable raw;
private int hashCode;
+
+ private transient ObjectStreamSource objectStreamSource;
/**
* Exposed for externalization.
@@ -74,6 +75,12 @@
}
}
+ public SimpleCachableMarshalledValue(Serializable obj, ObjectStreamSource streamSource)
+ {
+ this(obj);
+ this.objectStreamSource = streamSource;
+ }
+
public synchronized Serializable get() throws IOException, ClassNotFoundException
{
if (raw == null)
@@ -81,7 +88,7 @@
if (serializedForm != null)
{
ByteArrayInputStream bais = new ByteArrayInputStream(serializedForm);
- MarshalledValueInputStream mvis = new MarshalledValueInputStream(bais);
+ ObjectInput mvis = getObjectStreamSource().getObjectInput(bais);
try
{
raw = (Serializable) mvis.readObject();
@@ -108,31 +115,6 @@
return serializedForm;
}
- private byte[] serialize() throws IOException
- {
- byte[] result = serializedForm;
- if (result == null)
- {
- if (raw != null)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- MarshalledValueOutputStream mvos = new MarshalledValueOutputStream(baos);
- mvos.writeObject(raw);
- mvos.flush();
- try
- {
- result = baos.toByteArray();
- }
- finally
- {
- mvos.close();
- }
- }
-
- }
- return result;
- }
-
public Serializable peekUnderlyingObject()
{
return raw;
@@ -143,6 +125,20 @@
return serializedForm;
}
+ public ObjectStreamSource getObjectStreamSource()
+ {
+ if (objectStreamSource == null)
+ {
+ objectStreamSource = new MarshalledValueObjectStreamSource();
+ }
+ return objectStreamSource;
+ }
+
+ public void setObjectStreamSource(ObjectStreamSource objectStreamSource)
+ {
+ this.objectStreamSource = objectStreamSource;
+ }
+
/**
* Return a hash code for the wrapped object.
*
@@ -262,4 +258,29 @@
}
out.writeInt(hashCode);
}
+
+ private byte[] serialize() throws IOException
+ {
+ byte[] result = serializedForm;
+ if (result == null)
+ {
+ if (raw != null)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutput mvos = getObjectStreamSource().getObjectOutput(baos);
+ mvos.writeObject(raw);
+ mvos.flush();
+ try
+ {
+ result = baos.toByteArray();
+ }
+ finally
+ {
+ mvos.close();
+ }
+ }
+
+ }
+ return result;
+ }
}
More information about the jboss-cvs-commits
mailing list