云快充1.5.0 初始化

This commit is contained in:
3god
2024-10-08 09:38:54 +08:00
parent dea6774942
commit cb19b45919
297 changed files with 18020 additions and 28 deletions

View File

@@ -0,0 +1,24 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import sanbing.jcpp.protocol.cfg.enums.ForwarderType;
@Setter
@Getter
public class ForwarderCfg {
@NotNull
private ForwarderType type;
private MemoryCfg memory;
@Valid
private KafkaCfg kafka;
}

View File

@@ -0,0 +1,49 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg;
import lombok.Getter;
import lombok.Setter;
import sanbing.jcpp.infrastructure.util.property.PropertyUtils;
import java.util.Map;
@Getter
@Setter
public class KafkaCfg {
private String topic;
private boolean jcppPartition;
private String bootstrapServers;
private String acks;
private EncoderType encoder;
private int retries;
private String compressionType; // none, gzip, snappy, lz4, zstd
private int batchSize;
private int lingerMs;
private long bufferMemory;
private Map<String, String> otherProperties; // Other inline properties if necessary
private String topicProperties;
public void setOtherProperties(String otherProperties) {
this.otherProperties = PropertyUtils.getProps(otherProperties);
}
public enum EncoderType {
protobuf,
json
}
}

View File

@@ -0,0 +1,17 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg;
import jakarta.validation.Valid;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ListenerCfg {
@Valid
private TcpCfg tcp;
}

View File

@@ -0,0 +1,18 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg;
import lombok.Getter;
import lombok.Setter;
/**
* @author baigod
*/
@Getter
@Setter
public class MemoryCfg {
private String topic;
}

View File

@@ -0,0 +1,25 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ProtocolCfg {
private boolean enabled;
@NotNull
@Valid
private ListenerCfg listener;
@NotNull
@Valid
private ForwarderCfg forwarder;
}

View File

@@ -0,0 +1,45 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class TcpCfg {
private String bindAddress;
@Max(65000)
private int bindPort;
@Min(1)
private int bossGroupThreadCount;
@Min(1)
private int workerGroupThreadCount;
private boolean soKeepAlive;
@Min(1)
@Max(65500)
private int soBacklog;
@Min(1)
private int soRcvbuf;
@Min(1)
private int soSndbuf;
private boolean nodelay;
@Valid
private TcpHandlerCfg handler;
}

View File

@@ -0,0 +1,55 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.validation.constraints.Min;
import lombok.Getter;
import lombok.Setter;
import sanbing.jcpp.infrastructure.util.jackson.JacksonUtil;
import sanbing.jcpp.infrastructure.util.property.PropertyUtils;
import sanbing.jcpp.protocol.cfg.enums.TcpHandlerType;
import sanbing.jcpp.protocol.listener.tcp.configs.BinaryHandlerConfiguration;
import sanbing.jcpp.protocol.listener.tcp.configs.HandlerConfiguration;
import sanbing.jcpp.protocol.listener.tcp.configs.JsonHandlerConfiguration;
import sanbing.jcpp.protocol.listener.tcp.configs.TextHandlerConfiguration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TcpHandlerCfg {
@Getter
private TcpHandlerType type;
@Min(1)
@Setter
@Getter
private int idleTimeoutSeconds;
@Min(1)
@Setter
@Getter
private int maxConnections;
private final Map<TcpHandlerType, HandlerConfiguration> HANDLER_MAP = new ConcurrentHashMap<>();
public HandlerConfiguration getConfiguration(TcpHandlerType type) {
return HANDLER_MAP.get(type);
}
public void setConfiguration(String configuration) {
final JsonNode cfgJson = JacksonUtil.valueToTree(PropertyUtils.getProps(configuration));
type = TcpHandlerType.valueOf(cfgJson.get("type").asText());
switch (type) {
case TEXT -> HANDLER_MAP.put(type, JacksonUtil.treeToValue(cfgJson, TextHandlerConfiguration.class));
case JSON -> HANDLER_MAP.put(type, JacksonUtil.treeToValue(cfgJson, JsonHandlerConfiguration.class));
case BINARY -> HANDLER_MAP.put(type, JacksonUtil.treeToValue(cfgJson, BinaryHandlerConfiguration.class));
default -> throw new IllegalArgumentException("Unknown TCP handler type: " + type);
}
}
}

View File

@@ -0,0 +1,12 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg.enums;
public enum ForwarderType {
memory, // 本地队列模式
kafka // Kafka模式 - 发送到外部
}

View File

@@ -0,0 +1,14 @@
/**
* 抖音关注:程序员三丙
* 知识星球https://t.zsxq.com/j9b21
*/
package sanbing.jcpp.protocol.cfg.enums;
/**
* @author baigod
*/
public enum TcpHandlerType {
TEXT,
BINARY,
JSON
}