Skip to content
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

add fury serializer #1348

Merged
merged 41 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5415b1b
add FurySerializer
pandalee99 Jul 19, 2023
112d70b
add FurySerializer
pandalee99 Jul 20, 2023
f7d992e
add FurySerializer
pandalee99 Jul 20, 2023
5ffd32b
add FurySerializer
pandalee99 Jul 25, 2023
90b190c
add fury serializer
pandalee99 Jul 31, 2023
aad7adf
add fury serializer
pandalee99 Aug 14, 2023
586fc1b
add fury serializer with test
pandalee99 Aug 15, 2023
dd05c19
add fury serializer with test
pandalee99 Aug 23, 2023
6cc2eff
add fury serializer with test
pandalee99 Aug 28, 2023
7af8b1e
add fury serializer with test
Aug 29, 2023
1de4a05
Support for multiple parameters
Aug 29, 2023
7eb2c96
add whitelist
pandalee99 Aug 29, 2023
7a7c222
add ClassChecker to implement the whitelist mechanism.
pandalee99 Sep 21, 2023
8cf709d
Support hot update
pandalee99 Oct 8, 2023
9e5662a
(fury version) 0.1.1 update to 0.2.0
pandalee99 Oct 9, 2023
d0d591b
Whitelist function optimization
pandalee99 Oct 23, 2023
78700ae
use yaml to replace json ,change init logic, and enhance checker
pandalee99 Oct 27, 2023
a4ab229
to resolve conflicts
pandalee99 Oct 27, 2023
02f3979
to resolve conflicts
pandalee99 Oct 27, 2023
cc1b341
to resolve conflicts
pandalee99 Oct 27, 2023
0d5a0e3
Merge branch 'sofastack:master' into master
pandalee99 Oct 27, 2023
aeeed0a
to resolve build error
pandalee99 Oct 31, 2023
c665175
bug fix
pandalee99 Nov 2, 2023
090f2c5
fix codestyle
pandalee99 Nov 2, 2023
d7d1f29
fix test error
pandalee99 Nov 2, 2023
59be19d
optimized code
Nov 6, 2023
e227ade
Merge branch 'master' of github.com:sofastack/sofa-rpc into pandale99…
Nov 6, 2023
7fe900d
fury update to 0.3.0
pandalee99 Nov 6, 2023
59fdd58
Merge remote-tracking branch 'origin/master'
pandalee99 Nov 6, 2023
480cffa
Merge branch 'sofastack:master' into master
pandalee99 Nov 6, 2023
63eaab7
Merge remote-tracking branch 'origin/master'
pandalee99 Nov 6, 2023
28621f2
bug fix
pandalee99 Nov 6, 2023
03ee605
Configuration file format changes
pandalee99 Nov 8, 2023
f2d8a83
Refactoring Fury Serialization Integration
Jan 2, 2024
7fc8c4f
Refactoring Fury Serialization Integration
Jan 3, 2024
5b1c7c0
refactor: module
Jan 3, 2024
6b4e3d5
Merge branch 'fury_opensource_refactor' into pandalee99/master
Jan 3, 2024
a8d9d02
Refactoring Fury Serialization Integration
Jan 4, 2024
2c71e38
Refactoring Fury Serialization Integration
Jan 4, 2024
6020075
Refactoring Fury Serialization Integration
Jan 5, 2024
e373752
Refactoring Fury Serialization Integration
Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<msgpack.version>0.6.12</msgpack.version>
<protostuff.version>1.5.9</protostuff.version>
<grpc.version>1.33.1</grpc.version>
<fury.version>0.1.0-alpha.1</fury.version>

<!--common-->
<httpcore.version>4.4.13</httpcore.version>
Expand Down Expand Up @@ -297,6 +298,11 @@
<artifactId>msgpack</artifactId>
<version>${msgpack.version}</version>
</dependency>
<dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-core</artifactId>
<version>${fury.version}</version>
</dependency>
<!-- zk client -->
<dependency>
<groupId>org.apache.curator</groupId>
Expand Down
112 changes: 112 additions & 0 deletions codec/codec-fury/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.alipay.sofa</groupId>
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
<artifactId>sofa-rpc-codec</artifactId>
<version>${revision}</version>
</parent>

<artifactId>sofa-rpc-codec-fury</artifactId>

<dependencies>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-codec-api</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-api</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-log</artifactId>
</dependency>

<!-- 默认不主动依赖 -->
<dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-core</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
</dependencies>

<build>
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<testSourceDirectory>src/test/java</testSourceDirectory>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/**</include>
</includes>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<skip>${module.install.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>${module.deploy.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipTests}</skipTests>
<includes>
<!-- 这里需要根据自己的需要指定要跑的单元测试 -->
<include>**/*Test.java</include>
</includes>
<!-- 如无特殊需求,将forkMode设置为once -->
<forkMode>once</forkMode>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* 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 com.alipay.sofa.rpc.codec.fury;

import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.alipay.sofa.rpc.common.utils.ClassUtils;
import com.alipay.sofa.rpc.config.ConfigUniqueNameGenerator;
import com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException;
import com.alipay.sofa.rpc.log.LogCodes;

/**
* @author lipan
*/
public class FuryHelper {
/**
* 请求参数类型缓存 {service+method:class}
*/
private ConcurrentMap<String, Class> requestClassCache = new ConcurrentHashMap<String, Class>();

/**
* 返回结果类型缓存 {service+method:class}
*/
private ConcurrentMap<String, Class> responseClassCache = new ConcurrentHashMap<String, Class>();

/**
* 从缓存中获取请求值类
*
* @param service 接口名
* @param methodName 方法名
* @return 请求参数类
*/
public Class getReqClass(String service, String methodName) {

String key = buildMethodKey(service, methodName);
Class reqClass = requestClassCache.get(key);
if (reqClass == null) {
// 读取接口里的方法参数和返回值
String interfaceClass = ConfigUniqueNameGenerator.getInterfaceName(service);
Class clazz = ClassUtils.forName(interfaceClass, true);
loadProtoClassToCache(key, clazz, methodName);
}
return requestClassCache.get(key);
}

/**
* 从缓存中获取返回值类
*
* @param service 接口名
* @param methodName 方法名
* @return 请求参数类
*/
public Class getResClass(String service, String methodName) {
String key = service + "#" + methodName;
Class reqClass = responseClassCache.get(key);
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
if (reqClass == null) {
// 读取接口里的方法参数和返回值
String interfaceClass = ConfigUniqueNameGenerator.getInterfaceName(service);
Class clazz = ClassUtils.forName(interfaceClass, true);
loadProtoClassToCache(key, clazz, methodName);
}
return responseClassCache.get(key);
}

/**
* 拼装缓存的key
*
* @param serviceName 接口名
* @param methodName 方法名
* @return Key
*/
private String buildMethodKey(String serviceName, String methodName) {
return serviceName + "#" + methodName;
}

/**
* 加载fury接口里方法的参数和返回值类型到缓存,不需要传递
*
* @param key 缓存的key
* @param clazz 接口名
* @param methodName 方法名
*/
private void loadProtoClassToCache(String key, Class clazz, String methodName) {
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
Method pbMethod = null;
Method[] methods = clazz.getMethods();
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
for (Method method : methods) {
if (methodName.equals(method.getName())) {
pbMethod = method;
break;
}
}
if (pbMethod == null) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_METHOD_NOT_FOUND, clazz.getName(),
methodName));
}
Class[] parameterTypes = pbMethod.getParameterTypes();
if (parameterTypes == null || parameterTypes.length != 1) {
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_ONLY_ONE_PARAM, "protobuf",
clazz.getName()));
}
Class reqClass = parameterTypes[0];
requestClassCache.put(key, reqClass);
Class resClass = pbMethod.getReturnType();
if (resClass == void.class) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROTOBUF_RETURN, clazz.getName()));
}
responseClassCache.put(key, resClass);
}
}
Loading