Skip to content

Commit

Permalink
sync code starlight (#390)
Browse files Browse the repository at this point in the history
sync code starlight to support sse and crac
  • Loading branch information
tullyliu authored Jan 20, 2025
1 parent d5ab7ce commit cd6d1d1
Show file tree
Hide file tree
Showing 81 changed files with 2,945 additions and 431 deletions.
174 changes: 166 additions & 8 deletions starlight/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

<groupId>com.baidu.cloud</groupId>
<artifactId>starlight</artifactId>
<version>2022.2.2-SNAPSHOT</version>
<version>2024.0.2-SNAPSHOT</version>
<packaging>pom</packaging>

<name>${project.groupId}:${project.artifactId}</name>
<name>starlight</name>
<description>Starlight: simple fast rpc framework</description>

<modules>
Expand All @@ -25,6 +24,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<!-- plugin versions -->
<git-commit-id-plugin.version>2.2.5</git-commit-id-plugin.version>
<powermock.version>2.0.9</powermock.version>
<skip_maven_deploy>false</skip_maven_deploy>

Expand Down Expand Up @@ -81,13 +81,135 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<additionalJOptions>-Xdoclint:none</additionalJOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>${git-commit-id-plugin.version}</version>
<configuration>
<verbose>true</verbose>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
</configuration>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
</plugin>

<!--
在mac m1的电脑上会报错,原因是protoc2.5.0版本没有发布过arm的软件包。
解决方式如下:
1. 修改settings.xml文件 @see https://github.com/os72/protoc-jar/issues/93#issuecomment-1300577691
2. 运行mvn命令带一个参数 -Dos.arch=x86_64
这两种解决方法的思路都是让系统由arm被识别为x86_64,不用担心系统不兼容,m1芯片能兼容运行x86_64软件
-->
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.6.0.1</version>
<executions>
<execution>
<id>generate-sources</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<protocVersion>2.5.0</protocVersion>
<addSources>none</addSources>
<includeStdTypes>true</includeStdTypes>
<outputDirectory>src/main/java</outputDirectory>
<inputDirectories>
<include>src/main/proto</include>
</inputDirectories>
</configuration>
</execution>
<execution>
<id>generate-test-sources</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<protocVersion>2.5.0</protocVersion>
<includeStdTypes>true</includeStdTypes>
<addSources>none</addSources>
<outputDirectory>src/test/java</outputDirectory>
<inputDirectories>
<include>src/test/proto</include>
</inputDirectories>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand All @@ -98,23 +220,59 @@
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<skip>${skip_maven_deploy}</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>-Dfile.encoding=UTF-8 -Xms512m -Xmx1024m</argLine>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>

<configuration>
<instrumentation>
<excludes>
<exclude>com/baidu/cloud/starlight/benchmark/**/*.class</exclude>
<exclude>com/baidu/cloud/starlight/core/benchmark/**/*.class</exclude>
<exclude>com/baidu/cloud/starlight/api/exception/*.class</exclude>
<exclude>com/baidu/cloud/starlight/api/extension/*.class</exclude>
<exclude>org/openjdk/jmh/infra/generated/**/*.class</exclude>
</excludes>
</instrumentation>
<formats>
<format>xml</format>
<format>html</format>
</formats>
<check />
<aggregate>true</aggregate>
</configuration>
</plugin>

<plugin>
Expand Down
2 changes: 1 addition & 1 deletion starlight/starlight-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.baidu.cloud</groupId>
<artifactId>starlight</artifactId>
<version>2022.2.2-SNAPSHOT</version>
<version>2024.0.2-SNAPSHOT</version>
</parent>

<artifactId>starlight-all</artifactId>
Expand Down
10 changes: 8 additions & 2 deletions starlight/starlight-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
<parent>
<groupId>com.baidu.cloud</groupId>
<artifactId>starlight</artifactId>
<version>2022.2.2-SNAPSHOT</version>
<version>2024.0.2-SNAPSHOT</version>
</parent>

<artifactId>starlight-api</artifactId>
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand All @@ -22,7 +28,7 @@
<dependency>
<groupId>com.baidu.cloud</groupId>
<artifactId>spring-cloud-baidu-thirdparty-commons</artifactId>
<version>2023.0.1-SNAPSHOT</version>
<version>2024.0.1-SNAPSHOT</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,6 @@ public class Constants {
*/
public static final String SESSION_ID_KEY = "session.id";

/**
* biz thread pool name key, use spi to create ThreadPoolFactory
*/
public static final String BIZ_THREAD_POOL_NAME_KEY = "biz_thread_pool_name";

/**
* default biz thread pool name, use spi to create ThreadPoolFactory
*/
public static final String DEFAULT_BIZ_THREAD_POOL_NAME = "rpc";

/**
* Default thread pool size
*/
Expand Down Expand Up @@ -352,12 +342,12 @@ public class Constants {
public static final String LOCALHOST_VALUE = "127.0.0.1";

/**
* Generic Key, support Starlight Client to generic call to stargate server
* Generic Key, used in stargate protocol support Starlight Client ---> generic call ----> stargate server
*/
public static final String GENERIC_KEY = "generic";

/**
* Stargate uuid, used in stargate protocol support stargate Client call to starlight server
* Stargate uuid, used in stargate protocol support stargate Client ---> call ----> starlight server
*/
public static final String STARGATE_UUID = "stargate.id";

Expand Down Expand Up @@ -585,24 +575,17 @@ public class Constants {
public static final String STARGATE_REQUEST_ID_KEY = "stargate.rid";

/**
* s means server side
* sse call back attribute key
*/
public static final String SERVER_BIZ_THREAD_NAME_PREFIX = "star-s-biz";
public static final String SSE_CALLBACK_ATTR_KEY = "sse_callback";

/**
* c means client side
* sse embedded channel attribute key
*/
public static final String CLIENT_BIZ_THREAD_NAME_PREFIX = "star-c-biz";

public static final String CLIENT_NIO_THREAD_NAME_PREFIX = "star-c-nio";
public static final String SSE_EMBEDDED_CHANNEL_KEY = "sse_embedded_channel";

public static final String CLIENT_EPOLL_THREAD_NAME_PREFIX = "star-c-epoll";

public static final String SERVER_NIO_THREAD_NAME_PREFIX = "star-s-nio";

public static final String SERVER_EPOLL_THREAD_NAME_PREFIX = "star-s-epoll";

public static final String SERVER_EPOLL_ACCEPT_THREAD_NAME_PREFIX = "star-s-epoll-accept";

public static final String SERVER_NIO_ACCEPT_THREAD_NAME_PREFIX = "star-s-nio-accept";
/**
* sse call back request id
*/
public static final String SSE_REQUEST_ID_KEY = "sse_requset_id";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static RpcRequest heartbeatRequest() {
heartbeatRequest.setParamsTypes(new Class[] {Heartbeat.class});
heartbeatRequest.setProtocolName(Constants.BRPC_VALUE);
heartbeatRequest.setReturnType(Heartbeat.class);
heartbeatRequest.setGenericReturnType(Heartbeat.class);

return heartbeatRequest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static RpcResponse heartbeatResponse(RpcRequest heartbeatRequest) {
heartbeatResponse.setReturnType(Heartbeat.class);
heartbeatResponse.setResult(new Heartbeat(Constants.PONG));
heartbeatResponse.setProtocolName(heartbeatRequest.getProtocolName());
heartbeatResponse.setGenericReturnType(Heartbeat.class);

return heartbeatResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public interface MsgBase {
void setCompressType(int compressType);

/**
* Get Protocol name, when decoding
* Get Protocol name, used to decode <1>Get when decoding</1>
*
* @return
*/
String getProtocolName();

/**
* Set Protocol name, used to encode Then value may set when making a request or call decode
* Set Protocol name, used to encode <1>Set when making a request</1> <2>Set when decoding</2>
*
* @param protocolName
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public Object get() throws InterruptedException, ExecutionException {
@Override
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
countDownLatch.await(timeout, unit);
if (response == null) { // 在限定时间内未返回,则返回TimeoutException
throw new TimeoutException();
}
return result();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.baidu.cloud.starlight.api.transport.ClientPeer;
import com.baidu.cloud.starlight.api.serialization.serializer.Serializer;

import java.lang.reflect.Type;

/**
* Invoker, invoke the rpc call and handle exceptions There are two types: Client and Server. Created by liuruisen on
* 2019/12/18.
Expand All @@ -31,12 +29,12 @@ public interface Invoker {
/**
* Invoke on the client or server side. Async call.
* <p>
* <b>Client side</b> Pack and {@link Serializer#serialize(Object, Type)} message. Delegate {@link ClientPeer} to
* <b>Client side</b> Pack and {@link Serializer#serialize(Object, Class)} message. Delegate {@link ClientPeer} to
* implement real communication.
* </p>
*
* <p>
* <b>Server side</b> Unpack and {@link Serializer#deserialize(byte[], Type)} message. Invoke the real method by
* <b>Server side</b> Unpack and {@link Serializer#deserialize(byte[], Class)} message. Invoke the real method by
* java reflection.
* </p>
*
Expand Down
Loading

0 comments on commit cd6d1d1

Please sign in to comment.