Skip to content

Commit

Permalink
feat:use new compiler (sofastack#953)
Browse files Browse the repository at this point in the history
* feat:use new compiler

* feat:remove default for jdk6

* Revert "feat:remove default for jdk6"

This reverts commit 39b1162

* fix: fix unit test

Co-authored-by: zhangchengxi <[email protected]>
  • Loading branch information
leizhiyuan and OrezzerO authored Jul 15, 2020
1 parent 4b9ffd9 commit 6d8ac98
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 152 deletions.
4 changes: 2 additions & 2 deletions compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-compiler</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -109,7 +109,7 @@
</execution>
</executions>
<configuration>
<configFile>${user.dir}/tools/codestyle/formatter.xml</configFile>
<configFile>${user.dir}/../tools/codestyle/formatter.xml</configFile>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Expand Down
13 changes: 3 additions & 10 deletions compiler/src/main/resources/ReactorSofaTripleStub.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
package {{packageName}};
{{/packageName}}

import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.config.ConsumerConfig;

import java.util.concurrent.TimeUnit;

import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor;
Expand All @@ -23,8 +20,8 @@ comments = "Source: {{protoName}}")
public final class {{className}} {
private {{className}}() {}

public static ReactorSofa{{serviceName}}Stub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
return new ReactorSofa{{serviceName}}Stub(channel, callOptions, providerInfo, consumerConfig,timeout);
public static ReactorSofa{{serviceName}}Stub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, int timeout) {
return new ReactorSofa{{serviceName}}Stub(channel, callOptions, timeout);
}

public static String getServiceName() {
Expand All @@ -36,15 +33,11 @@ return {{packageName}}.{{serviceName}}Grpc.SERVICE_NAME;
{{/javaDoc}}
public static final class ReactorSofa{{serviceName}}Stub implements IReactor{{serviceName}} {
protected ProviderInfo providerInfo;
protected ConsumerConfig consumerConfig;
protected int timeout;
protected {{serviceName}}Grpc.{{serviceName}}Stub stub;

public ReactorSofa{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
this.providerInfo = providerInfo;
this.consumerConfig = consumerConfig;
public ReactorSofa{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, int timeout) {
this.timeout = timeout;
stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions);
}
Expand Down
13 changes: 3 additions & 10 deletions compiler/src/main/resources/RxSofaTripleStub.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
package {{packageName}};
{{/packageName}}

import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.config.ConsumerConfig;

import java.util.concurrent.TimeUnit;

import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor;
Expand All @@ -23,8 +20,8 @@ comments = "Source: {{protoName}}")
public final class {{className}} {
private {{className}}() {}

public static RxSofa{{serviceName}}Stub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
return new RxSofa{{serviceName}}Stub(channel, callOptions, providerInfo, consumerConfig, timeout);
public static RxSofa{{serviceName}}Stub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, int timeout) {
return new RxSofa{{serviceName}}Stub(channel, callOptions, timeout);
}

public static String getServiceName() {
Expand All @@ -36,15 +33,11 @@ return {{packageName}}.{{serviceName}}Grpc.SERVICE_NAME;
{{/javaDoc}}
public static final class RxSofa{{serviceName}}Stub implements IRx{{serviceName}} {
protected ProviderInfo providerInfo;
protected ConsumerConfig consumerConfig;
protected int timeout;
protected {{serviceName}}Grpc.{{serviceName}}Stub stub;

public RxSofa{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
this.providerInfo = providerInfo;
this.consumerConfig = consumerConfig;
public RxSofa{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, int timeout) {
this.timeout = timeout;
stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions);
}
Expand Down
13 changes: 3 additions & 10 deletions compiler/src/main/resources/SofaTripleStub.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
package {{packageName}};
{{/packageName}}

import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.config.ConsumerConfig;

import java.util.concurrent.TimeUnit;

import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor;
Expand All @@ -26,17 +23,13 @@ private {{className}}() {}

public static class Sofa{{serviceName}}Stub implements I{{serviceName}} {
protected ProviderInfo providerInfo;
protected ConsumerConfig consumerConfig;
protected int timeout;
protected {{serviceName}}Grpc.{{serviceName}}BlockingStub blockingStub;
protected {{serviceName}}Grpc.{{serviceName}}FutureStub futureStub;
protected {{serviceName}}Grpc.{{serviceName}}Stub stub;

public Sofa{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions,ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
this.providerInfo = providerInfo;
this.consumerConfig = consumerConfig;
public Sofa{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, int timeout) {
this.timeout = timeout;
blockingStub = {{serviceName}}Grpc.newBlockingStub(channel).build(channel, callOptions);
Expand Down Expand Up @@ -105,8 +98,8 @@ stub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions);
{{/biStreamingMethods}}
}

public static Sofa{{serviceName}}Stub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
return new Sofa{{serviceName}}Stub(channel, callOptions, providerInfo, consumerConfig, timeout);
public static Sofa{{serviceName}}Stub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions,int timeout) {
return new Sofa{{serviceName}}Stub(channel, callOptions, timeout);
}

public static String getServiceName() {
Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<properties>
<protoc.version>3.11.0</protoc.version>
<protoc-gen-grpc-java.version>1.17.0</protoc-gen-grpc-java.version>
<sofa.rpc.compiler.version>0.0.1</sofa.rpc.compiler.version>
<sofa.rpc.compiler.version>0.0.2</sofa.rpc.compiler.version>
<grpc.version>1.28.0</grpc.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>
Expand Down
37 changes: 0 additions & 37 deletions example/src/main/proto/TripleCoreMgetService.proto

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<skipTests>false</skipTests>
<protoc.version>3.7.1</protoc.version>
<grpc.version>1.27.2</grpc.version>
<sofa.rpc.compiler.version>0.0.1</sofa.rpc.compiler.version>
<sofa.rpc.compiler.version>0.0.2</sofa.rpc.compiler.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package triple;

import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.config.ConsumerConfig;

import java.util.concurrent.TimeUnit;

import static triple.GenericServiceGrpc.getServiceDescriptor;
Expand All @@ -21,17 +18,13 @@ private SofaGenericServiceTriple() {}

public static class SofaGenericServiceStub implements IGenericService {

protected ProviderInfo providerInfo;
protected ConsumerConfig consumerConfig;
protected int timeout;

protected GenericServiceGrpc.GenericServiceBlockingStub blockingStub;
protected GenericServiceGrpc.GenericServiceFutureStub futureStub;
protected GenericServiceGrpc.GenericServiceStub stub;

public SofaGenericServiceStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions,ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
this.providerInfo = providerInfo;
this.consumerConfig = consumerConfig;
public SofaGenericServiceStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, int timeout) {
this.timeout = timeout;

blockingStub = GenericServiceGrpc.newBlockingStub(channel).build(channel, callOptions);
Expand Down Expand Up @@ -59,8 +52,8 @@ public void generic(triple.Request request, io.grpc.stub.StreamObserver<triple.R

}

public static SofaGenericServiceStub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions, ProviderInfo providerInfo, ConsumerConfig consumerConfig, int timeout) {
return new SofaGenericServiceStub(channel, callOptions, providerInfo, consumerConfig, timeout);
public static SofaGenericServiceStub getSofaStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions,int timeout) {
return new SofaGenericServiceStub(channel, callOptions, timeout);
}

public static String getServiceName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public TripleClientInvoker(ConsumerConfig consumerConfig, Channel channel) {
if (!useGeneric) {
Class enclosingClass = consumerConfig.getProxyClass().getEnclosingClass();
try {
sofaStub = enclosingClass.getDeclaredMethod("getSofaStub", Channel.class, CallOptions.class,
ProviderInfo.class, ConsumerConfig.class, int.class);
sofaStub = enclosingClass.getDeclaredMethod("getSofaStub", Channel.class, CallOptions.class, int.class);
} catch (NoSuchMethodException e) {
LOGGER.error("getSofaStub not found in enclosingClass" + enclosingClass.getName());
}
Expand All @@ -98,8 +97,7 @@ public SofaResponse invoke(SofaRequest sofaRequest, int timeout)
if (!useGeneric) {
SofaResponse sofaResponse = new SofaResponse();
ProviderInfo providerInfo = null;
Object stub = sofaStub.invoke(null, channel, buildCustomCallOptions(sofaRequest, timeout), providerInfo,
consumerConfig, timeout);
Object stub = sofaStub.invoke(null, channel, buildCustomCallOptions(sofaRequest, timeout), timeout);
final Method method = sofaRequest.getMethod();
Object appResponse = method.invoke(stub, sofaRequest.getMethodArgs()[0]);
sofaResponse.setAppResponse(appResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.alipay.sofa.rpc.utils;

import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.common.utils.ClassUtils;
import com.alipay.sofa.rpc.config.ConsumerConfig;
import io.grpc.BindableService;
Expand Down Expand Up @@ -52,8 +51,7 @@ public static boolean checkIfUseGeneric(ConsumerConfig consumerConfig) {
Class enclosingClass = proxyClass.getEnclosingClass();
if (enclosingClass != null) {
try {
enclosingClass.getDeclaredMethod("getSofaStub", Channel.class, CallOptions.class,
ProviderInfo.class, ConsumerConfig.class, int.class);
enclosingClass.getDeclaredMethod("getSofaStub", Channel.class, CallOptions.class, int.class);
return false;
} catch (NoSuchMethodException e) {
//ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public void testCheckIfUseGeneric() {
}

static class NeedGeneric {
public void getSofaStub1(Channel channel, CallOptions callOptions,
ProviderInfo providerInfo, ConsumerConfig consumerConfig, int integer) {
public void getSofaStub1(Channel channel, CallOptions callOptions, int integer) {

}

Expand All @@ -89,8 +88,7 @@ interface NeedGenericInterface {
}

static class DoNotNeedGeneric {
public void getSofaStub(Channel channel, CallOptions callOptions,
ProviderInfo providerInfo, ConsumerConfig consumerConfig, int integer) {
public void getSofaStub(Channel channel, CallOptions callOptions, int integer) {

}

Expand Down
2 changes: 1 addition & 1 deletion test/test-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<properties>
<protoc.version>3.11.0</protoc.version>
<protoc-gen-grpc-java.version>1.17.0</protoc-gen-grpc-java.version>
<sofa.rpc.compiler.version>0.0.1</sofa.rpc.compiler.version>
<sofa.rpc.compiler.version>0.0.2</sofa.rpc.compiler.version>
<grpc.version>1.28.0</grpc.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>
Expand Down

0 comments on commit 6d8ac98

Please sign in to comment.