mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(agent): remove legacy ConfigLoader and related factory; refactor agent launch flow
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
package work.slhaf.partner;
|
||||
|
||||
import work.slhaf.partner.common.config.PartnerAgentConfigLoader;
|
||||
import work.slhaf.partner.framework.agent.Agent;
|
||||
import work.slhaf.partner.runtime.exception.PartnerExceptionCallback;
|
||||
import work.slhaf.partner.runtime.interaction.WebSocketGateway;
|
||||
import work.slhaf.partner.runtime.interaction.WebSocketGatewayRegistration;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Agent.newAgent(Main.class)
|
||||
.setAgentConfigManager(PartnerAgentConfigLoader.class)
|
||||
.setGateway(WebSocketGateway.class)
|
||||
.setAgentExceptionCallback(PartnerExceptionCallback.class)
|
||||
.addGatewayRegistration(WebSocketGatewayRegistration.INSTANCE)
|
||||
.launch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package work.slhaf.partner.common.config;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.common.exception.ConfigLoadFailedException;
|
||||
import work.slhaf.partner.framework.agent.config.FileAgentConfigLoader;
|
||||
import work.slhaf.partner.framework.agent.factory.config.exception.ConfigNotExistException;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public final class PartnerAgentConfigLoader extends FileAgentConfigLoader {
|
||||
|
||||
private static final String COMMON_CONFIG_FILE = CONFIG_DIR + "common_config.json";
|
||||
|
||||
private Config config;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
loadWebSocketConfig();
|
||||
super.load();
|
||||
}
|
||||
|
||||
private void loadWebSocketConfig() {
|
||||
File file = new File(COMMON_CONFIG_FILE);
|
||||
if (!file.exists()) {
|
||||
throw new ConfigNotExistException("Partner Config Not Exist: " + COMMON_CONFIG_FILE);
|
||||
}
|
||||
config = JSONUtil.readJSONObject(file, StandardCharsets.UTF_8).toBean(Config.class);
|
||||
if (config == null || config.getAgentId() == null) {
|
||||
throw new ConfigLoadFailedException("Partner Config Load Failed: " + COMMON_CONFIG_FILE);
|
||||
}
|
||||
int port = config.getWebSocketConfig().getPort();
|
||||
if (port <= 0 || port > 65535) {
|
||||
throw new ConfigLoadFailedException("Invalid Websocket port: " + port);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user