cleanup code by sonar

This commit is contained in:
三丙
2024-10-11 15:27:42 +08:00
parent 62a712ea36
commit 22c93292d0
6 changed files with 20 additions and 20 deletions

View File

@@ -12,7 +12,7 @@ import java.io.Serializable;
public abstract class VersionedCaffeineCache<K extends VersionedCacheKey, V extends Serializable & HasVersion> extends CaffeineTransactionalCache<K, V> implements VersionedCache<K, V> { public abstract class VersionedCaffeineCache<K extends VersionedCacheKey, V extends Serializable & HasVersion> extends CaffeineTransactionalCache<K, V> implements VersionedCache<K, V> {
public VersionedCaffeineCache(CacheManager cacheManager, String cacheName) { protected VersionedCaffeineCache(CacheManager cacheManager, String cacheName) {
super(cacheManager, cacheName); super(cacheManager, cacheName);
} }

View File

@@ -60,7 +60,7 @@ public abstract class AbstractQueueConsumerTemplate<R, T extends QueueMsg> imple
List<R> records; List<R> records;
long startNanos = System.nanoTime(); long startNanos = System.nanoTime();
if (stopped) { if (stopped) {
log.error("poll invoked but consumer stopped for topic " + topic, new RuntimeException("stacktrace")); log.error("poll invoked but consumer stopped for topic {}", topic, new RuntimeException("stacktrace"));
return emptyList(); return emptyList();
} }
if (!subscribed && partitions == null && subscribeQueue.isEmpty()) { if (!subscribed && partitions == null && subscribeQueue.isEmpty()) {
@@ -68,7 +68,7 @@ public abstract class AbstractQueueConsumerTemplate<R, T extends QueueMsg> imple
} }
if (consumerLock.isLocked()) { if (consumerLock.isLocked()) {
log.error("poll. consumerLock is locked. will wait with no timeout. it looks like a race conditions or deadlock topic " + topic, new RuntimeException("stacktrace")); log.error("poll. consumerLock is locked. will wait with no timeout. it looks like a race conditions or deadlock topic {}", topic, new RuntimeException("stacktrace"));
} }
consumerLock.lock(); consumerLock.lock();
@@ -132,7 +132,7 @@ public abstract class AbstractQueueConsumerTemplate<R, T extends QueueMsg> imple
@Override @Override
public void commit() { public void commit() {
if (consumerLock.isLocked()) { if (consumerLock.isLocked()) {
log.error("commit. consumerLock is locked. will wait with no timeout. it looks like a race conditions or deadlock topic " + topic, new RuntimeException("stacktrace")); log.error("commit. consumerLock is locked. will wait with no timeout. it looks like a race conditions or deadlock topic {}", topic, new RuntimeException("stacktrace"));
} }
consumerLock.lock(); consumerLock.lock();
try { try {

View File

@@ -57,10 +57,10 @@ public class AbstractYunKuaiChongCmdExe {
return TOP_BYTE; return TOP_BYTE;
case PEAK: case PEAK:
return PEAK_BYTE; return PEAK_BYTE;
case FLAT:
return FLAT_BYTE;
case VALLEY: case VALLEY:
return VALLEY_BYTE; return VALLEY_BYTE;
default:
return FLAT_BYTE;
} }
} }
} }

View File

@@ -34,8 +34,8 @@ import static sanbing.jcpp.infrastructure.util.codec.ByteUtil.checkCrcSum;
@Slf4j @Slf4j
public class YunKuaiChongV15ProtocolMessageProcessor extends ProtocolMessageProcessor { public class YunKuaiChongV15ProtocolMessageProcessor extends ProtocolMessageProcessor {
private final Map<Byte, YunKuaiChongUplinkCmdExe> UPLINK_CMD_EXE_MAP = new ConcurrentHashMap<>(); private final Map<Byte, YunKuaiChongUplinkCmdExe> uplinkCmdExeMap = new ConcurrentHashMap<>();
private final Map<Byte, YunKuaiChongDownlinkCmdExe> DOWNLINK_CMD_EXE_MAP = new ConcurrentHashMap<>(); private final Map<Byte, YunKuaiChongDownlinkCmdExe> downlinkCmdExeMap = new ConcurrentHashMap<>();
public YunKuaiChongV15ProtocolMessageProcessor(Forwarder forwarder, ProtocolContext protocolContext) { public YunKuaiChongV15ProtocolMessageProcessor(Forwarder forwarder, ProtocolContext protocolContext) {
super(forwarder, protocolContext); super(forwarder, protocolContext);
@@ -46,8 +46,10 @@ public class YunKuaiChongV15ProtocolMessageProcessor extends ProtocolMessageProc
byte cmd = clazz.getAnnotation(YunKuaiChongCmd.class).value(); byte cmd = clazz.getAnnotation(YunKuaiChongCmd.class).value();
try { try {
YunKuaiChongUplinkCmdExe yunKuaiChongUplinkCmdExe = (YunKuaiChongUplinkCmdExe) clazz.getDeclaredConstructor().newInstance(); YunKuaiChongUplinkCmdExe yunKuaiChongUplinkCmdExe = (YunKuaiChongUplinkCmdExe) clazz.getDeclaredConstructor().newInstance();
UPLINK_CMD_EXE_MAP.put(cmd, yunKuaiChongUplinkCmdExe); uplinkCmdExeMap.put(cmd, yunKuaiChongUplinkCmdExe);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | } catch (InstantiationException |
IllegalAccessException |
InvocationTargetException |
NoSuchMethodException e) { NoSuchMethodException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -58,8 +60,10 @@ public class YunKuaiChongV15ProtocolMessageProcessor extends ProtocolMessageProc
byte cmd = clazz.getAnnotation(YunKuaiChongCmd.class).value(); byte cmd = clazz.getAnnotation(YunKuaiChongCmd.class).value();
try { try {
YunKuaiChongDownlinkCmdExe yunKuaiChongDownlinkCmdExe = (YunKuaiChongDownlinkCmdExe) clazz.getDeclaredConstructor().newInstance(); YunKuaiChongDownlinkCmdExe yunKuaiChongDownlinkCmdExe = (YunKuaiChongDownlinkCmdExe) clazz.getDeclaredConstructor().newInstance();
DOWNLINK_CMD_EXE_MAP.put(cmd, yunKuaiChongDownlinkCmdExe); downlinkCmdExeMap.put(cmd, yunKuaiChongDownlinkCmdExe);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | } catch (InstantiationException |
IllegalAccessException |
InvocationTargetException |
NoSuchMethodException e) { NoSuchMethodException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -184,7 +188,7 @@ public class YunKuaiChongV15ProtocolMessageProcessor extends ProtocolMessageProc
} }
private void exeCmd(YunKuaiChongUplinkMessage message, TcpSession session) { private void exeCmd(YunKuaiChongUplinkMessage message, TcpSession session) {
YunKuaiChongUplinkCmdExe uplinkCmdExe = UPLINK_CMD_EXE_MAP.get((byte) message.getCmd()); YunKuaiChongUplinkCmdExe uplinkCmdExe = uplinkCmdExeMap.get((byte) message.getCmd());
if (uplinkCmdExe == null) { if (uplinkCmdExe == null) {
@@ -197,7 +201,7 @@ public class YunKuaiChongV15ProtocolMessageProcessor extends ProtocolMessageProc
} }
private void exeCmd(YunKuaiChongDwonlinkMessage message, TcpSession session) { private void exeCmd(YunKuaiChongDwonlinkMessage message, TcpSession session) {
YunKuaiChongDownlinkCmdExe downlinkCmdExe = DOWNLINK_CMD_EXE_MAP.get((byte) message.getCmd()); YunKuaiChongDownlinkCmdExe downlinkCmdExe = downlinkCmdExeMap.get((byte) message.getCmd());
if (downlinkCmdExe == null) { if (downlinkCmdExe == null) {

View File

@@ -44,12 +44,12 @@ public class YunKuaiChongV150BmsHandshakeULCmd extends YunKuaiChongUplinkCmdExe
byte[] pileCodeBytes = new byte[7]; byte[] pileCodeBytes = new byte[7];
byteBuf.readBytes(pileCodeBytes); byteBuf.readBytes(pileCodeBytes);
String pileCode = BCDUtil.toString(pileCodeBytes); String pileCode = BCDUtil.toString(pileCodeBytes);
additionalInfo.put("桩编号", tradeNo); additionalInfo.put("桩编号", pileCode);
// 3.抢号 // 3.抢号
byte gunCodeByte = byteBuf.readByte(); byte gunCodeByte = byteBuf.readByte();
String gunCode = BCDUtil.toString(gunCodeByte); String gunCode = BCDUtil.toString(gunCodeByte);
additionalInfo.put("抢号", tradeNo); additionalInfo.put("抢号", gunCode);
// 4.BMS 通信协议版本号 // 4.BMS 通信协议版本号
byte[] bmsConnectVersionBytes = new byte[3]; byte[] bmsConnectVersionBytes = new byte[3];

View File

@@ -7,7 +7,6 @@ package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import sanbing.jcpp.infrastructure.util.jackson.JacksonUtil;
import sanbing.jcpp.proto.gen.ProtocolProto.FlagPriceProto; import sanbing.jcpp.proto.gen.ProtocolProto.FlagPriceProto;
import sanbing.jcpp.proto.gen.ProtocolProto.PeriodProto; import sanbing.jcpp.proto.gen.ProtocolProto.PeriodProto;
import sanbing.jcpp.proto.gen.ProtocolProto.PricingModelProto; import sanbing.jcpp.proto.gen.ProtocolProto.PricingModelProto;
@@ -16,7 +15,6 @@ import sanbing.jcpp.protocol.ProtocolContext;
import sanbing.jcpp.protocol.listener.tcp.TcpSession; import sanbing.jcpp.protocol.listener.tcp.TcpSession;
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDownlinkCmdExe; import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDownlinkCmdExe;
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDwonlinkMessage; import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDwonlinkMessage;
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongUplinkMessage;
import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd; import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -46,8 +44,6 @@ public class YunKuaiChongV150QueryPricingModelAckDLCmd extends YunKuaiChongDownl
QueryPricingResponse queryPricingResponse = yunKuaiChongDwonlinkMessage.getMsg().getQueryPricingResponse(); QueryPricingResponse queryPricingResponse = yunKuaiChongDwonlinkMessage.getMsg().getQueryPricingResponse();
YunKuaiChongUplinkMessage requestData = JacksonUtil.fromBytes(yunKuaiChongDwonlinkMessage.getMsg().getRequestData().toByteArray(), YunKuaiChongUplinkMessage.class);
long pricingId = queryPricingResponse.getPricingId(); long pricingId = queryPricingResponse.getPricingId();
String pileCode = queryPricingResponse.getPileCode(); String pileCode = queryPricingResponse.getPileCode();
PricingModelProto pricingModel = queryPricingResponse.getPricingModel(); PricingModelProto pricingModel = queryPricingResponse.getPricingModel();