Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
iohao committed May 11, 2024
2 parents a32b6e3 + 85c6eeb commit fb8ec51
Show file tree
Hide file tree
Showing 70 changed files with 1,162 additions and 475 deletions.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/ask-question.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ about: 对框架使用过程中遇到的问题、不清楚或模糊的地方;




### 复现步骤

描述复现步骤,并提供复现 demo




### 版本

- ioGame version:
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ioGame 是轻量级的网络编程框架,**不依赖任何第三方**中间件
<dependency>
<groupId>com.iohao.game</groupId>
<artifactId>run-one-netty</artifactId>
<version>21.6</version>
<version>21.7</version>
</dependency>
```

Expand Down
19 changes: 13 additions & 6 deletions common/common-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ioGame</artifactId>
<groupId>com.iohao.game</groupId>
<version>21.6</version>
<version>21.7</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -55,7 +55,6 @@
<scope>provided</scope>
</dependency>


<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
Expand All @@ -71,14 +70,22 @@
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.github.javafaker/javafaker -->
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish/jakarta.el -->
<!-- EL实现。在 Java SE 环境中,您必须将实现作为依赖项添加到 POM 文件中 -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<version>${jakarta.el.version}</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class IoGameVersion {
public static String a;

static {
String internalVersion = "<version>21.6</version>";
String internalVersion = "<version>21.7</version>";

VERSION = internalVersion
.replace("<version>", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.ParameterizedType;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

/**
* ActionCommand 命令对象,也称为 action。
Expand Down Expand Up @@ -123,6 +125,10 @@ private ActionCommand(Builder builder) {
this.deliveryContainer = builder.deliveryContainer;
}

public Stream<ParamInfo> streamParamInfo() {
return this.methodHasParam ? Arrays.stream(this.paramInfos) : Stream.empty();
}

/**
* {@link ActionCommand} 命令的构建器
* <p>
Expand Down Expand Up @@ -248,16 +254,11 @@ public static final class ParamInfo implements MethodParamResultInfo {
* </pre>
*/
final Class<?> actualClazz;
/**
* 是否扩展属性
* <pre>
* true 表示是扩展属性
* </pre>
*/
final boolean extension;
final boolean customMethodParser;
/** JSR380 验证组 */
final Class<?>[] validatorGroups;
/** true 表示参数类型是 {@link FlowContext} */
final boolean flowContext;
/** true : 开启 JSR380 验证规范 */
boolean validator;

Expand Down Expand Up @@ -293,9 +294,18 @@ public static final class ParamInfo implements MethodParamResultInfo {
var validatedAnn = this.parameter.getAnnotation(ValidatedGroup.class);
this.validatorGroups = Objects.isNull(validatedAnn) ? EMPTY_GROUPS : validatedAnn.value();

this.extension = FlowContext.class.isAssignableFrom(paramClazz);
this.flowContext = FlowContext.class.isAssignableFrom(actualTypeArgumentClazz);
}

/**
* 是否业务参数
*
* @return true 业务参数
* @since 21.7
*/
public boolean isBizData() {
return !this.flowContext;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@
import com.esotericsoftware.reflectasm.MethodAccess;
import com.iohao.game.action.skeleton.annotation.ActionController;
import com.iohao.game.action.skeleton.annotation.ActionMethod;
import com.iohao.game.action.skeleton.core.action.parser.ProtobufCheckActionParserListener;
import com.iohao.game.action.skeleton.core.codec.ProtoDataCodec;
import com.iohao.game.action.skeleton.core.doc.ActionCommandDoc;
import com.iohao.game.action.skeleton.core.doc.ActionDoc;
import com.iohao.game.action.skeleton.core.doc.ActionDocs;
import com.iohao.game.action.skeleton.core.action.parser.ProtobufActionParserListener;
import com.iohao.game.action.skeleton.core.action.parser.ActionParserListener;
import com.iohao.game.action.skeleton.core.action.parser.ActionParserContext;
import com.iohao.game.common.kit.StrKit;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Stream;

/**
Expand All @@ -46,16 +54,21 @@
* @author 渔民小镇
* @date 2021-12-12
*/
@Setter
@Accessors(chain = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
final class ActionCommandParser {
/** 命令域 管理器 */
@Getter
final ActionCommandRegions actionCommandRegions = new ActionCommandRegions();

final BarSkeletonSetting setting;
final ActionParserListeners actionParserListeners;
BarSkeleton barSkeleton;

ActionCommandParser(BarSkeletonSetting setting) {
this.setting = setting;
ActionCommandParser(BarSkeletonBuilder builder) {
this.setting = builder.getSetting();
this.actionParserListeners = builder.actionParserListeners;
}

/**
Expand All @@ -69,7 +82,6 @@ final class ActionCommandParser {
* @param controllerList action 类的 class 列表
*/
ActionCommandParser buildAction(List<Class<?>> controllerList) {

var doc = new ActionCommandDocParser(this, controllerList, setting.parseDoc);

// action 类的 stream
Expand All @@ -82,6 +94,7 @@ ActionCommandParser buildAction(List<Class<?>> controllerList) {
int cmd = controllerClazz.getAnnotation(ActionController.class).value();
// 子路由 map
var actionCommandRegion = this.actionCommandRegions.getActionCommandRegion(cmd);
actionCommandRegion.setActionControllerClazz(controllerClazz);

// true 表示交付给容器来管理 如 spring 等
boolean deliveryContainer = this.deliveryContainer(controllerClazz);
Expand Down Expand Up @@ -133,14 +146,16 @@ ActionCommandParser buildAction(List<Class<?>> controllerList) {
// 子路由映射
actionCommandRegion.add(command);

// 文档相关
ActionDoc actionDoc = ActionDocs.ofActionDoc(cmd, controllerClazz);
actionDoc.addActionCommand(command);
});

});

// 内部将所有的 action 转换为 action 二维数组
actionCommandRegions.initActionCommandArray(setting);
// action 构建时的监听
executeActionListeners();

return this;
}
Expand Down Expand Up @@ -223,12 +238,11 @@ private void paramInfo(Method method, ActionCommand.Builder builder) {
* 1 没开启 JSR380 验证, 不做处理
* 2 过滤不需要验证的参数
*/
if (!this.setting.validator || paramInfo.isExtension()) {
if (!this.setting.validator || paramInfo.isFlowContext()) {
continue;
}

paramInfo.validator = ValidatorKit.isValidator(parameter.getType());

}
}

Expand Down Expand Up @@ -258,4 +272,50 @@ private Object ofActionInstance(Class<?> controllerClazz) {

return actionInstance;
}

private void executeActionListeners() {
actionCommandRegions.regionMap.forEach((cmd, actionCommandRegion) -> {
// action command, actionMethod
actionCommandRegion.getSubActionCommandMap().forEach((subCmd, command) -> {
// action 构建时的上下文
ActionParserContext context = new ActionParserContext()
.setBarSkeleton(barSkeleton)
.setActionCommand(command);

// action 构建时的监听 - actionCommand
this.actionParserListeners.onActionCommand(context);
});
});

this.actionParserListeners.onAfter(barSkeleton);
}
}

@FieldDefaults(level = AccessLevel.PRIVATE)
final class ActionParserListeners {
final List<ActionParserListener> listeners = new CopyOnWriteArrayList<>();

void addActionParserListener(ActionParserListener listener) {
this.listeners.add(listener);
}

void onActionCommand(ActionParserContext context) {
this.listeners.forEach(listener -> listener.onActionCommand(context));
}

void onAfter(BarSkeleton barSkeleton) {
this.listeners.forEach(listener -> listener.onAfter(barSkeleton));
}

public boolean isEmpty() {
return this.listeners.isEmpty();
}

public ActionParserListeners() {
// 监听器 - 预先创建协议代理类
if (DataCodecKit.getDataCodec() instanceof ProtoDataCodec) {
this.addActionParserListener(ProtobufActionParserListener.me());
this.addActionParserListener(ProtobufCheckActionParserListener.me());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.iohao.game.action.skeleton.core.exception.MsgExceptionInfo;
import com.iohao.game.action.skeleton.core.flow.*;
import com.iohao.game.action.skeleton.core.flow.internal.*;
import com.iohao.game.action.skeleton.core.action.parser.ActionParserListener;
import com.iohao.game.action.skeleton.core.runner.Runner;
import com.iohao.game.action.skeleton.core.runner.Runners;
import com.iohao.game.common.kit.concurrent.executor.*;
Expand Down Expand Up @@ -66,6 +67,8 @@ public final class BarSkeletonBuilder {
final ActionSendDocs actionSendDocs = new ActionSendDocs();
/** 错误码相关的文档 */
final ErrorCodeDocs errorCodeDocs = new ErrorCodeDocs();
/** action 构建时的钩子方法 */
ActionParserListeners actionParserListeners = new ActionParserListeners();
/** action工厂 */
ActionFactoryBean<Object> actionFactoryBean = new DefaultActionFactoryBean<>();
/** action 执行完后,最后需要做的事。 一般用于将数据发送到 Broker(游戏网关) */
Expand Down Expand Up @@ -145,6 +148,8 @@ public BarSkeleton build() {

this.runners.setBarSkeleton(barSkeleton);

this.actionParserListeners = null;

return barSkeleton;
}

Expand Down Expand Up @@ -204,14 +209,20 @@ public BarSkeletonBuilder addRunner(Runner runner) {
return this;
}

public BarSkeletonBuilder addActionParserListener(ActionParserListener listener) {
this.actionParserListeners.addActionParserListener(listener);
return this;
}

private void extractedInOut(BarSkeleton barSkeleton) {
var inOutManager = new InOutManager(this.setting, this.inOutList);
barSkeleton.setInOutManager(inOutManager);
}

private void extractedActionCommand(BarSkeleton barSkeleton) {
// action 命令对象解析器
var actionCommandParser = new ActionCommandParser(setting)
var actionCommandParser = new ActionCommandParser(this)
.setBarSkeleton(barSkeleton)
// 根据 action 类列表,来构建 ActionCommand
.buildAction(this.actionControllerClazzList);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* ioGame
* Copyright (C) 2021 - present 渔民小镇 ([email protected][email protected]) . All Rights Reserved.
* # iohao.com . 渔民小镇
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.iohao.game.action.skeleton.core.action.parser;

import com.iohao.game.action.skeleton.core.ActionCommand;
import com.iohao.game.action.skeleton.core.BarSkeleton;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;

/**
* action 构建时的上下文
*
* @author 渔民小镇
* @date 2024-04-30
* @since 21.7
*/
@Getter
@Setter
@Accessors(chain = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
public final class ActionParserContext {
/** 业务框架 */
BarSkeleton barSkeleton;
/** action method */
ActionCommand actionCommand;
}
Loading

0 comments on commit fb8ec51

Please sign in to comment.