Commit 1d2a73a4 by zhouhaibao

[+]callback统一处理

1 parent 35e05da1
......@@ -35,13 +35,7 @@ public class ParamSettingRspHandler implements TcpHandler<ParamSettingRsp, Param
}
// 结果响应给业务侧
String key = ProxyHelper.getCallbackKey(rsp, channel);
TcpCallback<TcpRsp> callback = ProxyHelper.getCallback(key);
if (Objects.nonNull(callback)) {
callback.callback(rsp);
} else {
log.info("callback为空");
}
ProxyHelper.getCallbackKey(rsp, channel, rsp);
return null;
}
}
......@@ -30,13 +30,8 @@ public class TimeSettingRspHandler implements TcpHandler<TimeSettingRsp, TimeSet
log.info("对时设置响应 pointId {} time {}", Ocpp16Helper.bcdToStr(data.getPileId()), ByteUtils.parseCp56Time2aStr(data.getTime()));
// TODO
String key = ProxyHelper.getCallbackKey(rsp, channel);
TcpCallback<TcpRsp> callback = ProxyHelper.getCallback(key);
if (Objects.nonNull(callback)) {
callback.callback(rsp);
} else {
log.info("callback为空");
}
ProxyHelper.getCallbackKey(rsp, channel,rsp);
return null;
}
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TimeSettingRsp;
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.Map;
......@@ -16,6 +17,7 @@ import cn.hutool.core.util.StrUtil;
import io.netty.channel.Channel;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
@Slf4j
......@@ -67,7 +69,8 @@ public class ProxyHelper {
log.info("【{}】Proxy连接建立:{}", pileId, proxyInfo);
} else {
if (proxyInfo.getChannel().id() != channel.id()) {
log.warn("【警告】pileId:{} 包含两个连接,新:{} 会覆盖旧:{} ...", pileId, channel.toString(), proxyInfo.getChannel().toString());
log.warn("【警告】pileId:{} 包含两个连接,新:{} 会覆盖旧:{} ...", pileId, channel.toString(),
proxyInfo.getChannel().toString());
}
}
proxyInfo.setChannel(channel);
......@@ -148,7 +151,8 @@ public class ProxyHelper {
return;
}
//
log.info("【自检】-------------------------------------------------------------------------------");
log.info(
"【自检】-------------------------------------------------------------------------------");
// log.info("【自检托管】{}", users);
for (ProxyInfo proxy : map.values()) {
log.info("【自检】{}", JacksonUtils.nodefaultMapper.toJson(proxy));
......@@ -175,10 +179,37 @@ public class ProxyHelper {
return callbackMap.get(key);
}
/**
* 获取callback的key
*
* @param data 请求体
* @param channel 通道
* @return
* @param <T>
*/
public static <T extends TcpBase> String getCallbackKey(T data, Channel channel) {
if (channel == null) {
if(channel==null){
throw new RuntimeException("channel为null!!!");
}
return channel.attr(ProxyHelper.PILE_ID_KEY).get() + "+" + data.getSeq();
}
/**
* 获取callback的key,并设置值
*
* @param data 请求体
* @param channel 通道
* @param rsp 返回值
* @param <T>
*/
public static <T extends TcpBase> void getCallbackKey(T data, Channel channel,
TcpRsp rsp) {
String key = getCallbackKey(data, channel);
TcpCallback<TcpRsp> callback = ProxyHelper.getCallback(key);
if (Objects.nonNull(callback)) {
callback.callback(rsp);
} else {
log.info("key{},callback为空", key);
}
}
}
......@@ -26,7 +26,7 @@ public class ModelValTest {
ModelValReq req = new ModelValReq();
req.setData(new ModelValReqData());
req.getData().setPileId(Ocpp16Helper.strToBcd("00000002100010", req.getData().getPileId()));
req.getData().setPileId(Ocpp16Helper.strToBcd("32010200000001", req.getData().getPileId()));
req.getData().setModelCode(Ocpp16Helper.strToBcd("0000", req.getData().getModelCode()));
client.sendSync(req);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!