mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(framework): rename @AgentModule to @AgentRunningModule
This commit is contained in:
@@ -7,7 +7,7 @@ import work.slhaf.partner.api.agent.factory.capability.annotation.*;
|
||||
import work.slhaf.partner.api.agent.factory.capability.exception.*;
|
||||
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.agent.factory.context.CapabilityFactoryContext;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentRunningModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
import work.slhaf.partner.api.agent.util.AgentUtil;
|
||||
|
||||
@@ -42,7 +42,7 @@ import static work.slhaf.partner.api.agent.util.AgentUtil.methodSignature;
|
||||
* </li>
|
||||
* <li>
|
||||
* <p>{@link CapabilityCheckFactory#checkInjectCapability()}</p>
|
||||
* 检查 {@link InjectCapability} 注解是否只用在 {@link CapabilityHolder} 所标识类的字段上。{@link AgentModule} 与 {@link AgentSubModule} 已经被 {@link CapabilityHolder} 标注
|
||||
* 检查 {@link InjectCapability} 注解是否只用在 {@link CapabilityHolder} 所标识类的字段上。{@link AgentRunningModule} 与 {@link AgentSubModule} 已经被 {@link CapabilityHolder} 标注
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
|
||||
@@ -9,7 +9,7 @@ import work.slhaf.partner.api.agent.factory.capability.exception.CapabilityProxy
|
||||
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.agent.factory.context.CapabilityFactoryContext;
|
||||
import work.slhaf.partner.api.agent.factory.module.ModuleInitHookExecuteFactory;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentRunningModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -27,7 +27,7 @@ import static work.slhaf.partner.api.agent.util.AgentUtil.methodSignature;
|
||||
*
|
||||
* <p>实现方式:</p>
|
||||
* <ol>
|
||||
* <li>通过动态代理,为 {@link AgentModule} 与 {@link AgentSubModule} 中待注入的
|
||||
* <li>通过动态代理,为 {@link AgentRunningModule} 与 {@link AgentSubModule} 中待注入的
|
||||
* <b>能力接口</b> 类型(即 {@link Capability} 标注的接口类)生成代理对象。
|
||||
* </li>
|
||||
* <li>在代理对象内部,根据调用方法的签名确定路由,将调用转发至对应的具体函数。
|
||||
|
||||
@@ -9,7 +9,7 @@ import work.slhaf.partner.api.agent.factory.capability.exception.CapabilityFacto
|
||||
import work.slhaf.partner.api.agent.factory.capability.exception.DuplicateMethodException;
|
||||
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.agent.factory.context.CapabilityFactoryContext;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentRunningModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -52,7 +52,7 @@ import static work.slhaf.partner.api.agent.util.AgentUtil.methodSignature;
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>
|
||||
* 函数路由表生成完毕、core实例创建完毕之后,将交由下一工厂完成能力(Capability)注入操作,注入到 {@link AgentModule} 与 {@link AgentSubModule} 对应的实例中
|
||||
* 函数路由表生成完毕、core实例创建完毕之后,将交由下一工厂完成能力(Capability)注入操作,注入到 {@link AgentRunningModule} 与 {@link AgentSubModule} 对应的实例中
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
|
||||
@@ -8,7 +8,7 @@ import work.slhaf.partner.api.agent.factory.module.abstracts.AbstractAgentRunnin
|
||||
import work.slhaf.partner.api.agent.factory.module.abstracts.AbstractAgentSubModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AfterExecute;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentRunningModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.BeforeExecute;
|
||||
import work.slhaf.partner.api.agent.factory.module.exception.ModuleCheckException;
|
||||
@@ -31,11 +31,11 @@ import static work.slhaf.partner.api.agent.util.AgentUtil.getMethodAnnotationTyp
|
||||
* <ol>
|
||||
* <li>
|
||||
* <p>{@link ModuleCheckFactory#annotationAbstractCheck(Set, Class)}</p>
|
||||
* 所有添加了 {@link AgentModule} 注解的类都将作为Agent的执行模块,为规范模块入口,都必须实现抽象类: {@link AbstractAgentRunningModule}; {@link AgentSubModule} 注解所在类则必须实现 {@link AbstractAgentSubModule}
|
||||
* 所有添加了 {@link AgentRunningModule} 注解的类都将作为Agent的执行模块,为规范模块入口,都必须实现抽象类: {@link AbstractAgentRunningModule}; {@link AgentSubModule} 注解所在类则必须实现 {@link AbstractAgentSubModule}
|
||||
* </li>
|
||||
* <li>
|
||||
* <p>{@link ModuleCheckFactory#moduleConstructorsCheck(Set)}</p>
|
||||
* 所有 {@link AgentModule} 与 {@link AgentSubModule} 注解所在类都必须具备空参构造方法,初始化逻辑可放在 @Init 注解所处方法中,将在 Capability 与 subModules 注入后才会执行
|
||||
* 所有 {@link AgentRunningModule} 与 {@link AgentSubModule} 注解所在类都必须具备空参构造方法,初始化逻辑可放在 @Init 注解所处方法中,将在 Capability 与 subModules 注入后才会执行
|
||||
* </li>
|
||||
* <li>
|
||||
* <p>{@link ModuleCheckFactory#activateModelImplCheck()}</p>
|
||||
@@ -84,7 +84,7 @@ public class ModuleCheckFactory extends AgentBaseFactory {
|
||||
}
|
||||
|
||||
private AnnotatedModules getAnnotatedModules() {
|
||||
Set<Class<?>> moduleTypes = reflections.getTypesAnnotatedWith(AgentModule.class)
|
||||
Set<Class<?>> moduleTypes = reflections.getTypesAnnotatedWith(AgentRunningModule.class)
|
||||
.stream()
|
||||
.filter(ClassUtil::isNormalClass)
|
||||
.collect(Collectors.toSet());
|
||||
@@ -133,7 +133,7 @@ public class ModuleCheckFactory extends AgentBaseFactory {
|
||||
}
|
||||
|
||||
private void initHookLocationCheck() {
|
||||
Set<Class<?>> types = getMethodAnnotationTypeSet(AgentModule.class, reflections);
|
||||
Set<Class<?>> types = getMethodAnnotationTypeSet(AgentRunningModule.class, reflections);
|
||||
checkLocation(types);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
||||
import work.slhaf.partner.api.agent.factory.context.ModuleFactoryContext;
|
||||
import work.slhaf.partner.api.agent.factory.module.abstracts.AbstractAgentRunningModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.abstracts.AbstractAgentSubModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentRunningModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.CoreModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.pojo.MetaModule;
|
||||
@@ -21,13 +21,13 @@ import java.util.Set;
|
||||
* <h2>Agent启动流程 2</h2>
|
||||
*
|
||||
* <p>
|
||||
* 负责收集 {@link AgentModule} 与 {@link AgentSubModule} 注解所在类的信息,供后续工厂完成动态代理、模块与能力注入
|
||||
* 负责收集 {@link AgentRunningModule} 与 {@link AgentSubModule} 注解所在类的信息,供后续工厂完成动态代理、模块与能力注入
|
||||
* <p/>
|
||||
*
|
||||
* <ol>
|
||||
* <li>
|
||||
* <p>{@link ModuleRegisterFactory#setModuleList()}</p>
|
||||
* 扫描 {@link AgentModule} 注解,获取执行模块信息: 类型、模块名称({@link AgentModule#name()}),执行顺序。并按照注解的 {@link AgentModule#order()} 字段进行排序
|
||||
* 扫描 {@link AgentRunningModule} 注解,获取执行模块信息: 类型、模块名称({@link AgentRunningModule#name()}),执行顺序。并按照注解的 {@link AgentRunningModule#order()} 字段进行排序
|
||||
* </li>
|
||||
* <li>
|
||||
* <p>{@link ModuleRegisterFactory#setSubModuleList()}</p>
|
||||
@@ -62,14 +62,14 @@ public class ModuleRegisterFactory extends AgentBaseFactory {
|
||||
|
||||
private static MetaModule getMetaModule(Class<? extends AbstractAgentRunningModule> clazz) {
|
||||
MetaModule metaModule = new MetaModule();
|
||||
AgentModule agentModule;
|
||||
AgentRunningModule agentRunningModule;
|
||||
if (clazz.isAnnotationPresent(CoreModule.class)){
|
||||
agentModule = CoreModule.class.getAnnotation(AgentModule.class);
|
||||
agentRunningModule = CoreModule.class.getAnnotation(AgentRunningModule.class);
|
||||
}else{
|
||||
agentModule = clazz.getAnnotation(AgentModule.class);
|
||||
agentRunningModule = clazz.getAnnotation(AgentRunningModule.class);
|
||||
}
|
||||
metaModule.setName(agentModule.name());
|
||||
metaModule.setOrder(agentModule.order());
|
||||
metaModule.setName(agentRunningModule.name());
|
||||
metaModule.setOrder(agentRunningModule.order());
|
||||
metaModule.setClazz(clazz);
|
||||
return metaModule;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class ModuleRegisterFactory extends AgentBaseFactory {
|
||||
|
||||
private void setModuleList() {
|
||||
//反射扫描获取@AgentModule所在类, 该部分为Agent流程执行模块
|
||||
Set<Class<?>> modules = reflections.getTypesAnnotatedWith(AgentModule.class);
|
||||
Set<Class<?>> modules = reflections.getTypesAnnotatedWith(AgentRunningModule.class);
|
||||
for (Class<?> module : modules) {
|
||||
if (!ClassUtil.isNormalClass(module)) {
|
||||
continue;
|
||||
|
||||
@@ -2,7 +2,7 @@ package work.slhaf.partner.api.agent.factory.module.abstracts;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AfterExecute;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentRunningModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.BeforeExecute;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.CoreModule;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.RunningFlowContext;
|
||||
@@ -25,10 +25,10 @@ public abstract class AbstractAgentRunningModule<C extends RunningFlowContext> e
|
||||
}
|
||||
|
||||
private String getModuleName(){
|
||||
if (this.getClass().isAnnotationPresent(AgentModule.class)) {
|
||||
return this.getClass().getAnnotation(AgentModule.class).name();
|
||||
if (this.getClass().isAnnotationPresent(AgentRunningModule.class)) {
|
||||
return this.getClass().getAnnotation(AgentRunningModule.class).name();
|
||||
} else if (this.getClass().isAnnotationPresent(CoreModule.class)) {
|
||||
return CoreModule.class.getAnnotation(AgentModule.class).name();
|
||||
return CoreModule.class.getAnnotation(AgentRunningModule.class).name();
|
||||
}else {
|
||||
return "Unknown AbstractAgentModule";
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 仅适用于以下类中的方法:
|
||||
* 1. <code>@AgentModule</code>注解所在类
|
||||
* 1. <code>@AgentRunningModule</code>注解所在类
|
||||
* 2. <code>ActivateModel</code>子类
|
||||
* 3. <code>AbstractAgentRunningModule</code>或者<code>AbstractAgentSubModule</code>子类
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@CapabilityHolder
|
||||
@Inherited
|
||||
public @interface AgentModule {
|
||||
public @interface AgentRunningModule {
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
@@ -7,7 +7,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 仅适用于以下类中的方法:
|
||||
* 1. <code>@AgentModule</code>注解所在类
|
||||
* 1. <code>@AgentRunningModule</code>注解所在类
|
||||
* 2. <code>ActivateModel</code>子类
|
||||
* 3. <code>AbstractAgentRunningModule</code>或者<code>AbstractAgentSubModule</code>子类
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@AgentModule(name = "core",order = 5)
|
||||
@AgentRunningModule(name = "core", order = 5)
|
||||
public @interface CoreModule {
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import work.slhaf.partner.api.agent.factory.module.abstracts.AbstractAgentRunnin
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class AbstractAgentModuleProxyTest {
|
||||
public class AbstractAgentRunningModuleProxyTest {
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException {
|
||||
Class<? extends AbstractAgentRunningModule> clazz = new ByteBuddy().subclass(MyAbstractAgentRunningAbstractAgentModule.class)
|
||||
@@ -18,7 +18,7 @@ public class AbstractAgentModuleProxyTest {
|
||||
new MyModuleProxyInterceptor()
|
||||
))
|
||||
.make()
|
||||
.load(AbstractAgentModuleProxyTest.class.getClassLoader())
|
||||
.load(AbstractAgentRunningModuleProxyTest.class.getClassLoader())
|
||||
.getLoaded();
|
||||
clazz.getConstructor().newInstance().execute(null);
|
||||
}
|
||||
Reference in New Issue
Block a user