-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2:增加hessian2序列化 3:增加自定义注册中心 仅用于管理客户端
- Loading branch information
Showing
46 changed files
with
426 additions
and
1,560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
simple-rpc-api/src/main/java/simple/rpc/api/MessageProtocol1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
simple-rpc-api/src/main/java/simple/rpc/api/net/NetClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
simple-rpc-api/src/main/java/simple/rpc/api/net/NetServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
simple-rpc-api/src/main/java/simple/rpc/api/protocol/MessageProtocol.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
...y/simple-rpc-registry-simple/src/main/java/simple/rpc/registry/simple/SimpleRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
simple-rpc-serialization/simple-rpc-serialization-hessian2/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.