Author: david.lloyd(a)jboss.com
Date: 2008-07-16 22:25:47 -0400 (Wed, 16 Jul 2008)
New Revision: 4376
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/AbstractSerializationUnmarshaller.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JavaSerializationUnmarshaller.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java
Log:
Add various marshaller bugfixes
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/AbstractSerializationUnmarshaller.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/AbstractSerializationUnmarshaller.java 2008-07-15
20:02:34 UTC (rev 4375)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/AbstractSerializationUnmarshaller.java 2008-07-17
02:25:47 UTC (rev 4376)
@@ -29,11 +29,14 @@
import java.util.concurrent.Executor;
import org.jboss.cx.remoting.spi.marshal.Unmarshaller;
import org.jboss.cx.remoting.spi.marshal.ObjectResolver;
+import org.jboss.xnio.log.Logger;
/**
*
*/
public abstract class AbstractSerializationUnmarshaller implements
Unmarshaller<ByteBuffer> {
+ private static final Logger log =
Logger.getLogger(AbstractSerializationUnmarshaller.class);
+
private final Executor executor;
private final ObjectInputStream objectInputStream;
private final Object resultLock = new Object();
@@ -41,7 +44,7 @@
protected final ObjectResolver resolver;
protected final OneBufferInputStream inputStream = new
OneBufferInputStream(resultLock);
- private boolean done;
+ private boolean done = true;
private Object result;
private Throwable cause;
@@ -54,19 +57,35 @@
protected abstract ObjectInputStream getObjectInputStream() throws IOException;
public boolean unmarshal(final ByteBuffer buffer) throws IOException {
- executor.execute(new Runnable() {
- public void run() {
- synchronized (resultLock) {
- try {
- result = objectInputStream.readObject();
- } catch (Throwable t) {
- cause = t;
+ synchronized (resultLock) {
+ if (done) {
+ done = false;
+ executor.execute(new Runnable() {
+ public void run() {
+ synchronized (resultLock) {
+ try {
+ result = objectInputStream.readObject();
+ log.trace("Successfully unmarshalled object
%s", result);
+ } catch (Throwable t) {
+ cause = t;
+ log.trace(t, "Failed to unmarshal an object");
+ }
+ done = true;
+ }
}
- done = true;
+ });
+ }
+ inputStream.setBuffer(buffer, false);
+ try {
+ while (! inputStream.isWaiting() && ! done) {
+ resultLock.wait();
}
+ return done;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new InterruptedIOException("unmarshal operation was
interrupted");
}
- });
- return false;
+ }
}
public Object get() throws IOException, IllegalStateException, ClassNotFoundException
{
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JavaSerializationUnmarshaller.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JavaSerializationUnmarshaller.java 2008-07-15
20:02:34 UTC (rev 4375)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/JavaSerializationUnmarshaller.java 2008-07-17
02:25:47 UTC (rev 4376)
@@ -58,6 +58,10 @@
this.resolver = resolver;
}
+ protected final void readStreamHeader() {
+ // no headers
+ }
+
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException,
ClassNotFoundException {
final String name = desc.getName();
if (primitiveTypes.containsKey(name)) {
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java
===================================================================
---
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java 2008-07-15
20:02:34 UTC (rev 4375)
+++
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/marshal/OneBufferInputStream.java 2008-07-17
02:25:47 UTC (rev 4376)
@@ -65,6 +65,12 @@
}
}
+ public boolean isWaiting() {
+ synchronized (lock) {
+ return buffer == null;
+ }
+ }
+
public void setBuffer(ByteBuffer buffer, boolean eof) {
synchronized (lock) {
if (this.buffer != null) {
Show replies by date