-
Notifications
You must be signed in to change notification settings - Fork 26.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #3960 #3965
fix #3960 #3965
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,10 +146,13 @@ | |
|
||
<metrics_version>2.0.1</metrics_version> | ||
<gson_version>2.8.5</gson_version> | ||
|
||
<jsonrpc_version>1.2.0</jsonrpc_version> | ||
<portlet_version>2.0</portlet_version> | ||
<maven_flatten_version>1.1.0</maven_flatten_version> | ||
<revision>2.7.2-SNAPSHOT</revision> | ||
<javax_annotation_api_version>1.3.2</javax_annotation_api_version> | ||
<junit_version>4.12</junit_version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
|
@@ -571,6 +574,19 @@ | |
<artifactId>testcontainers</artifactId> | ||
<version>${test_container_version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.annotation</groupId> | ||
<artifactId>javax.annotation-api</artifactId> | ||
<version>${javax_annotation_api_version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit_version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Junit 4 is not necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. i'll changed |
||
</dependencies> | ||
</dependencyManagement> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>dubbo-rpc</artifactId> | ||
<groupId>org.apache.dubbo</groupId> | ||
<version>2.7.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>dubbo-rpc-native-thrift</artifactId> | ||
|
||
<packaging>jar</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>The native thrift rpc module of dubbo project</description> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<skip_maven_deploy>false</skip_maven_deploy> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-rpc-api</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.thrift</groupId> | ||
<artifactId>libthrift</artifactId> | ||
<version>0.11.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-serialization-jdk</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
* 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.rpc.protocol.nativethrift; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.rpc.RpcException; | ||
import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol; | ||
import org.apache.thrift.TException; | ||
import org.apache.thrift.TMultiplexedProcessor; | ||
import org.apache.thrift.TProcessor; | ||
import org.apache.thrift.protocol.TCompactProtocol; | ||
import org.apache.thrift.protocol.TMultiplexedProtocol; | ||
import org.apache.thrift.protocol.TProtocol; | ||
import org.apache.thrift.server.TServer; | ||
import org.apache.thrift.server.TThreadedSelectorServer; | ||
import org.apache.thrift.transport.TFramedTransport; | ||
import org.apache.thrift.transport.TNonblockingServerSocket; | ||
import org.apache.thrift.transport.TSocket; | ||
import org.apache.thrift.transport.TTransport; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.net.InetSocketAddress; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* native thrift protocol | ||
*/ | ||
public class ThriftProtocol extends AbstractProxyProtocol { | ||
|
||
public static final int DEFAULT_PORT = 40880; | ||
|
||
public static final String NAME = "nthrift"; | ||
public static final String THRIFT_IFACE = "$Iface"; | ||
public static final String THRIFT_PROCESSOR = "$Processor"; | ||
public static final String THRIFT_CLIENT = "$Client"; | ||
|
||
private static final Map<String,TServer> serverMap = new HashMap<>(); | ||
private TMultiplexedProcessor processor = new TMultiplexedProcessor(); | ||
|
||
@Override | ||
public int getDefaultPort() { | ||
return DEFAULT_PORT; | ||
} | ||
|
||
public ThriftProtocol() { | ||
super(TException.class, RpcException.class); | ||
} | ||
|
||
@Override | ||
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException { | ||
return exportThreadedSelectorServer(impl, type, url); | ||
} | ||
|
||
@Override | ||
protected <T> T doRefer(Class<T> type, URL url) throws RpcException { | ||
return doReferFrameAndCompact(type, url); | ||
} | ||
|
||
public ThriftProtocol(Class<?>... exceptions) { | ||
super(exceptions); | ||
} | ||
|
||
private <T> Runnable exportThreadedSelectorServer(T impl, Class<T> type, URL url) throws RpcException { | ||
|
||
TThreadedSelectorServer.Args tArgs = null; | ||
String typeName = type.getName(); | ||
|
||
TServer tserver = null; | ||
if (typeName.endsWith(THRIFT_IFACE)) { | ||
String processorClsName = typeName.substring(0, typeName.indexOf(THRIFT_IFACE)) + THRIFT_PROCESSOR; | ||
try { | ||
Class<?> clazz = Class.forName(processorClsName); | ||
Constructor constructor = clazz.getConstructor(type); | ||
try { | ||
TProcessor tprocessor = (TProcessor) constructor.newInstance(impl); | ||
processor.registerProcessor(typeName,tprocessor); | ||
|
||
tserver = serverMap.get(url.getAddress()); | ||
if(tserver == null) { | ||
|
||
/**Solve the problem of only 50 of the default number of concurrent connections*/ | ||
TNonblockingServerSocket.NonblockingAbstractServerSocketArgs args = new TNonblockingServerSocket.NonblockingAbstractServerSocketArgs(); | ||
/**1000 connections*/ | ||
args.backlog(1000); | ||
args.bindAddr(new InetSocketAddress(url.getHost(), url.getPort())); | ||
/**timeout: 10s */ | ||
args.clientTimeout(10000); | ||
|
||
TNonblockingServerSocket transport = new TNonblockingServerSocket(args); | ||
|
||
tArgs = new TThreadedSelectorServer.Args(transport); | ||
tArgs.workerThreads(200); | ||
tArgs.selectorThreads(4); | ||
tArgs.acceptQueueSizePerThread(256); | ||
tArgs.processor(processor); | ||
tArgs.transportFactory(new TFramedTransport.Factory()); | ||
tArgs.protocolFactory(new TCompactProtocol.Factory()); | ||
}else{ | ||
return null; // if server is starting, return and do nothing here | ||
} | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
throw new RpcException("Fail to create thrift server(" + url + ") : " + e.getMessage(), e); | ||
} | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
throw new RpcException("Fail to create thrift server(" + url + ") : " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
if (tserver == null && tArgs == null) { | ||
logger.error("Fail to create thrift server(" + url + ") due to null args"); | ||
throw new RpcException("Fail to create thrift server(" + url + ") due to null args"); | ||
} | ||
final TServer thriftServer = new TThreadedSelectorServer(tArgs); | ||
serverMap.put(url.getAddress(),thriftServer); | ||
|
||
new Thread(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
logger.info("Start Thrift ThreadedSelectorServer"); | ||
thriftServer.serve(); | ||
logger.info("Thrift ThreadedSelectorServer started."); | ||
} | ||
}).start(); | ||
|
||
return new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
logger.info("Close Thrift NonblockingServer"); | ||
thriftServer.stop(); | ||
} catch (Throwable e) { | ||
logger.warn(e.getMessage(), e); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private <T> T doReferFrameAndCompact(Class<T> type, URL url) throws RpcException { | ||
|
||
try { | ||
T thriftClient = null; | ||
String typeName = type.getName(); | ||
if (typeName.endsWith(THRIFT_IFACE)) { | ||
String clientClsName = typeName.substring(0, typeName.indexOf(THRIFT_IFACE)) + THRIFT_CLIENT; | ||
Class<?> clazz = Class.forName(clientClsName); | ||
Constructor constructor = clazz.getConstructor(TProtocol.class); | ||
try { | ||
TSocket tSocket = new TSocket(url.getHost(), url.getPort()); | ||
TTransport transport = new TFramedTransport(tSocket); | ||
TProtocol tprotocol = new TCompactProtocol(transport); | ||
TMultiplexedProtocol protocol = new TMultiplexedProtocol(tprotocol,typeName); | ||
thriftClient = (T) constructor.newInstance(protocol); | ||
transport.open(); | ||
logger.info("thrift client opened for service(" + url + ")"); | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
throw new RpcException("Fail to create remote client:" + e.getMessage(), e); | ||
} | ||
} | ||
return thriftClient; | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
throw new RpcException("Fail to create remote client for service(" + url + "): " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nthrift=org.apache.dubbo.rpc.protocol.nativethrift.ThriftProtocol |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
namespace java org.apache.dubbo.rpc.protocol.nativethrift | ||
namespace go demo | ||
/*Demo service define file,can be generated to inteface files*/ | ||
/*Here test the 7 kind of data type*/ | ||
service DemoService { | ||
string sayHello(1:required string name); | ||
|
||
bool hasName( 1:required bool hasName); | ||
|
||
string sayHelloTimes(1:required string name, 2:required i32 times); | ||
|
||
void timeOut(1:required i32 millis); | ||
|
||
string customException(); | ||
|
||
string context(1:required string name); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
namespace java org.apache.dubbo.rpc.protocol.nativethrift | ||
namespace go demo | ||
|
||
service UserService { | ||
string find(1:required i32 id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this declaration? I don't find the place where it was referenced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. i'll remove..i'm just merge this from rpc-native-thrift-for-apache-dubbo to here. it's my fault.btw i find the thirft version of rpc-native-thrift and rpc-thrift is not same. should i make it same or declare 0.11 just in rpc-native-thrift module ??