mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-06 19:09:57 +08:00
云快充1.5.0 初始化
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.protocol.domain;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
*/
|
||||
public enum DownlinkCmdEnum {
|
||||
|
||||
LOGIN_ACK,
|
||||
|
||||
VERIFY_PRICING_ACK,
|
||||
|
||||
QUERY_PRICING_ACK,
|
||||
|
||||
SET_PRICING,
|
||||
|
||||
REMOTE_START_CHARGING,
|
||||
|
||||
TRANSACTION_RECORD,
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.protocol.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ListenerToHandlerMsg(UUID id, byte[] msg, ProtocolSession session) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.protocol.domain;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.DownlinkRestMessage;
|
||||
import sanbing.jcpp.protocol.forwarder.Forwarder;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
*/
|
||||
@Getter
|
||||
@Slf4j
|
||||
public abstract class ProtocolSession implements Closeable {
|
||||
|
||||
private static final int REQUEST_CACHE_LIMIT = 1000;
|
||||
|
||||
protected final String protocolName;
|
||||
|
||||
protected final UUID id;
|
||||
|
||||
@Setter
|
||||
protected LocalDateTime lastActivityTime;
|
||||
|
||||
protected final Set<String> pileCodeSet;
|
||||
|
||||
private final Map<String, ScheduledFuture<?>> scheduledFutures = new ConcurrentHashMap<>();
|
||||
|
||||
private final Cache<String, Object> requestCache = Caffeine.newBuilder()
|
||||
.initialCapacity(REQUEST_CACHE_LIMIT)
|
||||
.maximumSize(REQUEST_CACHE_LIMIT)
|
||||
.expireAfterAccess(Duration.ofMinutes(1))
|
||||
.build();
|
||||
|
||||
@Setter
|
||||
private Forwarder forwarder;
|
||||
|
||||
public ProtocolSession(String protocolName) {
|
||||
this.protocolName = protocolName;
|
||||
this.pileCodeSet = new LinkedHashSet<>();
|
||||
this.id = UUID.randomUUID();
|
||||
this.lastActivityTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public abstract void onDownlink(DownlinkRestMessage downlinkMsg);
|
||||
|
||||
public void close() {
|
||||
close(SessionCloseReason.DESTRUCTION);
|
||||
}
|
||||
|
||||
public void close(SessionCloseReason reason) {
|
||||
log.info("[{}] Protocol会话关闭,原因: {}", this, reason);
|
||||
|
||||
scheduledFutures.values().forEach(scheduledFuture -> scheduledFuture.cancel(true));
|
||||
scheduledFutures.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + id + "]" + pileCodeSet;
|
||||
}
|
||||
|
||||
public void addPileCode(String pileCode) {
|
||||
this.pileCodeSet.add(pileCode);
|
||||
}
|
||||
|
||||
public void addSchedule(String name, Function<String, ScheduledFuture<?>> scheduledFutureFunction) {
|
||||
scheduledFutures.computeIfAbsent(name, scheduledFutureFunction);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.protocol.domain;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
public record ProtocolUplinkMsg<T>(SocketAddress address, UUID id, T data, int size) {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (data instanceof byte[]) {
|
||||
return ByteBufUtil.hexDump((byte[]) data);
|
||||
} else {
|
||||
return data.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.protocol.domain;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
*/
|
||||
public enum SessionCloseReason {
|
||||
DESTRUCTION,
|
||||
INACTIVE,
|
||||
MANUALLY
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.protocol.domain;
|
||||
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.DownlinkRestMessage;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
*/
|
||||
public record SessionToHandlerMsg(DownlinkRestMessage downlinkMsg, ProtocolSession session) {
|
||||
}
|
||||
Reference in New Issue
Block a user