mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
feat(agent): support add custom configurable object in Agent launch flow
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package work.slhaf.partner;
|
package work.slhaf.partner;
|
||||||
|
|
||||||
|
import work.slhaf.partner.common.vector.VectorClientRegistry;
|
||||||
import work.slhaf.partner.framework.agent.Agent;
|
import work.slhaf.partner.framework.agent.Agent;
|
||||||
import work.slhaf.partner.runtime.gateway.WebSocketGatewayRegistration;
|
import work.slhaf.partner.runtime.gateway.WebSocketGatewayRegistration;
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Agent.newAgent(Main.class)
|
Agent.newAgent(Main.class)
|
||||||
.addGatewayRegistration(WebSocketGatewayRegistration.INSTANCE)
|
.addGatewayRegistration(WebSocketGatewayRegistration.INSTANCE)
|
||||||
|
.addConfigurable(new VectorClientRegistry())
|
||||||
.launch();
|
.launch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package work.slhaf.partner.framework.agent;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import work.slhaf.partner.framework.agent.config.ConfigCenter;
|
import work.slhaf.partner.framework.agent.config.ConfigCenter;
|
||||||
|
import work.slhaf.partner.framework.agent.config.Configurable;
|
||||||
import work.slhaf.partner.framework.agent.exception.AgentStartupException;
|
import work.slhaf.partner.framework.agent.exception.AgentStartupException;
|
||||||
import work.slhaf.partner.framework.agent.exception.ExceptionReporter;
|
import work.slhaf.partner.framework.agent.exception.ExceptionReporter;
|
||||||
import work.slhaf.partner.framework.agent.exception.ExceptionReporterHandler;
|
import work.slhaf.partner.framework.agent.exception.ExceptionReporterHandler;
|
||||||
import work.slhaf.partner.framework.agent.factory.AgentRegisterFactory;
|
import work.slhaf.partner.framework.agent.factory.AgentRegisterFactory;
|
||||||
import work.slhaf.partner.framework.agent.factory.component.annotation.AgentComponent;
|
|
||||||
import work.slhaf.partner.framework.agent.factory.context.AgentContext;
|
import work.slhaf.partner.framework.agent.factory.context.AgentContext;
|
||||||
import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistration;
|
import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistration;
|
||||||
import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistry;
|
import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistry;
|
||||||
@@ -34,6 +34,7 @@ public final class Agent {
|
|||||||
private final Class<?> applicationClass;
|
private final Class<?> applicationClass;
|
||||||
private final Set<AgentGatewayRegistration> gatewayRegistrations = new LinkedHashSet<>();
|
private final Set<AgentGatewayRegistration> gatewayRegistrations = new LinkedHashSet<>();
|
||||||
private final Set<ExceptionReporter> exceptionReporters = new LinkedHashSet<>();
|
private final Set<ExceptionReporter> exceptionReporters = new LinkedHashSet<>();
|
||||||
|
private final Set<Configurable> configurables = new LinkedHashSet<>();
|
||||||
private final Set<LifecycleHook> preShutdownHooks = new LinkedHashSet<>();
|
private final Set<LifecycleHook> preShutdownHooks = new LinkedHashSet<>();
|
||||||
private final Set<LifecycleHook> postShutdownHooks = new LinkedHashSet<>();
|
private final Set<LifecycleHook> postShutdownHooks = new LinkedHashSet<>();
|
||||||
|
|
||||||
@@ -46,6 +47,11 @@ public final class Agent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AgentApp addConfigurable(Configurable configurable) {
|
||||||
|
this.configurables.add(configurable);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public AgentApp addExceptionReporter(ExceptionReporter... exceptionReporters) {
|
public AgentApp addExceptionReporter(ExceptionReporter... exceptionReporters) {
|
||||||
this.exceptionReporters.addAll(Set.of(exceptionReporters));
|
this.exceptionReporters.addAll(Set.of(exceptionReporters));
|
||||||
return this;
|
return this;
|
||||||
@@ -73,17 +79,17 @@ public final class Agent {
|
|||||||
try {
|
try {
|
||||||
// Keep startup order explicit so registries are ready before component scanning.
|
// Keep startup order explicit so registries are ready before component scanning.
|
||||||
for (ExceptionReporter exceptionReporter : exceptionReporters) {
|
for (ExceptionReporter exceptionReporter : exceptionReporters) {
|
||||||
// AgentComponent will be initialized by factory
|
|
||||||
if (exceptionReporter.getClass().isAnnotationPresent(AgentComponent.class)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
exceptionReporter.register();
|
exceptionReporter.register();
|
||||||
}
|
}
|
||||||
// Load class
|
// Load class
|
||||||
StateCenter.INSTANCE.toString();
|
StateCenter.INSTANCE.toString();
|
||||||
|
|
||||||
// Register into config center
|
// Register into config center
|
||||||
ModelRuntimeRegistry.INSTANCE.register();
|
ModelRuntimeRegistry.INSTANCE.register();
|
||||||
AgentGatewayRegistry.INSTANCE.register();
|
AgentGatewayRegistry.INSTANCE.register();
|
||||||
|
for (Configurable configurable : configurables) {
|
||||||
|
configurable.register();
|
||||||
|
}
|
||||||
|
|
||||||
for (AgentGatewayRegistration registration : gatewayRegistrations) {
|
for (AgentGatewayRegistration registration : gatewayRegistrations) {
|
||||||
registration.register();
|
registration.register();
|
||||||
|
|||||||
Reference in New Issue
Block a user