You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by dk...@apache.org on 2019/01/17 20:28:28 UTC
[avro] branch master updated: AVRO-1214 Use void instead of Void
for RPC methods
This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 05171ee AVRO-1214 Use void instead of Void for RPC methods
05171ee is described below
commit 05171ee872bb8d6e9173a34b7832f522b2a56763
Author: Sébastien Launay <se...@slaunay.fr>
AuthorDate: Mon Nov 19 14:29:32 2012 -0800
AVRO-1214 Use void instead of Void for RPC methods
- one-way message use void but two-ways messages might use java.lang.Void
---
.../apache/avro/compiler/specific/SpecificCompiler.java | 16 ++++++++++++++--
.../compiler/specific/templates/java/classic/protocol.vm | 2 +-
.../java/org/apache/avro/grpc/TestAvroProtocolGrpc.java | 2 +-
.../ipc/src/test/java/org/apache/avro/TestBulkData.java | 3 +--
.../test/java/org/apache/avro/TestNamespaceSpecific.java | 2 +-
.../test/java/org/apache/avro/TestProtocolSpecific.java | 2 +-
.../avro/ipc/TestNettyServerConcurrentExecution.java | 2 +-
.../apache/avro/ipc/TestNettyServerWithCallbacks.java | 6 +++---
8 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index 1936bd6..800d50e 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -793,8 +793,16 @@ public class SpecificCompiler {
return null;
}
- /** Utility for template use. Returns the unboxed java type for a Schema. */
+ /**
+ * Utility for template use. Returns the unboxed java type for a Schema.
+ * @Deprecated use javaUnbox(Schema, boolean), kept for backward compatibiliby of custom templates
+ */
public String javaUnbox(Schema schema) {
+ return javaUnbox(schema, false);
+ }
+
+ /** Utility for template use. Returns the unboxed java type for a Schema including the void type. */
+ public String javaUnbox(Schema schema, boolean unboxNullToVoid) {
String convertedLogicalType = getConvertedLogicalType(schema);
if (convertedLogicalType != null) {
return convertedLogicalType;
@@ -806,11 +814,15 @@ public class SpecificCompiler {
case FLOAT: return "float";
case DOUBLE: return "double";
case BOOLEAN: return "boolean";
+ case NULL:
+ if (unboxNullToVoid) {
+ // Used for preventing unnecessary returns for RPC methods without response but with error(s)
+ return "void";
+ }
default: return javaType(schema, false);
}
}
-
/** Utility for template use. Return a string with a given number
* of spaces to be used for indentation purposes. */
public String indent(int n) {
diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
index ca5492d..2d53f62 100644
--- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
+++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
@@ -44,7 +44,7 @@ public interface $this.mangle($protocol.getName()) {
#foreach ($annotation in $this.javaAnnotations($message))
@$annotation
#end
- #if ($message.isOneWay())void#else${this.javaUnbox($response)}#end
+ #if ($message.isOneWay())void#else${this.javaUnbox($response, true)}#end
${this.mangle($name)}(##
#foreach ($p in $message.getRequest().getFields())##
#* *#${this.javaUnbox($p.schema())} ${this.mangle($p.name())}#if ($foreach.hasNext), #end
diff --git a/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java b/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
index d11aa3d..f91addd 100644
--- a/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
+++ b/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
@@ -241,7 +241,7 @@ public class TestAvroProtocolGrpc {
}
@Override
- public Void error(boolean declared) throws AvroRemoteException, TestError {
+ public void error(boolean declared) throws AvroRemoteException, TestError {
if (declared) {
throw declaredError;
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestBulkData.java b/lang/java/ipc/src/test/java/org/apache/avro/TestBulkData.java
index d620e9e..3ca8ecc 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestBulkData.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestBulkData.java
@@ -52,9 +52,8 @@ public class TestBulkData {
public static class BulkDataImpl implements BulkData {
public ByteBuffer read() { return DATA.duplicate(); }
- public Void write(ByteBuffer data) {
+ public void write(ByteBuffer data) {
Assert.assertEquals(SIZE, data.remaining());
- return null;
}
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java b/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java
index 09785c1..6d4bd3d 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java
@@ -39,7 +39,7 @@ public class TestNamespaceSpecific {
public static class TestImpl implements TestNamespace {
public TestRecord echo(TestRecord record) { return record; }
- public Void error() throws AvroRemoteException {
+ public void error() throws AvroRemoteException {
throw TestError.newBuilder().setMessage$("an error").build();
}
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
index ea79b27..381071d 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
@@ -68,7 +68,7 @@ public class TestProtocolSpecific {
public int add(int arg1, int arg2) { return arg1 + arg2; }
public TestRecord echo(TestRecord record) { return record; }
public ByteBuffer echoBytes(ByteBuffer data) { return data; }
- public Void error() throws AvroRemoteException {
+ public void error() throws AvroRemoteException {
if (throwUndeclaredError) throw new RuntimeException("foo");
throw TestError.newBuilder().setMessage$("an error").build();
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerConcurrentExecution.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerConcurrentExecution.java
index fcae16f..de0ea35 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerConcurrentExecution.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerConcurrentExecution.java
@@ -192,7 +192,7 @@ public class TestNettyServerConcurrentExecution {
}
@Override
- public Void error() throws AvroRemoteException, TestError {
+ public void error() throws AvroRemoteException, TestError {
throw new TestError("TestError");
}
}
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java
index 30b1fb9..77c89a3 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java
@@ -566,7 +566,7 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public Void error() throws AvroRemoteException, TestError {
+ public void error() throws AvroRemoteException, TestError {
throw TestError.newBuilder().setMessage$("Test Message").build();
}
@@ -638,11 +638,11 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public Void error() throws AvroRemoteException, TestError {
+ public void error() throws AvroRemoteException, TestError {
releaseEnterPermit();
acquireRunPermit();
try {
- return super.error();
+ super.error();
} finally {
releaseRunPermit();
}