Skip to content

Commit

Permalink
perf(i18n): 🐳 #376 cmd check tips
Browse files Browse the repository at this point in the history
  • Loading branch information
iohao committed Oct 24, 2024
1 parent 435e516 commit d9dbd52
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.iohao.game.action.skeleton.core;

import com.iohao.game.action.skeleton.i18n.Bundle;
import com.iohao.game.action.skeleton.i18n.MessageKey;
import com.iohao.game.action.skeleton.toy.IoGameBanner;
import com.iohao.game.common.kit.MoreKit;
import lombok.AccessLevel;
Expand Down Expand Up @@ -177,28 +179,32 @@ private ActionCommand[][] convertArray(BarSkeletonSetting barSkeletonSetting) {
private int getMaxCmd(BarSkeletonSetting barSkeletonSetting) {
// 获取最大的路由数字 并且+1
int max = this.regionMap
.keySet()
.stream()
.max(Integer::compareTo)
.orElse(0) + 1;
.keySet()
.stream()
.max(Integer::compareTo)
.orElse(0) + 1;

if (max > barSkeletonSetting.getCmdMaxLen()) {

String info = String.format("cmd 超过最大默认值! 如果有需要, 请手动设置容量! 默认最大容量 %s. 当前容量 %s"
, barSkeletonSetting.getCmdMaxLen(), max
/*
* %s exceeds the maximum default value.
* Please set the capacity manually if necessary.
* Default maximum capacity %d, current capacity %d
*/
var info = Bundle.getMessage(MessageKey.cmdMergeLimit).formatted(
"cmd", barSkeletonSetting.getCmdMaxLen(), max
);

IoGameBanner.me().ofRuntimeException(info);
}

// subCmd
for (ActionCommandRegion actionCommandRegion : this.regionMap.values()) {

int subCmdMax = actionCommandRegion.getMaxSubCmd() + 1;

if (subCmdMax > barSkeletonSetting.getSubCmdMaxLen()) {

String info = String.format("subCmd 超过最大默认值! 如果有需要, 请手动设置容量! 默认最大容量 %s. 当前容量 %s"
, barSkeletonSetting.getSubCmdMaxLen(), subCmdMax
var info = Bundle.getMessage(MessageKey.cmdMergeLimit).formatted(
"subCmd", barSkeletonSetting.getSubCmdMaxLen(), subCmdMax
);

IoGameBanner.me().ofRuntimeException(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import com.iohao.game.action.skeleton.core.action.parser.ActionParserContext;
import com.iohao.game.action.skeleton.core.action.parser.ActionParserListener;
import com.iohao.game.action.skeleton.i18n.Bundle;
import com.iohao.game.action.skeleton.i18n.MessageKey;
import com.iohao.game.action.skeleton.protocol.wrapper.*;
import com.iohao.game.common.kit.ProtoKit;
import lombok.AccessLevel;
Expand Down Expand Up @@ -127,7 +129,7 @@ public void onAfter(BarSkeleton barSkeleton) {
return;
}

log.error("======== 注意,协议类没有添加 ProtobufClass 注解 ========");
log.error(Bundle.getMessage(MessageKey.protobufAnnotationCheck));
for (Class<?> protoClass : protoSet) {
log.error(protoClass.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import lombok.experimental.UtilityClass;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.Objects;
import java.util.ResourceBundle;
Expand All @@ -46,9 +45,4 @@ ResourceBundle getBundle() {
public String getMessage(String key) {
return getBundle().getString(key);
}

String getMessage(String key, Object... args) {
var keyPattern = getBundle().getString(key);
return MessageFormat.format(keyPattern, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ public interface MessageKey {
String timeRangeInOutDayTitle = "timeRangeInOutDayTitle";
String timeRangeInOutHourTitle = "timeRangeInOutHourTitle";
String timeRangeInOutMinuteTitle = "timeRangeInOutMinuteTitle";
/* see ActionCommandRegions.java */
String cmdMergeLimit = "cmdMergeLimit";
/* see ProtobufCheckActionParserListener.java */
String protobufAnnotationCheck = "protobufAnnotationCheck";
}
5 changes: 5 additions & 0 deletions common/common-core/src/main/resources/iohao.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ threadMonitorInOutThreadMonitor=thread[%s], execute[%d], avgTime[%d]ms, remainTa
timeRangeInOutDayTitle=action execution times[%d]
timeRangeInOutHourTitle=%d:00 execute[%s];
timeRangeInOutMinuteTitle=[%d~%d minutes, execute:%d]
# see ActionCommandRegions.java
cmdMergeLimit=%s exceeds the maximum default value. Please set the capacity manually if necessary. Default maximum capacity %d, current capacity %d
# see ProtobufCheckActionParserListener
protobufAnnotationCheck=Note that the protocol class does not have the ProtobufClass annotation added

4 changes: 4 additions & 0 deletions common/common-core/src/main/resources/iohao_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ threadMonitorInOutThreadMonitor=业务线程[%s],共执行了[%d]次业务,
timeRangeInOutDayTitle=action 执行次数 共 [%d] 次
timeRangeInOutHourTitle=%d:00 共 %s 次;
timeRangeInOutMinuteTitle=[%d~%d分钟,%d 次]
# see ActionCommandRegions.java
cmdMergeLimit=%s 超过最大默认值,如有需要请手动设置容量。默认最大容量 %d. 当前容量 %d
# see ProtobufCheckActionParserListener
protobufAnnotationCheck=注意,协议类没有添加 ProtobufClass 注解

0 comments on commit d9dbd52

Please sign in to comment.