Skip to content

Commit

Permalink
1:删除之前的代码
Browse files Browse the repository at this point in the history
2:增加hessian2序列化
3:增加自定义注册中心 仅用于管理客户端
  • Loading branch information
force-c committed May 19, 2022
1 parent f2ab5d2 commit 5748d8d
Show file tree
Hide file tree
Showing 46 changed files with 426 additions and 1,560 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
.mvn
45 changes: 18 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<packaging>pom</packaging>
<modules>
<module>simple-rpc-serialization</module>
<module>simple-rpc-api</module>
<module>simple-rpc-registry</module>
</modules>

<groupId>cn.simple.rpc</groupId>
<artifactId>simple-rpc</artifactId>
Expand All @@ -21,29 +20,10 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.77.Final</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
Expand All @@ -60,6 +40,17 @@
<artifactId>slf4j-api</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.66</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>

</dependencies>

<build>
Expand Down
32 changes: 32 additions & 0 deletions simple-rpc-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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">
<parent>
<artifactId>simple-rpc</artifactId>
<groupId>cn.simple.rpc</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simple-rpc-api</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>cn.simple.rpc</groupId>
<artifactId>simple-rpc-registry-simple</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.simple.rpc</groupId>
<artifactId>simple-rpc-serialization-hessian2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

</project>
12 changes: 12 additions & 0 deletions simple-rpc-api/src/main/java/simple/rpc/api/MessageProtocol1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package simple.rpc.api;

/**
*
* 消息协议
*
* @author guochuang
* @version 6.3
* @date 2022/05/19 17:51
*/
public class MessageProtocol1 {
}
12 changes: 12 additions & 0 deletions simple-rpc-api/src/main/java/simple/rpc/api/net/NetClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package simple.rpc.api.net;

/**
*
* 网络客户端
*
* @author guochuang
* @version 6.3
* @date 2022/05/19 18:34
*/
public class NetClient {
}
66 changes: 66 additions & 0 deletions simple-rpc-api/src/main/java/simple/rpc/api/net/NetServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package simple.rpc.api.net;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.extern.slf4j.Slf4j;

/**
*
* 网络服务端
*
* @author guochuang
* @version 6.3
* @date 2022/05/19 18:34
*/
@Slf4j
public class NetServer {

private final int port;

private Channel channel;

public NetServer(int port) {
this.port = port;
}

public void start() {

NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
NioEventLoopGroup workGroup = new NioEventLoopGroup();

try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.childHandler((new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline()
.addLast(null);
}
}));
ChannelFuture future = serverBootstrap.bind(port).sync();
channel = future.channel();
channel.closeFuture().sync();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}

public void stop() {
channel.close();
}

// private class ChannelHandler

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package simple.rpc.api.protocol;

import java.io.Serializable;

/**
* 消息传输协议
*
* @author guochuang
* @version 6.3
* @date 2022/05/19 17:52
*/
public class MessageProtocol implements Serializable {


private String version;

private long serialization;

private Object message;


}
23 changes: 23 additions & 0 deletions simple-rpc-registry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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">
<parent>
<artifactId>simple-rpc</artifactId>
<groupId>cn.simple.rpc</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simple-rpc-registry</artifactId>
<packaging>pom</packaging>
<modules>
<module>simple-rpc-registry-simple</module>
</modules>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

</project>
19 changes: 19 additions & 0 deletions simple-rpc-registry/simple-rpc-registry-simple/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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">
<parent>
<artifactId>simple-rpc-registry</artifactId>
<groupId>cn.simple.rpc</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simple-rpc-registry-simple</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package simple.rpc.registry.simple;

import io.netty.channel.ChannelHandlerContext;

import java.util.HashMap;
import java.util.Map;

/**
* @author guochuang
* @version 6.3
* @date 2022/05/19 18:42
*/
public class SimpleRegistry {

private static final Map<String, ChannelHandlerContext> CTX_CONTAINER1 = new HashMap<>();

private static final Map<ChannelHandlerContext, String> CTX_CONTAINER2 = new HashMap<>();

@SuppressWarnings("unchecked")
public static <T> T get(Object key) {

if (key instanceof String) {
return (T) CTX_CONTAINER1.get(key);
}
if (key instanceof ChannelHandlerContext) {
return (T) CTX_CONTAINER2.get(key);
}
return null;
}

public static void put(String clientId, ChannelHandlerContext ctx) {
CTX_CONTAINER1.put(clientId, ctx);
CTX_CONTAINER2.put(ctx, clientId);
}

}
24 changes: 24 additions & 0 deletions simple-rpc-serialization/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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">
<parent>
<groupId>cn.simple.rpc</groupId>
<artifactId>simple-rpc</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simple-rpc-serialization</artifactId>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<modules>
<module>simple-rpc-serialization-hessian2</module>
</modules>

</project>
20 changes: 20 additions & 0 deletions simple-rpc-serialization/simple-rpc-serialization-hessian2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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">
<parent>
<groupId>cn.simple.rpc</groupId>
<artifactId>simple-rpc-serialization</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simple-rpc-serialization-hessian2</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

</project>
Loading

0 comments on commit 5748d8d

Please sign in to comment.