-- Protocol and transport factories now wrap around a single protocol/transport
Summary:
- This is an analagous to the C++ change made in r31441
Reviewed By: slee
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664978 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/src/protocol/TBinaryProtocol.java b/lib/java/src/protocol/TBinaryProtocol.java
index b6431bf..08f6e55 100644
--- a/lib/java/src/protocol/TBinaryProtocol.java
+++ b/lib/java/src/protocol/TBinaryProtocol.java
@@ -14,18 +14,16 @@
* Factory
*/
public static class Factory implements TProtocolFactory {
- public TProtocol[] getIOProtocols(TTransport in, TTransport out) {
- TProtocol[] io = new TProtocol[2];
- io[0] = io[1] = new TBinaryProtocol(in, out);
- return io;
+ public TProtocol getProtocol(TTransport trans) {
+ return new TBinaryProtocol(trans);
}
}
/**
* Constructor
*/
- public TBinaryProtocol(TTransport in, TTransport out) {
- super(in, out);
+ public TBinaryProtocol(TTransport trans) {
+ super(trans);
}
public void writeMessageBegin(TMessage message) throws TException {
@@ -80,14 +78,14 @@
private byte [] bout = new byte[1];
public void writeByte(byte b) throws TException {
bout[0] = b;
- outputTransport_.write(bout, 0, 1);
+ trans_.write(bout, 0, 1);
}
private byte[] i16out = new byte[2];
public void writeI16(short i16) throws TException {
i16out[0] = (byte)(0xff & (i16 >> 8));
i16out[1] = (byte)(0xff & (i16));
- outputTransport_.write(i16out, 0, 2);
+ trans_.write(i16out, 0, 2);
}
private byte[] i32out = new byte[4];
@@ -96,7 +94,7 @@
i32out[1] = (byte)(0xff & (i32 >> 16));
i32out[2] = (byte)(0xff & (i32 >> 8));
i32out[3] = (byte)(0xff & (i32));
- outputTransport_.write(i32out, 0, 4);
+ trans_.write(i32out, 0, 4);
}
private byte[] i64out = new byte[8];
@@ -109,7 +107,7 @@
i64out[5] = (byte)(0xff & (i64 >> 16));
i64out[6] = (byte)(0xff & (i64 >> 8));
i64out[7] = (byte)(0xff & (i64));
- outputTransport_.write(i64out, 0, 8);
+ trans_.write(i64out, 0, 8);
}
public void writeDouble(double dub) throws TException {
@@ -119,7 +117,7 @@
public void writeString(String str) throws TException {
byte[] dat = str.getBytes();
writeI32(dat.length);
- outputTransport_.write(dat, 0, dat.length);
+ trans_.write(dat, 0, dat.length);
}
/**
@@ -187,13 +185,13 @@
private byte[] bin = new byte[1];
public byte readByte() throws TException {
- inputTransport_.readAll(bin, 0, 1);
+ trans_.readAll(bin, 0, 1);
return bin[0];
}
private byte[] i16rd = new byte[2];
public short readI16() throws TException {
- inputTransport_.readAll(i16rd, 0, 2);
+ trans_.readAll(i16rd, 0, 2);
return
(short)
(((i16rd[0] & 0xff) << 8) |
@@ -202,7 +200,7 @@
private byte[] i32rd = new byte[4];
public int readI32() throws TException {
- inputTransport_.readAll(i32rd, 0, 4);
+ trans_.readAll(i32rd, 0, 4);
return
((i32rd[0] & 0xff) << 24) |
((i32rd[1] & 0xff) << 16) |
@@ -212,7 +210,7 @@
private byte[] i64rd = new byte[8];
public long readI64() throws TException {
- inputTransport_.readAll(i64rd, 0, 8);
+ trans_.readAll(i64rd, 0, 8);
return
((long)(i64rd[0] & 0xff) << 56) |
((long)(i64rd[1] & 0xff) << 48) |
@@ -231,7 +229,7 @@
public String readString() throws TException {
int size = readI32();
byte[] buf = new byte[size];
- inputTransport_.readAll(buf, 0, size);
+ trans_.readAll(buf, 0, size);
return new String(buf);
}
}
diff --git a/lib/java/src/protocol/TProtocol.java b/lib/java/src/protocol/TProtocol.java
index 43b4f07..502f473 100644
--- a/lib/java/src/protocol/TProtocol.java
+++ b/lib/java/src/protocol/TProtocol.java
@@ -16,35 +16,22 @@
private TProtocol() {}
/**
- * Input transport
+ * Transport
*/
- protected TTransport inputTransport_;
-
- /**
- * Output transport
- */
- protected TTransport outputTransport_;
+ protected TTransport trans_;
/**
* Constructor
*/
- protected TProtocol(TTransport in, TTransport out) {
- inputTransport_ = in;
- outputTransport_ = out;
+ protected TProtocol(TTransport trans) {
+ trans_ = trans;
}
/**
- * Input accessor
+ * Transport accessor
*/
- public TTransport getInputTransport() {
- return inputTransport_;
- }
-
- /**
- * Output accessor
- */
- public TTransport getOutputTransport() {
- return outputTransport_;
+ public TTransport getTransport() {
+ return trans_;
}
/**
diff --git a/lib/java/src/protocol/TProtocolFactory.java b/lib/java/src/protocol/TProtocolFactory.java
index 7604b12..9ca3c9e 100644
--- a/lib/java/src/protocol/TProtocolFactory.java
+++ b/lib/java/src/protocol/TProtocolFactory.java
@@ -3,11 +3,11 @@
import com.facebook.thrift.transport.TTransport;
/**
- * Factory interface for constructing protocol encoder/decoder pair from an
- * input and output transport.
+ * Factory interface for constructing protocol instances.
*
* @author Mark Slee <mcslee@facebook.com>
+ * @author Aditya Agarwal <aditya@facebook.com>
*/
public interface TProtocolFactory {
- public TProtocol[] getIOProtocols(TTransport in, TTransport out);
+ public TProtocol getProtocol(TTransport trans);
}