init
This commit is contained in:
35
did-common/pom.xml
Normal file
35
did-common/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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>did</artifactId>
|
||||
<groupId>cn.ceres.did</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>did-common</artifactId>
|
||||
|
||||
<name>did-common</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
45
did-common/src/main/java/cn/ceres/did/common/Constants.java
Normal file
45
did-common/src/main/java/cn/ceres/did/common/Constants.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package cn.ceres.did.common;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ehlxr
|
||||
*/
|
||||
public class Constants {
|
||||
private static Map<String, String> SYS_ENV = System.getenv();
|
||||
|
||||
public static String getEnv(String key) {
|
||||
return SYS_ENV.get(key) == null ? "" : SYS_ENV.get(key);
|
||||
}
|
||||
|
||||
public static String DEFAULT_HOST = "localhost";
|
||||
/**
|
||||
* HTTP协议和SDK协议服务器的端口
|
||||
*/
|
||||
public static int HTTP_PORT = 16830;
|
||||
public static int SDKS_PORT = 16831;
|
||||
|
||||
/**
|
||||
* HTTP协议和SDK协议的请求路径
|
||||
*/
|
||||
public static String HTTP_REQUEST = "did";
|
||||
public static String SDKS_REQUEST = "did";
|
||||
|
||||
/**
|
||||
* 数据中心的标识ID,取值范围:0~31
|
||||
* 机器或进程的标识ID,取值范围:0~31
|
||||
* 两个标识ID组合在分布式环境中必须唯一
|
||||
*/
|
||||
public static long DATACENTER_ID = 1;
|
||||
public static long MACHINES_SIGN = 1;
|
||||
|
||||
/**
|
||||
* 流量控制,表示每秒处理的并发数
|
||||
*/
|
||||
public static int HANDLE_HTTP_TPS = 10000;
|
||||
public static int HANDLE_SDKS_TPS = 50000;
|
||||
public static int ACQUIRE_TIMEOUTMILLIS = 5000;
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
}
|
46
did-common/src/main/java/cn/ceres/did/common/NettyUtil.java
Normal file
46
did-common/src/main/java/cn/ceres/did/common/NettyUtil.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package cn.ceres.did.common;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* @author ehlxr
|
||||
*/
|
||||
public class NettyUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(NettyUtil.class);
|
||||
|
||||
/**
|
||||
* 获取 Channel 的远程 IP 地址
|
||||
*/
|
||||
public static String parseRemoteAddr(final Channel channel) {
|
||||
if (null == channel) {
|
||||
return "";
|
||||
}
|
||||
SocketAddress remote = channel.remoteAddress();
|
||||
final String addr = remote != null ? remote.toString() : "";
|
||||
|
||||
if (addr.length() > 0) {
|
||||
int index = addr.lastIndexOf("/");
|
||||
if (index >= 0) {
|
||||
return addr.substring(index + 1);
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void closeChannel(Channel channel) {
|
||||
final String addrRemote = parseRemoteAddr(channel);
|
||||
channel.close().addListener(new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) {
|
||||
logger.info("closeChannel: close the connection to remote address[{}] result: {}", addrRemote, future.isSuccess());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
5
did-common/target/maven-archiver/pom.properties
Normal file
5
did-common/target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Tue Aug 14 15:16:52 CST 2018
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.ceres.did
|
||||
artifactId=did-common
|
@@ -0,0 +1,3 @@
|
||||
cn/ceres/did/common/NettyUtil.class
|
||||
cn/ceres/did/common/Constants.class
|
||||
cn/ceres/did/common/NettyUtil$1.class
|
@@ -0,0 +1,2 @@
|
||||
/Users/ehlxr/WorkSpaces/did/did-common/src/main/java/cn/ceres/did/common/Constants.java
|
||||
/Users/ehlxr/WorkSpaces/did/did-common/src/main/java/cn/ceres/did/common/NettyUtil.java
|
Reference in New Issue
Block a user