diff options
author | Mark Spruiell <mes@zeroc.com> | 2004-10-20 00:04:40 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2004-10-20 00:04:40 +0000 |
commit | 486c95495b7457fa035001ba026b1b9b848b794b (patch) | |
tree | 3bf070fb9ec87b39ab3423823fdad0efb94c7013 /java/src | |
parent | Win32 fixes (diff) | |
download | ice-486c95495b7457fa035001ba026b1b9b848b794b.tar.bz2 ice-486c95495b7457fa035001ba026b1b9b848b794b.tar.xz ice-486c95495b7457fa035001ba026b1b9b848b794b.zip |
adding streaming interface
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/InputStream.java | 57 | ||||
-rw-r--r-- | java/src/Ice/InputStreamI.java | 232 | ||||
-rw-r--r-- | java/src/Ice/Object.java | 3 | ||||
-rw-r--r-- | java/src/Ice/ObjectImpl.java | 29 | ||||
-rw-r--r-- | java/src/Ice/ObjectReader.java | 28 | ||||
-rw-r--r-- | java/src/Ice/ObjectWriter.java | 28 | ||||
-rw-r--r-- | java/src/Ice/OutputStream.java | 54 | ||||
-rw-r--r-- | java/src/Ice/OutputStreamI.java | 198 | ||||
-rw-r--r-- | java/src/Ice/ReadObjectCallback.java | 15 | ||||
-rw-r--r-- | java/src/Ice/UserException.java | 12 | ||||
-rw-r--r-- | java/src/Ice/Util.java | 12 | ||||
-rw-r--r-- | java/src/Ice/_ObjectDelM.java | 12 | ||||
-rw-r--r-- | java/src/IceInternal/BasicInputStream.java | 22 | ||||
-rw-r--r-- | java/src/IceInternal/BasicOutputStream.java | 22 | ||||
-rw-r--r-- | java/src/IceInternal/ListPatcher.java | 8 | ||||
-rw-r--r-- | java/src/IceInternal/SequencePatcher.java | 8 |
16 files changed, 735 insertions, 5 deletions
diff --git a/java/src/Ice/InputStream.java b/java/src/Ice/InputStream.java new file mode 100644 index 00000000000..a272d560d2b --- /dev/null +++ b/java/src/Ice/InputStream.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public interface InputStream +{ + Communicator communicator(); + + void sliceObjects(boolean slice); + + boolean readBool(); + boolean[] readBoolSeq(); + + byte readByte(); + byte[] readByteSeq(); + + short readShort(); + short[] readShortSeq(); + + int readInt(); + int[] readIntSeq(); + + long readLong(); + long[] readLongSeq(); + + float readFloat(); + float[] readFloatSeq(); + + double readDouble(); + double[] readDoubleSeq(); + + String readString(); + String[] readStringSeq(); + + int readSize(); + + ObjectPrx readProxy(); + + void readObject(ReadObjectCallback cb); + + String readTypeId(); + + void throwException() throws UserException; + + void startSlice(); + void endSlice(); + void skipSlice(); + + void finished(); +} diff --git a/java/src/Ice/InputStreamI.java b/java/src/Ice/InputStreamI.java new file mode 100644 index 00000000000..eeda0a961a2 --- /dev/null +++ b/java/src/Ice/InputStreamI.java @@ -0,0 +1,232 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public class InputStreamI implements InputStream +{ + public + InputStreamI(Communicator communicator, byte[] data) + { + _communicator = communicator; + _readObjects = false; + + _is = new IceInternal.BasicInputStream(Util.getInstance(communicator), this); + _is.resize(data.length, true); + java.nio.ByteBuffer buf = _is.prepareRead(); + buf.position(0); + buf.put(data); + buf.position(0); + } + + protected void + finalize() + throws Throwable + { + if(_is != null) + { + _is.destroy(); + } + } + + public Communicator + communicator() + { + return _communicator; + } + + public void + sliceObjects(boolean slice) + { + _is.sliceObjects(slice); + } + + public boolean + readBool() + { + return _is.readBool(); + } + + public boolean[] + readBoolSeq() + { + return _is.readBoolSeq(); + } + + public byte + readByte() + { + return _is.readByte(); + } + + public byte[] + readByteSeq() + { + return _is.readByteSeq(); + } + + public short + readShort() + { + return _is.readShort(); + } + + public short[] + readShortSeq() + { + return _is.readShortSeq(); + } + + public int + readInt() + { + return _is.readInt(); + } + + public int[] + readIntSeq() + { + return _is.readIntSeq(); + } + + public long + readLong() + { + return _is.readLong(); + } + + public long[] + readLongSeq() + { + return _is.readLongSeq(); + } + + public float + readFloat() + { + return _is.readFloat(); + } + + public float[] + readFloatSeq() + { + return _is.readFloatSeq(); + } + + public double + readDouble() + { + return _is.readDouble(); + } + + public double[] + readDoubleSeq() + { + return _is.readDoubleSeq(); + } + + public String + readString() + { + return _is.readString(); + } + + public String[] + readStringSeq() + { + return _is.readStringSeq(); + } + + public int + readSize() + { + return _is.readSize(); + } + + public ObjectPrx + readProxy() + { + return _is.readProxy(); + } + + private static class Patcher implements IceInternal.Patcher + { + Patcher(ReadObjectCallback cb) + { + _cb = cb; + } + + public void + patch(Ice.Object v) + { + _cb.invoke(v); + } + + public String + type() + { + return "unknown"; + } + + ReadObjectCallback _cb; + } + + public void + readObject(ReadObjectCallback cb) + { + _readObjects = true; + _is.readObject(new Patcher(cb)); + } + + public String + readTypeId() + { + return _is.readTypeId(); + } + + public void + throwException() + throws UserException + { + _is.throwException(); + } + + public void + startSlice() + { + _is.startReadSlice(); + } + + public void + endSlice() + { + _is.endReadSlice(); + } + + public void + skipSlice() + { + _is.skipSlice(); + } + + public void + finished() + { + if(_readObjects) + { + _is.readPendingObjects(); + } + _is.destroy(); + _is = null; + } + + private Communicator _communicator; + private IceInternal.BasicInputStream _is; + private boolean _readObjects; +} diff --git a/java/src/Ice/Object.java b/java/src/Ice/Object.java index edcb4233322..caed1a491e2 100644 --- a/java/src/Ice/Object.java +++ b/java/src/Ice/Object.java @@ -36,4 +36,7 @@ public interface Object void __write(IceInternal.BasicStream __os); void __read(IceInternal.BasicStream __is, boolean __rid); + + void __write(OutputStream __out); + void __read(InputStream __in, boolean __rid); } diff --git a/java/src/Ice/ObjectImpl.java b/java/src/Ice/ObjectImpl.java index 4cb030d2dc6..6739b651903 100644 --- a/java/src/Ice/ObjectImpl.java +++ b/java/src/Ice/ObjectImpl.java @@ -203,4 +203,33 @@ public class ObjectImpl implements Object, java.lang.Cloneable __is.endReadSlice(); } + + public void + __write(Ice.OutputStream __out) + { + __out.writeTypeId(ice_staticId()); + __out.startSlice(); + __out.writeSize(0); // For compatibility with the old AFM. + __out.endSlice(); + } + + public void + __read(Ice.InputStream __in, boolean __rid) + { + if(__rid) + { + String myId = __in.readTypeId(); + } + + __in.startSlice(); + + // For compatibility with the old AFM. + int sz = __in.readSize(); + if(sz != 0) + { + throw new MarshalException(); + } + + __in.endSlice(); + } } diff --git a/java/src/Ice/ObjectReader.java b/java/src/Ice/ObjectReader.java new file mode 100644 index 00000000000..73d0c288ed4 --- /dev/null +++ b/java/src/Ice/ObjectReader.java @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public abstract class ObjectReader extends ObjectImpl +{ + public abstract void read(InputStream in, boolean rid); + + public void + __write(IceInternal.BasicStream os) + { + assert(false); + } + + public void + __read(IceInternal.BasicStream is, boolean rid) + { + IceInternal.BasicInputStream bis = (IceInternal.BasicInputStream)is; + read(bis._in, rid); + } +} diff --git a/java/src/Ice/ObjectWriter.java b/java/src/Ice/ObjectWriter.java new file mode 100644 index 00000000000..b28ca230eb6 --- /dev/null +++ b/java/src/Ice/ObjectWriter.java @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public abstract class ObjectWriter extends ObjectImpl +{ + public abstract void write(OutputStream out); + + public void + __write(IceInternal.BasicStream os) + { + IceInternal.BasicOutputStream bos = (IceInternal.BasicOutputStream)os; + write(bos._out); + } + + public void + __read(IceInternal.BasicStream is, boolean rid) + { + assert(false); + } +} diff --git a/java/src/Ice/OutputStream.java b/java/src/Ice/OutputStream.java new file mode 100644 index 00000000000..2c8022b483e --- /dev/null +++ b/java/src/Ice/OutputStream.java @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public interface OutputStream +{ + Communicator communicator(); + + void writeBool(boolean v); + void writeBoolSeq(boolean[] v); + + void writeByte(byte v); + void writeByteSeq(byte[] v); + + void writeShort(short v); + void writeShortSeq(short[] v); + + void writeInt(int v); + void writeIntSeq(int[] v); + + void writeLong(long v); + void writeLongSeq(long[] v); + + void writeFloat(float v); + void writeFloatSeq(float[] v); + + void writeDouble(double v); + void writeDoubleSeq(double[] v); + + void writeString(String v); + void writeStringSeq(String[] v); + + void writeSize(int sz); + + void writeProxy(ObjectPrx v); + + void writeObject(Ice.Object v); + + void writeTypeId(String id); + + void writeException(UserException ex); + + void startSlice(); + void endSlice(); + + byte[] finished(); +} diff --git a/java/src/Ice/OutputStreamI.java b/java/src/Ice/OutputStreamI.java new file mode 100644 index 00000000000..2c040f7acbe --- /dev/null +++ b/java/src/Ice/OutputStreamI.java @@ -0,0 +1,198 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public class OutputStreamI implements OutputStream +{ + public + OutputStreamI(Communicator communicator) + { + _communicator = communicator; + _os = new IceInternal.BasicOutputStream(Util.getInstance(communicator), this); + _writeObjects = false; + } + + protected void + finalize() + throws Throwable + { + if(_os != null) + { + _os.destroy(); + } + } + + public Communicator + communicator() + { + return _communicator; + } + + public void + writeBool(boolean v) + { + _os.writeBool(v); + } + + public void + writeBoolSeq(boolean[] v) + { + _os.writeBoolSeq(v); + } + + public void + writeByte(byte v) + { + _os.writeByte(v); + } + + public void + writeByteSeq(byte[] v) + { + _os.writeByteSeq(v); + } + + public void + writeShort(short v) + { + _os.writeShort(v); + } + + public void + writeShortSeq(short[] v) + { + _os.writeShortSeq(v); + } + + public void + writeInt(int v) + { + _os.writeInt(v); + } + + public void + writeIntSeq(int[] v) + { + _os.writeIntSeq(v); + } + + public void + writeLong(long v) + { + _os.writeLong(v); + } + + public void + writeLongSeq(long[] v) + { + _os.writeLongSeq(v); + } + + public void + writeFloat(float v) + { + _os.writeFloat(v); + } + + public void + writeFloatSeq(float[] v) + { + _os.writeFloatSeq(v); + } + + public void + writeDouble(double v) + { + _os.writeDouble(v); + } + + public void + writeDoubleSeq(double[] v) + { + _os.writeDoubleSeq(v); + } + + public void + writeString(String v) + { + _os.writeString(v); + } + + public void + writeStringSeq(String[] v) + { + _os.writeStringSeq(v); + } + + public void + writeSize(int sz) + { + _os.writeSize(sz); + } + + public void + writeProxy(ObjectPrx v) + { + _os.writeProxy(v); + } + + public void + writeObject(Ice.Object v) + { + _writeObjects = true; + _os.writeObject(v); + } + + public void + writeTypeId(String id) + { + _os.writeTypeId(id); + } + + public void + writeException(UserException v) + { + _os.writeUserException(v); + } + + public void + startSlice() + { + _os.startWriteSlice(); + } + + public void + endSlice() + { + _os.endWriteSlice(); + } + + public byte[] + finished() + { + if(_writeObjects) + { + _os.writePendingObjects(); + } + + java.nio.ByteBuffer buf = _os.prepareWrite(); + byte[] result = new byte[buf.limit()]; + buf.get(result); + + _os.destroy(); + _os = null; + + return result; + } + + private Communicator _communicator; + private IceInternal.BasicOutputStream _os; + private boolean _writeObjects; +} diff --git a/java/src/Ice/ReadObjectCallback.java b/java/src/Ice/ReadObjectCallback.java new file mode 100644 index 00000000000..7322dafdac9 --- /dev/null +++ b/java/src/Ice/ReadObjectCallback.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Ice; + +public interface ReadObjectCallback +{ + void invoke(Ice.Object obj); +} diff --git a/java/src/Ice/UserException.java b/java/src/Ice/UserException.java index b86df1a7189..3f182e0be32 100644 --- a/java/src/Ice/UserException.java +++ b/java/src/Ice/UserException.java @@ -34,6 +34,18 @@ public abstract class UserException extends Exception public abstract void __read(IceInternal.BasicStream __is, boolean __rid); + public void + __write(Ice.OutputStream __out) + { + assert(false); + } + + public void + __read(Ice.InputStream __in, boolean __rid) + { + assert(false); + } + public boolean __usesClasses() { diff --git a/java/src/Ice/Util.java b/java/src/Ice/Util.java index d6ca964184d..630c68216a6 100644 --- a/java/src/Ice/Util.java +++ b/java/src/Ice/Util.java @@ -280,6 +280,18 @@ public final class Util } } + public static InputStream + createInputStream(Communicator communicator, byte[] bytes) + { + return new InputStreamI(communicator, bytes); + } + + public static OutputStream + createOutputStream(Communicator communicator) + { + return new OutputStreamI(communicator); + } + private static Properties _defaultProperties = null; private static String _localAddress = null; } diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java index c045f2beb34..904246bda55 100644 --- a/java/src/Ice/_ObjectDelM.java +++ b/java/src/Ice/_ObjectDelM.java @@ -119,8 +119,11 @@ public class _ObjectDelM implements _ObjectDel IceInternal.Outgoing __out = getOutgoing(operation, mode, __context); try { - IceInternal.BasicStream __os = __out.os(); - __os.writeBlob(inParams); + if(inParams != null) + { + IceInternal.BasicStream __os = __out.os(); + __os.writeBlob(inParams); + } boolean ok = __out.invoke(); if(__reference.mode == IceInternal.Reference.ModeTwoway) { @@ -128,7 +131,10 @@ public class _ObjectDelM implements _ObjectDel { IceInternal.BasicStream __is = __out.is(); int sz = __is.getReadEncapsSize(); - outParams.value = __is.readBlob(sz); + if(outParams != null) + { + outParams.value = __is.readBlob(sz); + } } catch(LocalException __ex) { diff --git a/java/src/IceInternal/BasicInputStream.java b/java/src/IceInternal/BasicInputStream.java new file mode 100644 index 00000000000..bd165fecae0 --- /dev/null +++ b/java/src/IceInternal/BasicInputStream.java @@ -0,0 +1,22 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceInternal; + +public class BasicInputStream extends BasicStream +{ + public + BasicInputStream(Instance instance, Ice.InputStream in) + { + super(instance); + _in = in; + } + + public Ice.InputStream _in; +} diff --git a/java/src/IceInternal/BasicOutputStream.java b/java/src/IceInternal/BasicOutputStream.java new file mode 100644 index 00000000000..609efc03b61 --- /dev/null +++ b/java/src/IceInternal/BasicOutputStream.java @@ -0,0 +1,22 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceInternal; + +public class BasicOutputStream extends BasicStream +{ + public + BasicOutputStream(Instance instance, Ice.OutputStream out) + { + super(instance); + _out = out; + } + + public Ice.OutputStream _out; +} diff --git a/java/src/IceInternal/ListPatcher.java b/java/src/IceInternal/ListPatcher.java index 45fdf537134..8af59acf78d 100644 --- a/java/src/IceInternal/ListPatcher.java +++ b/java/src/IceInternal/ListPatcher.java @@ -9,7 +9,7 @@ package IceInternal; -public class ListPatcher implements Patcher +public class ListPatcher implements Patcher, Ice.ReadObjectCallback { public ListPatcher(java.util.List list, Class cls, String type, int index) @@ -49,6 +49,12 @@ public class ListPatcher implements Patcher return _type; } + public void + invoke(Ice.Object v) + { + patch(v); + } + private java.util.List _list; private Class _cls; private String _type; diff --git a/java/src/IceInternal/SequencePatcher.java b/java/src/IceInternal/SequencePatcher.java index d733cf7289f..6b4cafd69ae 100644 --- a/java/src/IceInternal/SequencePatcher.java +++ b/java/src/IceInternal/SequencePatcher.java @@ -9,7 +9,7 @@ package IceInternal; -public class SequencePatcher implements Patcher +public class SequencePatcher implements Patcher, Ice.ReadObjectCallback { public SequencePatcher(java.lang.Object[] seq, Class cls, String type, int index) @@ -44,6 +44,12 @@ public class SequencePatcher implements Patcher return _type; } + public void + invoke(Ice.Object v) + { + patch(v); + } + private java.lang.Object[] _seq; private Class _cls; private String _type; |