diff --git a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/enums/DubboGenerateTypeEnum.java b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/enums/DubboGenerateTypeEnum.java index f66bb21b5ba..2b8a62cb920 100644 --- a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/enums/DubboGenerateTypeEnum.java +++ b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/enums/DubboGenerateTypeEnum.java @@ -17,13 +17,9 @@ package org.apache.dubbo.maven.plugin.protoc.enums; public enum DubboGenerateTypeEnum { - Dubbo("dubbo", "org.apache.dubbo.gen.dubbo.DubboGenerator"), Dubbo3("dubbo3", "org.apache.dubbo.gen.dubbo.Dubbo3Generator"), Tri("tri", "org.apache.dubbo.gen.tri.Dubbo3TripleGenerator"), Tri_reactor("tri_reactor", "org.apache.dubbo.gen.tri.reactive.ReactorDubbo3TripleGenerator"), - Grpc("grpc", "org.apache.dubbo.gen.grpc.DubboGrpcGenerator"), - Grpc_reactor("grpc_reactor", "org.apache.dubbo.gen.grpc.reactive.ReactorDubboGrpcGenerator"), - Grpc_rx("grpc_rx", "org.apache.dubbo.gen.grpc.reactive.RxDubboGrpcGenerator"), ; private String id; private String mainClass; diff --git a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/dubbo/DubboGenerator.java b/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/dubbo/DubboGenerator.java deleted file mode 100644 index 793253b3e40..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/dubbo/DubboGenerator.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.gen.dubbo; - -import org.apache.dubbo.gen.AbstractGenerator; -import org.apache.dubbo.gen.DubboGeneratorPlugin; - -public class DubboGenerator extends AbstractGenerator { - - public static void main(String[] args) { - DubboGeneratorPlugin.generate(new DubboGenerator()); - } - - @Override - protected String getClassPrefix() { - return ""; - } - - @Override - protected String getClassSuffix() { - return "Dubbo"; - } -} diff --git a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/DubboGrpcGenerator.java b/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/DubboGrpcGenerator.java deleted file mode 100644 index bc3ee340ad4..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/DubboGrpcGenerator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.gen.grpc; - -import org.apache.dubbo.gen.AbstractGenerator; -import org.apache.dubbo.gen.DubboGeneratorPlugin; - -public class DubboGrpcGenerator extends AbstractGenerator { - - public static void main(String[] args) { - DubboGeneratorPlugin.generate(new DubboGrpcGenerator()); - } - - @Override - protected String getClassPrefix() { - return "Dubbo"; - } - - protected String getClassSuffix() { - return "Grpc"; - } -} diff --git a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/ReactorDubboGrpcGenerator.java b/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/ReactorDubboGrpcGenerator.java deleted file mode 100644 index b053db4b3fc..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/ReactorDubboGrpcGenerator.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.gen.grpc.reactive; - -import org.apache.dubbo.gen.AbstractGenerator; -import org.apache.dubbo.gen.DubboGeneratorPlugin; - -public class ReactorDubboGrpcGenerator extends AbstractGenerator { - - @Override - protected String getClassPrefix() { - return "ReactorDubbo"; - } - - @Override - protected String getClassSuffix() { - return "Grpc"; - } - - public static void main(String[] args) { - DubboGeneratorPlugin.generate(new ReactorDubboGrpcGenerator()); - } -} diff --git a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/RxDubboGrpcGenerator.java b/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/RxDubboGrpcGenerator.java deleted file mode 100644 index e81e90f57dc..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/java/org/apache/dubbo/gen/grpc/reactive/RxDubboGrpcGenerator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.gen.grpc.reactive; - -import org.apache.dubbo.gen.AbstractGenerator; -import org.apache.dubbo.gen.DubboGeneratorPlugin; - -public class RxDubboGrpcGenerator extends AbstractGenerator { - @Override - protected String getClassPrefix() { - return "RxDubbo"; - } - - @Override - protected String getClassSuffix() { - return "Grpc"; - } - - public static void main(String[] args) { - DubboGeneratorPlugin.generate(new RxDubboGrpcGenerator()); - } -} diff --git a/dubbo-plugin/dubbo-compiler/src/main/resources/DubboGrpcStub.mustache b/dubbo-plugin/dubbo-compiler/src/main/resources/DubboGrpcStub.mustache deleted file mode 100644 index 80456bcfa4f..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/resources/DubboGrpcStub.mustache +++ /dev/null @@ -1,323 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{{#packageName}} - package {{packageName}}; -{{/packageName}} - -import org.apache.dubbo.common.URL; - -import java.util.concurrent.TimeUnit; - -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; - -import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; - -{{#deprecated}} - @java.lang.Deprecated -{{/deprecated}} -public final class {{className}} { -private {{className}}() {} - -public static class Dubbo{{serviceName}}Stub implements I{{serviceName}} { - -protected URL url; - -protected {{serviceName}}Grpc.{{serviceName}}BlockingStub blockingStub; -protected {{serviceName}}Grpc.{{serviceName}}FutureStub futureStub; -protected {{serviceName}}Grpc.{{serviceName}}Stub stub; - -public Dubbo{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url) { -this.url = url; - -blockingStub = {{serviceName}}Grpc.newBlockingStub(channel).build(channel, callOptions); -futureStub = {{serviceName}}Grpc.newFutureStub(channel).build(channel, callOptions); -stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions); -} - -{{#unaryMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{outputType}} {{methodName}}({{inputType}} request) { - return blockingStub - .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS) - .{{methodName}}(request); - } - - public com.google.common.util.concurrent.ListenableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request) { - return futureStub - .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS) - .{{methodName}}(request); - } - - public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver){ - stub - .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS) - .{{methodName}}(request, responseObserver); - } - -{{/unaryMethods}} -{{#serverStreamingMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public java.util.Iterator<{{outputType}}> {{methodName}}({{inputType}} request) { - return blockingStub - .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS) - .{{methodName}}(request); - } - - public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) { - stub - .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS) - .{{methodName}}(request, responseObserver); - } - -{{/serverStreamingMethods}} -{{#biStreamingMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public io.grpc.stub.StreamObserver<{{inputType}}> {{methodName}}(io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) { - return stub - .withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS) - .{{methodName}}(responseObserver); - } -{{/biStreamingMethods}} -} - -public static Dubbo{{serviceName}}Stub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url) { -return new Dubbo{{serviceName}}Stub(channel, callOptions, url); -} - -public interface I{{serviceName}} { -{{#unaryMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - default public {{outputType}} {{methodName}}({{inputType}} request) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - default public com.google.common.util.concurrent.ListenableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver); - -{{/unaryMethods}} -{{#serverStreamingMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - default public java.util.Iterator<{{outputType}}> {{methodName}}({{inputType}} request) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public void {{methodName}}({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> responseObserver); - -{{/serverStreamingMethods}} -{{#biStreamingMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public io.grpc.stub.StreamObserver<{{inputType}}> {{methodName}}(io.grpc.stub.StreamObserver<{{outputType}}> responseObserver); - -{{/biStreamingMethods}} -} - -{{#javaDoc}} - {{{javaDoc}}} -{{/javaDoc}} -public static abstract class {{serviceName}}ImplBase implements I{{serviceName}}, io.grpc.BindableService { - -private I{{serviceName}} proxiedImpl; - -public final void setProxiedImpl(I{{serviceName}} proxiedImpl) { -this.proxiedImpl = proxiedImpl; -} - -{{#unaryMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - @java.lang.Override - public final {{outputType}} {{methodName}}({{inputType}} request) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - @java.lang.Override - public final com.google.common.util.concurrent.ListenableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - -{{/unaryMethods}} -{{#serverStreamingMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - @java.lang.Override - public final java.util.Iterator<{{outputType}}> {{methodName}}({{inputType}} request) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - -{{/serverStreamingMethods}} -{{#methods}} - {{#isManyInput}} - public io.grpc.stub.StreamObserver<{{inputType}}> {{methodName}}( - io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) { - return asyncUnimplementedStreamingCall({{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(), responseObserver); - } - {{/isManyInput}}{{^isManyInput}} - public void {{methodName}}({{inputType}} request, - io.grpc.stub.StreamObserver<{{outputType}}> responseObserver) { - asyncUnimplementedUnaryCall({{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(), responseObserver); - } - {{/isManyInput}} -{{/methods}} - -@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { -return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) -{{#methods}} - .addMethod( - {{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(), - {{grpcCallsMethodName}}( - new MethodHandlers< - {{inputType}}, - {{outputType}}>( - proxiedImpl, METHODID_{{methodNameUpperUnderscore}}))) -{{/methods}} -.build(); -} -} -{{#methods}} - private static final int METHODID_{{methodNameUpperUnderscore}} = {{methodNumber}}; -{{/methods}} - -private static final class MethodHandlers - implements -io.grpc.stub.ServerCalls.UnaryMethod -, -io.grpc.stub.ServerCalls.ServerStreamingMethod -, -io.grpc.stub.ServerCalls.ClientStreamingMethod -, -io.grpc.stub.ServerCalls.BidiStreamingMethod - { -private final I{{serviceName}} serviceImpl; -private final int methodId; - -MethodHandlers(I{{serviceName}} serviceImpl, int methodId) { -this.serviceImpl = serviceImpl; -this.methodId = methodId; -} - -@java.lang.Override -@java.lang.SuppressWarnings("unchecked") -public void invoke(Req request, io.grpc.stub.StreamObserver - responseObserver) { - switch (methodId) { - {{#methods}} - {{^isManyInput}} - case METHODID_{{methodNameUpperUnderscore}}: - serviceImpl.{{methodName}}(({{inputType}}) request, - (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver); - break; - {{/isManyInput}} - {{/methods}} - default: - throw new java.lang.AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver - invoke(io.grpc.stub.StreamObserver - responseObserver) { - switch (methodId) { - {{#methods}} - {{#isManyInput}} - case METHODID_{{methodNameUpperUnderscore}}: - return (io.grpc.stub.StreamObserver - ) serviceImpl.{{methodName}}( - (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver); - {{/isManyInput}} - {{/methods}} - default: - throw new java.lang.AssertionError(); - } - } - } - - } diff --git a/dubbo-plugin/dubbo-compiler/src/main/resources/DubboStub.mustache b/dubbo-plugin/dubbo-compiler/src/main/resources/DubboStub.mustache deleted file mode 100644 index 8bf729e8dd3..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/resources/DubboStub.mustache +++ /dev/null @@ -1,67 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{{#packageName}} - package {{packageName}}; -{{/packageName}} - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicBoolean; - -{{#deprecated}} - @java.lang.Deprecated -{{/deprecated}} -public final class {{className}} { -private static final AtomicBoolean registered = new AtomicBoolean(); - -private static Class init() { -Class clazz = null; -try { -clazz = Class.forName({{serviceName}}Dubbo.class.getName()); -if (registered.compareAndSet(false, true)) { -{{#methodTypes}} - org.apache.dubbo.common.serialize.protobuf.support.ProtobufUtils.marshaller( - {{.}}.getDefaultInstance()); -{{/methodTypes}} -} -} catch (ClassNotFoundException e) { -// ignore -} -return clazz; -} - -private {{serviceName}}Dubbo() {} - -public static final String SERVICE_NAME = "{{packageName}}.{{serviceName}}"; - -/** -* Code generated for Dubbo -*/ -public interface I{{serviceName}} extends org.apache.dubbo.rpc.model.DubboStub { - -static Class clazz = init(); - -{{#methods}} - {{outputType}} {{methodName}}({{inputType}} request); - - CompletableFuture<{{outputType}}> {{methodName}}Async({{inputType}} request); - -{{/methods}} - -} - -} diff --git a/dubbo-plugin/dubbo-compiler/src/main/resources/ReactorDubboGrpcStub.mustache b/dubbo-plugin/dubbo-compiler/src/main/resources/ReactorDubboGrpcStub.mustache deleted file mode 100644 index 952b6151804..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/resources/ReactorDubboGrpcStub.mustache +++ /dev/null @@ -1,223 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{{#packageName}} - package {{packageName}}; -{{/packageName}} - -import org.apache.dubbo.common.URL; - -import java.util.concurrent.TimeUnit; - -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; - -import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; - - -{{#deprecated}} - @java.lang.Deprecated -{{/deprecated}} -public final class {{className}} { -private {{className}}() {} - -public static ReactorDubbo{{serviceName}}Stub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url) { -return new ReactorDubbo{{serviceName}}Stub(channel, callOptions, url); -} - -{{#javaDoc}} - {{{javaDoc}}} -{{/javaDoc}} -public static final class ReactorDubbo{{serviceName}}Stub implements IReactor{{serviceName}} { - -protected URL url; - -protected {{serviceName}}Grpc.{{serviceName}}Stub stub; - -public ReactorDubbo{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url) { -this.url = url; -stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions); -} - -{{#methods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> reactorRequest) { - {{serviceName}}Grpc.{{serviceName}}Stub localStub = stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); - return com.salesforce.reactorgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(reactorRequest, localStub::{{methodName}}); - } - -{{/methods}} -{{#unaryRequestMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} reactorRequest) { - {{serviceName}}Grpc.{{serviceName}}Stub localStub = stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); - return com.salesforce.reactorgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(reactor.core.publisher.Mono.just(reactorRequest), localStub::{{methodName}}); - } - -{{/unaryRequestMethods}} -} - -public interface IReactor{{serviceName}} { -{{#methods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> reactorRequest); - -{{/methods}} -{{#unaryRequestMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} reactorRequest); - -{{/unaryRequestMethods}} -} - -{{#javaDoc}} - {{{javaDoc}}} -{{/javaDoc}} -public static abstract class {{serviceName}}ImplBase implements IReactor{{serviceName}}, io.grpc.BindableService { - -private IReactor{{serviceName}} proxiedImpl; - -public final void setProxiedImpl(IReactor{{serviceName}} proxiedImpl) { -this.proxiedImpl = proxiedImpl; -} - -{{#unaryRequestMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public final {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} reactorRequest) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - -{{/unaryRequestMethods}} -{{#methods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> request) { - throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNIMPLEMENTED); - } - -{{/methods}} -@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { -return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) -{{#methods}} - .addMethod( - {{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(), - {{grpcCallsMethodName}}( - new MethodHandlers< - {{inputType}}, - {{outputType}}>( - proxiedImpl, METHODID_{{methodNameUpperUnderscore}}))) -{{/methods}} -.build(); -} -} - -{{#methods}} - private static final int METHODID_{{methodNameUpperUnderscore}} = {{methodNumber}}; -{{/methods}} - -private static final class MethodHandlers - implements -io.grpc.stub.ServerCalls.UnaryMethod -, -io.grpc.stub.ServerCalls.ServerStreamingMethod -, -io.grpc.stub.ServerCalls.ClientStreamingMethod -, -io.grpc.stub.ServerCalls.BidiStreamingMethod - { -private final IReactor{{serviceName}} serviceImpl; -private final int methodId; - -MethodHandlers(IReactor{{serviceName}} serviceImpl, int methodId) { -this.serviceImpl = serviceImpl; -this.methodId = methodId; -} - -@java.lang.Override -@java.lang.SuppressWarnings("unchecked") -public void invoke(Req request, io.grpc.stub.StreamObserver - responseObserver) { - switch (methodId) { - {{#methods}} - {{^isManyInput}} - case METHODID_{{methodNameUpperUnderscore}}: - com.salesforce.reactorgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(({{inputType}}) request, - (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver, - serviceImpl::{{methodName}}); - break; - {{/isManyInput}} - {{/methods}} - default: - throw new java.lang.AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver - invoke(io.grpc.stub.StreamObserver - responseObserver) { - switch (methodId) { - {{#methods}} - {{#isManyInput}} - case METHODID_{{methodNameUpperUnderscore}}: - return (io.grpc.stub.StreamObserver - ) com.salesforce.reactorgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}( - (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver, - serviceImpl::{{methodName}}); - {{/isManyInput}} - {{/methods}} - default: - throw new java.lang.AssertionError(); - } - } - } - - } diff --git a/dubbo-plugin/dubbo-compiler/src/main/resources/RxDubboGrpcStub.mustache b/dubbo-plugin/dubbo-compiler/src/main/resources/RxDubboGrpcStub.mustache deleted file mode 100644 index f27a0a209b4..00000000000 --- a/dubbo-plugin/dubbo-compiler/src/main/resources/RxDubboGrpcStub.mustache +++ /dev/null @@ -1,257 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{{#packageName}} - package {{packageName}}; -{{/packageName}} - -import org.apache.dubbo.common.URL; - -import java.util.concurrent.TimeUnit; - -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; - -import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; - - -{{#deprecated}} - @java.lang.Deprecated -{{/deprecated}} -public final class {{className}} { -private {{className}}() {} - -public static RxDubbo{{serviceName}}Stub getDubboStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url) { -return new RxDubbo{{serviceName}}Stub(channel, callOptions, url); -} - -{{#javaDoc}} - {{{javaDoc}}} -{{/javaDoc}} -public static final class RxDubbo{{serviceName}}Stub implements IRx{{serviceName}} { - -protected URL url; - -protected {{serviceName}}Grpc.{{serviceName}}Stub stub; - -public RxDubbo{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, URL url) { -this.url = url; -stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions); -} - -{{#methods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> rxRequest) { - return com.salesforce.rxgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(rxRequest, - {{^isManyInput}} - new com.salesforce.reactivegrpc.common.BiConsumer<{{inputType}}, io.grpc.stub.StreamObserver<{{outputType}}>>() { - @java.lang.Override - public void accept({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> observer) { - stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS).{{methodNameCamelCase}}(request, observer); - } - }); - {{/isManyInput}} - {{#isManyInput}} - new com.salesforce.reactivegrpc.common.Function - , io.grpc.stub.StreamObserver<{{inputType}}>>() { - @java.lang.Override - public io.grpc.stub.StreamObserver<{{inputType}}> apply(io.grpc.stub.StreamObserver<{{outputType}}> observer) { - return stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS).{{methodNameCamelCase}}(observer); - } - }); - {{/isManyInput}} - } - -{{/methods}} -{{#unaryRequestMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} rxRequest) { - return com.salesforce.rxgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(io.reactivex.Single.just(rxRequest), - new com.salesforce.reactivegrpc.common.BiConsumer<{{inputType}}, io.grpc.stub.StreamObserver<{{outputType}}>>() { - @java.lang.Override - public void accept({{inputType}} request, io.grpc.stub.StreamObserver<{{outputType}}> observer) { - stub.withDeadlineAfter(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS).{{methodNameCamelCase}}(request, observer); - } - }); - } - -{{/unaryRequestMethods}} -} - -public interface IRx{{serviceName}} { -{{#methods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> rxRequest); - -{{/methods}} -{{#unaryRequestMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} rxRequest); - -{{/unaryRequestMethods}} -} - - -{{#javaDoc}} - {{{javaDoc}}} -{{/javaDoc}} -public static abstract class {{serviceName}}ImplBase implements IRx{{serviceName}}, io.grpc.BindableService { - -private IRx{{serviceName}} proxiedImpl; - -public final void setProxiedImpl(IRx{{serviceName}} proxiedImpl) { -this.proxiedImpl = proxiedImpl; -} -{{#unaryRequestMethods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public final {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} rxRequest) { - throw new UnsupportedOperationException("No need to override this method, extend XxxImplBase and override all methods it allows."); - } - -{{/unaryRequestMethods}} -{{#methods}} - {{#javaDoc}} - {{{javaDoc}}} - {{/javaDoc}} - {{#deprecated}} - @java.lang.Deprecated - {{/deprecated}} - public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodNameCamelCase}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> request) { - throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNIMPLEMENTED); - } - -{{/methods}} -@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { -return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) -{{#methods}} - .addMethod( - {{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(), - {{grpcCallsMethodName}}( - new MethodHandlers< - {{inputType}}, - {{outputType}}>( - proxiedImpl, METHODID_{{methodNameUpperUnderscore}}))) -{{/methods}} -.build(); -} -} - -{{#methods}} - private static final int METHODID_{{methodNameUpperUnderscore}} = {{methodNumber}}; -{{/methods}} - -private static final class MethodHandlers - implements -io.grpc.stub.ServerCalls.UnaryMethod -, -io.grpc.stub.ServerCalls.ServerStreamingMethod -, -io.grpc.stub.ServerCalls.ClientStreamingMethod -, -io.grpc.stub.ServerCalls.BidiStreamingMethod - { -private final IRx{{serviceName}} serviceImpl; -private final int methodId; - -MethodHandlers(IRx{{serviceName}} serviceImpl, int methodId) { -this.serviceImpl = serviceImpl; -this.methodId = methodId; -} - -@java.lang.Override -@java.lang.SuppressWarnings("unchecked") -public void invoke(Req request, io.grpc.stub.StreamObserver - responseObserver) { - switch (methodId) { - {{#methods}} - {{^isManyInput}} - case METHODID_{{methodNameUpperUnderscore}}: - com.salesforce.rxgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(({{inputType}}) request, - (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver, - new com.salesforce.reactivegrpc.common.Function - <{{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}} - <{{inputType}}>, {{#isManyOutput}} - io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}} - io.reactivex.Single{{/isManyOutput}}<{{outputType}}>>() { - @java.lang.Override - public {{#isManyOutput}} - io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}} - io.reactivex.Single{{/isManyOutput}}<{{outputType}}> apply({{#isManyInput}} - io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}} - io.reactivex.Single{{/isManyInput}}<{{inputType}}> single) { - return serviceImpl.{{methodNameCamelCase}}(single); - } - }); - break; - {{/isManyInput}} - {{/methods}} - default: - throw new java.lang.AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver - invoke(io.grpc.stub.StreamObserver - responseObserver) { - switch (methodId) { - {{#methods}} - {{#isManyInput}} - case METHODID_{{methodNameUpperUnderscore}}: - return (io.grpc.stub.StreamObserver - ) com.salesforce.rxgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}( - (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver, - serviceImpl::{{methodNameCamelCase}}); - {{/isManyInput}} - {{/methods}} - default: - throw new java.lang.AssertionError(); - } - } - } - - }