Author: manik.surtani(a)jboss.com
Date: 2009-03-01 07:05:53 -0500 (Sun, 01 Mar 2009)
New Revision: 7810
Added:
core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectInputStream.java
core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectOutputStream.java
Modified:
core/branches/flat/src/main/java/org/horizon/loader/CacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/ReadOnlyStore.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java
core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java
Log:
CacheStore stream API and Marshaller API to use ObjectInput and ObjectOutput interfaces
rather than ObjectInputStream and ObjectOutputStream impls.
Also added UnclosableOIS/OOS impls.
Added: core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectInputStream.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectInputStream.java
(rev 0)
+++
core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectInputStream.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -0,0 +1,106 @@
+package org.horizon.io;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+
+/**
+ * A delegating {@link java.io.ObjectInput} that delegates all methods except {@link
ObjectInput#close()}.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class UnclosableObjectInputStream implements ObjectInput {
+ private final ObjectInput delegate;
+
+ public UnclosableObjectInputStream(ObjectInput delegate) {
+ this.delegate = delegate;
+ }
+
+ public final Object readObject() throws ClassNotFoundException, IOException {
+ return delegate.readObject();
+ }
+
+ public final int read() throws IOException {
+ return delegate.read();
+ }
+
+ public final int read(byte[] b) throws IOException {
+ return delegate.read(b);
+ }
+
+ public final int read(byte[] b, int off, int len) throws IOException {
+ return delegate.read(b, off, len);
+ }
+
+ public final long skip(long n) throws IOException {
+ return delegate.skip(n);
+ }
+
+ public final int available() throws IOException {
+ return delegate.available();
+ }
+
+ public final void close() throws IOException {
+ throw new UnsupportedOperationException("close() is not supported in an
UnclosableObjectInputStream!");
+ }
+
+ public final void readFully(byte[] b) throws IOException {
+ delegate.readFully(b);
+ }
+
+ public final void readFully(byte[] b, int off, int len) throws IOException {
+ delegate.readFully(b, off, len);
+ }
+
+ public final int skipBytes(int n) throws IOException {
+ return delegate.skipBytes(n);
+ }
+
+ public final boolean readBoolean() throws IOException {
+ return delegate.readBoolean();
+ }
+
+ public final byte readByte() throws IOException {
+ return delegate.readByte();
+ }
+
+ public final int readUnsignedByte() throws IOException {
+ return delegate.readUnsignedByte();
+ }
+
+ public final short readShort() throws IOException {
+ return delegate.readShort();
+ }
+
+ public final int readUnsignedShort() throws IOException {
+ return delegate.readUnsignedShort();
+ }
+
+ public final char readChar() throws IOException {
+ return delegate.readChar();
+ }
+
+ public final int readInt() throws IOException {
+ return delegate.readInt();
+ }
+
+ public final long readLong() throws IOException {
+ return delegate.readLong();
+ }
+
+ public final float readFloat() throws IOException {
+ return delegate.readFloat();
+ }
+
+ public final double readDouble() throws IOException {
+ return delegate.readDouble();
+ }
+
+ public final String readLine() throws IOException {
+ return delegate.readLine();
+ }
+
+ public final String readUTF() throws IOException {
+ return delegate.readUTF();
+ }
+}
Added: core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectOutputStream.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectOutputStream.java
(rev 0)
+++
core/branches/flat/src/main/java/org/horizon/io/UnclosableObjectOutputStream.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -0,0 +1,88 @@
+package org.horizon.io;
+
+import java.io.IOException;
+import java.io.ObjectOutput;
+
+/**
+ * An unclosable version of an {@link java.io.ObjectOutput}. This delegates all methods
except {@link #flush()} and
+ * {@link #close()}.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class UnclosableObjectOutputStream implements ObjectOutput {
+
+ private final ObjectOutput delegate;
+
+ public UnclosableObjectOutputStream(ObjectOutput delegate) {
+ this.delegate = delegate;
+ }
+
+ public final void writeObject(Object obj) throws IOException {
+ delegate.writeObject(obj);
+ }
+
+ public final void write(int b) throws IOException {
+ delegate.write(b);
+ }
+
+ public final void write(byte[] b) throws IOException {
+ delegate.write(b);
+ }
+
+ public final void write(byte[] b, int off, int len) throws IOException {
+ delegate.write(b, off, len);
+ }
+
+ public final void writeBoolean(boolean v) throws IOException {
+ delegate.writeBoolean(v);
+ }
+
+ public final void writeByte(int v) throws IOException {
+ delegate.writeByte(v);
+ }
+
+ public final void writeShort(int v) throws IOException {
+ delegate.writeShort(v);
+ }
+
+ public final void writeChar(int v) throws IOException {
+ delegate.writeChar(v);
+ }
+
+ public final void writeInt(int v) throws IOException {
+ delegate.writeInt(v);
+ }
+
+ public final void writeLong(long v) throws IOException {
+ delegate.writeLong(v);
+ }
+
+ public final void writeFloat(float v) throws IOException {
+ delegate.writeFloat(v);
+ }
+
+ public final void writeDouble(double v) throws IOException {
+ delegate.writeDouble(v);
+ }
+
+ public final void writeBytes(String s) throws IOException {
+ delegate.writeBytes(s);
+ }
+
+ public final void writeChars(String s) throws IOException {
+ delegate.writeChars(s);
+ }
+
+ public final void writeUTF(String str) throws IOException {
+ delegate.writeUTF(str);
+ }
+
+ public final void flush() throws IOException {
+ throw new UnsupportedOperationException("flush() not supported in an
UnclosableObjectOutputStream!");
+ }
+
+ public final void close() throws IOException {
+ throw new UnsupportedOperationException("close() not supported in an
UnclosableObjectOutputStream!");
+ }
+}
Modified: core/branches/flat/src/main/java/org/horizon/loader/CacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/CacheStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++ core/branches/flat/src/main/java/org/horizon/loader/CacheStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -3,8 +3,8 @@
import org.horizon.loader.modifications.Modification;
import javax.transaction.Transaction;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.List;
import java.util.Set;
@@ -26,26 +26,26 @@
/**
* Writes contents of the stream to the store. Implementations should expect that the
stream contains data in an
- * implementation-specific format, typically generated using {@link
#toStream(java.io.ObjectOutputStream)}. While
- * not a requirement, it is recommended that implementations make use of the {@link
org.horizon.marshall.Marshaller}
- * when dealing with the stream to make use of efficient marshalling.
+ * implementation-specific format, typically generated using {@link
#toStream(java.io.ObjectOutput)}. While not a
+ * requirement, it is recommended that implementations make use of the {@link
org.horizon.marshall.Marshaller} when
+ * dealing with the stream to make use of efficient marshalling.
* <p/>
* It is imperative that implementations <b><i>do not</i></b>
close the stream after finishing with it.
* <p/>
* It is also <b><i>recommended</b></i> that implementations
use their own start and end markers on the stream since
* other processes may write additional data to the stream after the cache store has
written to it. As such, either
* markers or some other mechanism to prevent the store from reading too much
information should be employed when
- * writing to the stream in {@link #fromStream(java.io.ObjectInputStream)} to prevent
data corruption.
+ * writing to the stream in {@link #fromStream(java.io.ObjectInput)} to prevent data
corruption.
* <p/>
*
* @param inputStream stream to read from
* @throws CacheLoaderException in the event of problems writing to the store
*/
- void fromStream(ObjectInputStream inputStream) throws CacheLoaderException;
+ void fromStream(ObjectInput inputStream) throws CacheLoaderException;
/**
* Loads the entire state into a stream, using whichever format is most efficient for
the cache loader
- * implementation. Typically read and parsed by {@link
#fromStream(java.io.ObjectInputStream)}.
+ * implementation. Typically read and parsed by {@link
#fromStream(java.io.ObjectInput)}.
* <p/>
* While not a requirement, it is recommended that implementations make use of the
{@link
* org.horizon.marshall.Marshaller} when dealing with the stream to make use of
efficient marshalling.
@@ -55,13 +55,13 @@
* It is also <b><i>recommended</b></i> that implementations
use their own start and end markers on the stream since
* other processes may write additional data to the stream after the cache store has
written to it. As such, either
* markers or some other mechanism to prevent the store from reading too much
information in {@link
- * #fromStream(java.io.ObjectInputStream)} should be employed, to prevent data
corruption.
+ * #fromStream(java.io.ObjectInput)} should be employed, to prevent data corruption.
* <p/>
*
* @param outputStream stream to write to
* @throws CacheLoaderException in the event of problems reading from the store
*/
- void toStream(ObjectOutputStream outputStream) throws CacheLoaderException;
+ void toStream(ObjectOutput outputStream) throws CacheLoaderException;
/**
* Clears all entries in the store
Modified:
core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -11,8 +11,8 @@
import org.horizon.marshall.Marshaller;
import org.horizon.util.concurrent.WithinThreadExecutor;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -126,7 +126,7 @@
}
}
- public void fromStream(ObjectInputStream inputStream) throws CacheLoaderException {
+ public void fromStream(ObjectInput inputStream) throws CacheLoaderException {
try {
// first clear all local state
acquireGlobalLock(true);
@@ -137,7 +137,7 @@
}
}
- public void toStream(ObjectOutputStream outputStream) throws CacheLoaderException {
+ public void toStream(ObjectOutput outputStream) throws CacheLoaderException {
try {
acquireGlobalLock(true);
toStreamInternal(outputStream);
@@ -237,9 +237,9 @@
protected abstract Bucket loadBucket(String keyHashCode) throws CacheLoaderException;
- protected abstract void toStreamInternal(ObjectOutputStream oos) throws
CacheLoaderException;
+ protected abstract void toStreamInternal(ObjectOutput oos) throws
CacheLoaderException;
- protected abstract void fromStreamInternal(ObjectInputStream ois) throws
CacheLoaderException;
+ protected abstract void fromStreamInternal(ObjectInput ois) throws
CacheLoaderException;
protected abstract void clearInternal() throws CacheLoaderException;
Modified:
core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -10,8 +10,8 @@
import org.horizon.marshall.Marshaller;
import javax.transaction.Transaction;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.List;
import java.util.Set;
@@ -42,11 +42,11 @@
delegate.store(ed);
}
- public void fromStream(ObjectInputStream inputStream) throws CacheLoaderException {
+ public void fromStream(ObjectInput inputStream) throws CacheLoaderException {
delegate.fromStream(inputStream);
}
- public void toStream(ObjectOutputStream outputStream) throws CacheLoaderException {
+ public void toStream(ObjectOutput outputStream) throws CacheLoaderException {
delegate.toStream(outputStream);
}
Modified:
core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -10,8 +10,8 @@
import org.horizon.marshall.Marshaller;
import javax.transaction.Transaction;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -39,7 +39,7 @@
for (CacheStore s : stores.keySet()) s.store(ed);
}
- public void fromStream(ObjectInputStream inputStream) throws CacheLoaderException {
+ public void fromStream(ObjectInput inputStream) throws CacheLoaderException {
// loading and storing state via streams is *only* supported on the *first* store
that has fetchPersistentState set.
for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
if (e.getValue().isFetchPersistentState()) {
@@ -50,7 +50,7 @@
}
}
- public void toStream(ObjectOutputStream outputStream) throws CacheLoaderException {
+ public void toStream(ObjectOutput outputStream) throws CacheLoaderException {
// loading and storing state via streams is *only* supported on the *first* store
that has fetchPersistentState set.
for (Map.Entry<CacheStore, CacheLoaderConfig> e : stores.entrySet()) {
if (e.getValue().isFetchPersistentState()) {
Modified:
core/branches/flat/src/main/java/org/horizon/loader/decorators/ReadOnlyStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/decorators/ReadOnlyStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/loader/decorators/ReadOnlyStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -5,7 +5,7 @@
import org.horizon.loader.modifications.Modification;
import javax.transaction.Transaction;
-import java.io.ObjectInputStream;
+import java.io.ObjectInput;
import java.util.List;
/**
@@ -27,7 +27,7 @@
}
@Override
- public void fromStream(ObjectInputStream inputStream) {
+ public void fromStream(ObjectInput inputStream) {
// no-op
}
Modified:
core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -17,7 +17,7 @@
import org.horizon.remoting.transport.Address;
import javax.transaction.Transaction;
-import java.io.ObjectInputStream;
+import java.io.ObjectInput;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
@@ -112,7 +112,7 @@
}
@Override
- public void fromStream(ObjectInputStream inputStream) throws CacheLoaderException {
+ public void fromStream(ObjectInput inputStream) throws CacheLoaderException {
if (active) super.fromStream(inputStream);
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -11,14 +11,7 @@
import org.horizon.logging.LogFactory;
import org.horizon.marshall.Marshaller;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.*;
import java.util.HashSet;
import java.util.Set;
@@ -81,7 +74,7 @@
return result;
}
- protected void fromStreamInternal(ObjectInputStream ois) throws CacheLoaderException
{
+ protected void fromStreamInternal(ObjectInput ois) throws CacheLoaderException {
try {
int numFiles = ois.readInt();
byte[] buffer = new byte[streamBufferSize];
@@ -111,7 +104,7 @@
}
}
- protected void toStreamInternal(ObjectOutputStream oos) throws CacheLoaderException {
+ protected void toStreamInternal(ObjectOutput oos) throws CacheLoaderException {
try {
File[] files = root.listFiles();
oos.writeInt(files.length);
Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -13,8 +13,8 @@
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -190,7 +190,7 @@
}
}
- protected void fromStreamInternal(ObjectInputStream ois) throws CacheLoaderException
{
+ protected void fromStreamInternal(ObjectInput ois) throws CacheLoaderException {
Connection conn = null;
PreparedStatement ps = null;
try {
@@ -233,7 +233,7 @@
}
}
- protected void toStreamInternal(ObjectOutputStream oos) throws CacheLoaderException {
+ protected void toStreamInternal(ObjectOutput oos) throws CacheLoaderException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
@@ -375,13 +375,15 @@
ps.addBatch();
deletionCount++;
if (deletionCount % batchSize == 0) {
- if (log.isTraceEnabled()) log.trace("Flushing deletion batch, total
deletion count so far is " + deletionCount);
+ if (log.isTraceEnabled())
+ log.trace("Flushing deletion batch, total deletion count so far is
" + deletionCount);
ps.executeBatch();
}
}
if (deletionCount % batchSize != 0) {
int[] batchResult = ps.executeBatch();
- if (log.isTraceEnabled()) log.trace("Flushed the batch and received
following results: " + Arrays.toString(batchResult));
+ if (log.isTraceEnabled())
+ log.trace("Flushed the batch and received following results: " +
Arrays.toString(batchResult));
}
} catch (SQLException ex) {
//if something happens make sure buckets locks are being release
Modified: core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -40,7 +40,8 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
@@ -111,7 +112,7 @@
return bytes;
}
- protected void marshallObject(Object o, ObjectOutputStream out, Map<Object,
Integer> refMap) throws IOException {
+ protected void marshallObject(Object o, ObjectOutput out, Map<Object, Integer>
refMap) throws IOException {
if (o != null && o.getClass().isArray() &&
isKnownType(o.getClass().getComponentType())) {
marshallArray(o, out, refMap);
} else {
@@ -202,12 +203,12 @@
}
- protected void marshallString(String s, ObjectOutputStream out) throws IOException {
+ protected void marshallString(String s, ObjectOutput out) throws IOException {
//StringUtil.saveString(out, s);
out.writeObject(s);
}
- private void marshallCommand(ReplicableCommand command, ObjectOutputStream out,
Map<Object, Integer> refMap) throws IOException {
+ private void marshallCommand(ReplicableCommand command, ObjectOutput out,
Map<Object, Integer> refMap) throws IOException {
out.writeShort(command.getCommandId());
Object[] args = command.getParameters();
byte numArgs = (byte) (args == null ? 0 : args.length);
@@ -224,17 +225,17 @@
return reference;
}
- private void marshallGlobalTransaction(GlobalTransaction globalTransaction,
ObjectOutputStream out, Map<Object, Integer> refMap) throws IOException {
+ private void marshallGlobalTransaction(GlobalTransaction globalTransaction,
ObjectOutput out, Map<Object, Integer> refMap) throws IOException {
out.writeLong(globalTransaction.getId());
marshallObject(globalTransaction.getAddress(), out, refMap);
}
- private void marshallJGroupsAddress(JGroupsAddress address, ObjectOutputStream out)
throws IOException {
+ private void marshallJGroupsAddress(JGroupsAddress address, ObjectOutput out) throws
IOException {
address.writeExternal(out);
}
@SuppressWarnings("unchecked")
- private void marshallCollection(Collection c, ObjectOutputStream out, Map refMap)
throws IOException {
+ private void marshallCollection(Collection c, ObjectOutput out, Map refMap) throws
IOException {
writeUnsignedInt(out, c.size());
for (Object o : c) {
marshallObject(o, out, refMap);
@@ -242,7 +243,7 @@
}
@SuppressWarnings("unchecked")
- private void marshallMap(Map map, ObjectOutputStream out, Map<Object, Integer>
refMap) throws IOException {
+ private void marshallMap(Map map, ObjectOutput out, Map<Object, Integer> refMap)
throws IOException {
int mapSize = map.size();
writeUnsignedInt(out, mapSize);
if (mapSize == 0) return;
@@ -255,7 +256,7 @@
// --------- Unmarshalling methods
- protected Object unmarshallObject(ObjectInputStream in, ClassLoader loader,
UnmarshalledReferences refMap, boolean overrideContextClassloaderOnThread) throws
IOException, ClassNotFoundException {
+ protected Object unmarshallObject(ObjectInput in, ClassLoader loader,
UnmarshalledReferences refMap, boolean overrideContextClassloaderOnThread) throws
IOException, ClassNotFoundException {
if (loader == null) {
return unmarshallObject(in, refMap);
} else {
@@ -272,7 +273,7 @@
}
}
- protected Object unmarshallObject(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ protected Object unmarshallObject(ObjectInput in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
byte magicNumber = in.readByte();
int reference = 0;
Object retVal;
@@ -346,17 +347,17 @@
throw new IOException("Unknown magic number " + magicNumber);
}
- private FastCopyHashMap unmarshallFastCopyHashMap(ObjectInputStream in,
UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
+ private FastCopyHashMap unmarshallFastCopyHashMap(ObjectInput in,
UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
FastCopyHashMap map = new FastCopyHashMap();
populateFromStream(in, refMap, map);
return map;
}
- protected String unmarshallString(ObjectInputStream in) throws IOException,
ClassNotFoundException {
+ protected String unmarshallString(ObjectInput in) throws IOException,
ClassNotFoundException {
return (String) in.readObject();
}
- private ReplicableCommand unmarshallCommand(ObjectInputStream in,
UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
+ private ReplicableCommand unmarshallCommand(ObjectInput in, UnmarshalledReferences
refMap) throws IOException, ClassNotFoundException {
short methodId = in.readShort();
byte numArgs = in.readByte();
Object[] args = null;
@@ -370,7 +371,7 @@
}
- private GlobalTransaction unmarshallGlobalTransaction(ObjectInputStream in,
UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
+ private GlobalTransaction unmarshallGlobalTransaction(ObjectInput in,
UnmarshalledReferences refMap) throws IOException, ClassNotFoundException {
GlobalTransaction gtx = new GlobalTransaction();
long id = in.readLong();
Object address = unmarshallObject(in, refMap);
@@ -379,74 +380,74 @@
return gtx;
}
- private JGroupsAddress unmarshallJGroupsAddress(ObjectInputStream in) throws
IOException, ClassNotFoundException {
+ private JGroupsAddress unmarshallJGroupsAddress(ObjectInput in) throws IOException,
ClassNotFoundException {
JGroupsAddress address = new JGroupsAddress();
address.readExternal(in);
return address;
}
- private List unmarshallArrayList(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ private List unmarshallArrayList(ObjectInput in, UnmarshalledReferences refMap) throws
IOException, ClassNotFoundException {
int listSize = readUnsignedInt(in);
List list = new ArrayList(listSize);
populateFromStream(in, refMap, list, listSize);
return list;
}
- private List unmarshallLinkedList(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ private List unmarshallLinkedList(ObjectInput in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
List list = new LinkedList();
populateFromStream(in, refMap, list, readUnsignedInt(in));
return list;
}
- private List unmarshallSingletonList(ObjectInputStream in, UnmarshalledReferences
refMap) throws IOException, ClassNotFoundException {
+ private List unmarshallSingletonList(ObjectInput in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
return Collections.singletonList(unmarshallObject(in, refMap));
}
- private Map unmarshallHashMap(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ private Map unmarshallHashMap(ObjectInput in, UnmarshalledReferences refMap) throws
IOException, ClassNotFoundException {
Map map = new HashMap();
populateFromStream(in, refMap, map);
return map;
}
@SuppressWarnings("unchecked")
- private Map unmarshallMapCopy(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ private Map unmarshallMapCopy(ObjectInput in, UnmarshalledReferences refMap) throws
IOException, ClassNotFoundException {
// read in as a HashMap first
Map m = unmarshallHashMap(in, refMap);
return Immutables.immutableMapWrap(m);
}
- private Map unmarshallTreeMap(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ private Map unmarshallTreeMap(ObjectInput in, UnmarshalledReferences refMap) throws
IOException, ClassNotFoundException {
Map map = new TreeMap();
populateFromStream(in, refMap, map);
return map;
}
- private Set unmarshallHashSet(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ private Set unmarshallHashSet(ObjectInput in, UnmarshalledReferences refMap) throws
IOException, ClassNotFoundException {
Set set = new HashSet();
populateFromStream(in, refMap, set);
return set;
}
- private Set unmarshallTreeSet(ObjectInputStream in, UnmarshalledReferences refMap)
throws IOException, ClassNotFoundException {
+ private Set unmarshallTreeSet(ObjectInput in, UnmarshalledReferences refMap) throws
IOException, ClassNotFoundException {
Set set = new TreeSet();
populateFromStream(in, refMap, set);
return set;
}
@SuppressWarnings("unchecked")
- private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap,
Map mapToPopulate) throws IOException, ClassNotFoundException {
+ private void populateFromStream(ObjectInput in, UnmarshalledReferences refMap, Map
mapToPopulate) throws IOException, ClassNotFoundException {
int size = readUnsignedInt(in);
for (int i = 0; i < size; i++) mapToPopulate.put(unmarshallObject(in, refMap),
unmarshallObject(in, refMap));
}
@SuppressWarnings("unchecked")
- private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap,
Set setToPopulate) throws IOException, ClassNotFoundException {
+ private void populateFromStream(ObjectInput in, UnmarshalledReferences refMap, Set
setToPopulate) throws IOException, ClassNotFoundException {
int size = readUnsignedInt(in);
for (int i = 0; i < size; i++) setToPopulate.add(unmarshallObject(in, refMap));
}
@SuppressWarnings("unchecked")
- private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap,
List listToPopulate, int listSize) throws IOException, ClassNotFoundException {
+ private void populateFromStream(ObjectInput in, UnmarshalledReferences refMap, List
listToPopulate, int listSize) throws IOException, ClassNotFoundException {
for (int i = 0; i < listSize; i++) listToPopulate.add(unmarshallObject(in,
refMap));
}
@@ -459,7 +460,7 @@
* @throws java.io.IOException propagated from OOS
* @see <a
href="http://jira.jboss.org/jira/browse/JBCACHE-1211">JBCACH...
*/
- protected void writeReference(ObjectOutputStream out, int reference) throws
IOException {
+ protected void writeReference(ObjectOutput out, int reference) throws IOException {
writeUnsignedInt(out, reference);
}
@@ -472,7 +473,7 @@
* @throws java.io.IOException propagated from OUS
* @see <a
href="http://jira.jboss.org/jira/browse/JBCACHE-1211">JBCACH...
*/
- protected int readReference(ObjectInputStream in) throws IOException {
+ protected int readReference(ObjectInput in) throws IOException {
return readUnsignedInt(in);
}
@@ -480,7 +481,7 @@
* Reads an int stored in variable-length format. Reads between one and five bytes.
Smaller values take fewer
* bytes. Negative numbers are not supported.
*/
- protected int readUnsignedInt(ObjectInputStream in) throws IOException {
+ protected int readUnsignedInt(ObjectInput in) throws IOException {
byte b = in.readByte();
int i = b & 0x7F;
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
@@ -496,7 +497,7 @@
*
* @param i int to write
*/
- protected void writeUnsignedInt(ObjectOutputStream out, int i) throws IOException {
+ protected void writeUnsignedInt(ObjectOutput out, int i) throws IOException {
while ((i & ~0x7F) != 0) {
out.writeByte((byte) ((i & 0x7f) | 0x80));
i >>>= 7;
@@ -509,7 +510,7 @@
* Reads an int stored in variable-length format. Reads between one and nine bytes.
Smaller values take fewer
* bytes. Negative numbers are not supported.
*/
- protected long readUnsignedLong(ObjectInputStream in) throws IOException {
+ protected long readUnsignedLong(ObjectInput in) throws IOException {
byte b = in.readByte();
long i = b & 0x7F;
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
@@ -525,7 +526,7 @@
*
* @param i int to write
*/
- protected void writeUnsignedLong(ObjectOutputStream out, long i) throws IOException {
+ protected void writeUnsignedLong(ObjectOutput out, long i) throws IOException {
while ((i & ~0x7F) != 0) {
out.writeByte((byte) ((i & 0x7f) | 0x80));
i >>>= 7;
@@ -533,7 +534,7 @@
out.writeByte((byte) i);
}
- protected Object unmarshallArray(ObjectInputStream in, UnmarshalledReferences refs)
throws IOException, ClassNotFoundException {
+ protected Object unmarshallArray(ObjectInput in, UnmarshalledReferences refs) throws
IOException, ClassNotFoundException {
int sz = readUnsignedInt(in);
byte type = in.readByte();
switch (type) {
@@ -650,7 +651,7 @@
}
}
- protected void marshallArray(Object o, ObjectOutputStream out, Map<Object,
Integer> refMap) throws IOException {
+ protected void marshallArray(Object o, ObjectOutput out, Map<Object, Integer>
refMap) throws IOException {
out.writeByte(MAGICNUMBER_ARRAY);
Class arrayTypeClass = o.getClass().getComponentType();
int sz = Array.getLength(o);
@@ -726,7 +727,7 @@
c.equals(Double.class));
}
- public void objectToObjectStream(Object o, ObjectOutputStream out) throws IOException
{
+ public void objectToObjectStream(Object o, ObjectOutput out) throws IOException {
Map<Object, Integer> refMap = useRefs ? new IdentityHashMap<Object,
Integer>() : null;
ClassLoader toUse = defaultClassLoader;
Thread current = Thread.currentThread();
@@ -742,7 +743,7 @@
}
}
- public Object objectFromObjectStream(ObjectInputStream in) throws IOException,
ClassNotFoundException {
+ public Object objectFromObjectStream(ObjectInput in) throws IOException,
ClassNotFoundException {
UnmarshalledReferences refMap = useRefs ? new UnmarshalledReferences() : null;
Object retValue = unmarshallObject(in, defaultClassLoader, refMap, false);
if (trace) log.trace("Unmarshalled object " + retValue);
@@ -755,7 +756,7 @@
public ByteBuffer objectToBuffer(Object o) throws IOException {
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(128);
- ObjectOutputStream out = new ObjectOutputStream(baos);
+ ObjectOutput out = new ObjectOutputStream(baos);
//now marshall the contents of the object
objectToObjectStream(o, out);
@@ -765,7 +766,7 @@
}
public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws
IOException, ClassNotFoundException {
- ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(buf,
offset, length));
+ ObjectInput in = new MarshalledValueInputStream(new ByteArrayInputStream(buf,
offset, length));
return objectFromObjectStream(in);
}
Modified: core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java 2009-03-01
11:33:40 UTC (rev 7809)
+++ core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -27,17 +27,16 @@
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
/**
* A marshaller is a class that is able to marshall and unmarshall objects efficiently.
* <p/>
- * The reason why this is implemented specially in Horizon rather than resorting to Java
serialization or even the
- * more efficient JBoss serialization is that a lot of efficiency can be gained when a
majority of the serialization
- * that occurs has to do with a small set of known types such as {@link
org.horizon.transaction.GlobalTransaction} or
- * {@link org.horizon.commands.ReplicableCommand}, and class type information can be
replaced with simple magic
- * numbers.
+ * The reason why this is implemented specially in Horizon rather than resorting to Java
serialization or even the more
+ * efficient JBoss serialization is that a lot of efficiency can be gained when a
majority of the serialization that
+ * occurs has to do with a small set of known types such as {@link
org.horizon.transaction.GlobalTransaction} or {@link
+ * org.horizon.commands.ReplicableCommand}, and class type information can be replaced
with simple magic numbers.
* <p/>
* Unknown types (typically user data) falls back to JBoss serialization.
* <p/>
@@ -58,19 +57,19 @@
@Scope(Scopes.GLOBAL)
public interface Marshaller {
/**
- * Marshalls an object to a given {@link java.io.ObjectOutputStream}
+ * Marshalls an object to a given {@link java.io.ObjectOutput}
*
* @param obj object to marshall
* @param out stream to marshall to
*/
- void objectToObjectStream(Object obj, ObjectOutputStream out) throws IOException;
+ void objectToObjectStream(Object obj, ObjectOutput out) throws IOException;
/**
- * Unmarshalls an object from an {@link java.io.ObjectInputStream}
+ * Unmarshalls an object from an {@link java.io.ObjectInput}
*
* @param in stream to unmarshall from
*/
- Object objectFromObjectStream(ObjectInputStream in) throws IOException,
ClassNotFoundException;
+ Object objectFromObjectStream(ObjectInput in) throws IOException,
ClassNotFoundException;
/**
* Unmarshalls an object from an {@link java.io.InputStream}
Modified:
core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/main/java/org/horizon/marshall/VersionAwareMarshaller.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -32,7 +32,9 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
/**
@@ -108,13 +110,13 @@
return defaultMarshaller.objectFromObjectStream(in);
}
- public void objectToObjectStream(Object obj, ObjectOutputStream out) throws
IOException {
+ public void objectToObjectStream(Object obj, ObjectOutput out) throws IOException {
out.writeShort(VERSION_100);
log.trace("Wrote version {0}", VERSION_100);
defaultMarshaller.objectToObjectStream(obj, out);
}
- public Object objectFromObjectStream(ObjectInputStream in) throws IOException,
ClassNotFoundException {
+ public Object objectFromObjectStream(ObjectInput in) throws IOException,
ClassNotFoundException {
int versionId;
try {
versionId = in.readShort();
Modified:
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -11,8 +11,8 @@
import org.horizon.marshall.Marshaller;
import org.horizon.marshall.ObjectStreamMarshaller;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -34,7 +34,7 @@
}
@SuppressWarnings("unchecked")
- public void fromStream(ObjectInputStream ois) throws CacheLoaderException {
+ public void fromStream(ObjectInput ois) throws CacheLoaderException {
try {
int numEntries = (Integer) marshaller.objectFromObjectStream(ois);
store.clear();
@@ -47,7 +47,7 @@
}
}
- public void toStream(ObjectOutputStream oos) throws CacheLoaderException {
+ public void toStream(ObjectOutput oos) throws CacheLoaderException {
try {
marshaller.objectToObjectStream(store.size(), oos);
for (StoredEntry se : store.values()) marshaller.objectToObjectStream(se, oos);
Modified:
core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java 2009-03-01
11:33:40 UTC (rev 7809)
+++
core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java 2009-03-01
12:05:53 UTC (rev 7810)
@@ -6,7 +6,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
/**
@@ -15,11 +17,11 @@
* @author Manik Surtani
*/
public class ObjectStreamMarshaller implements Marshaller {
- public void objectToObjectStream(Object obj, ObjectOutputStream out) throws
IOException {
+ public void objectToObjectStream(Object obj, ObjectOutput out) throws IOException {
out.writeObject(obj);
}
- public Object objectFromObjectStream(ObjectInputStream in) throws IOException,
ClassNotFoundException {
+ public Object objectFromObjectStream(ObjectInput in) throws IOException,
ClassNotFoundException {
return in.readObject();
}