From ca6385776e33a87ab2b89219d6208c784391a221 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 20 Nov 2024 10:23:28 +0800 Subject: [PATCH] refactor: optimize Chain events name --- .../java/com/agentsflex/core/chain/Chain.java | 8 ++++---- ...{OnFinishedEvent.java => OnChainEndEvent.java} | 2 +- .../{OnStartEvent.java => OnChainStartEvent.java} | 2 +- ...NodeFinishedEvent.java => OnNodeEndEvent.java} | 6 +++--- .../core/chain/event/OnStatusChangeEvent.java | 15 +++++++++++++-- 5 files changed, 22 insertions(+), 11 deletions(-) rename agents-flex-core/src/main/java/com/agentsflex/core/chain/event/{OnFinishedEvent.java => OnChainEndEvent.java} (93%) rename agents-flex-core/src/main/java/com/agentsflex/core/chain/event/{OnStartEvent.java => OnChainStartEvent.java} (93%) rename agents-flex-core/src/main/java/com/agentsflex/core/chain/event/{OnNodeFinishedEvent.java => OnNodeEndEvent.java} (88%) diff --git a/agents-flex-core/src/main/java/com/agentsflex/core/chain/Chain.java b/agents-flex-core/src/main/java/com/agentsflex/core/chain/Chain.java index 851993f..d43d1d5 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/core/chain/Chain.java +++ b/agents-flex-core/src/main/java/com/agentsflex/core/chain/Chain.java @@ -139,7 +139,7 @@ public class Chain extends ChainNode { this.status = status; if (before != status) { - notifyEvent(new OnStatusChangeEvent(this.status, before)); + notifyEvent(new OnStatusChangeEvent(this, this.status, before)); } } @@ -260,7 +260,7 @@ public class Chain extends ChainNode { } finally { onNodeExecuteEnd(nodeContext); ChainContext.clearNode(); - notifyEvent(new OnNodeFinishedEvent(currentNode, executeResult)); + notifyEvent(new OnNodeEndEvent(currentNode, executeResult)); } if (executeResult != null && !executeResult.isEmpty()) { @@ -371,7 +371,7 @@ public class Chain extends ChainNode { } try { ChainContext.setChain(this); - notifyEvent(new OnStartEvent()); + notifyEvent(new OnChainStartEvent()); try { setStatus(ChainStatus.RUNNING); runnable.run(); @@ -386,7 +386,7 @@ public class Chain extends ChainNode { } } finally { ChainContext.clearChain(); - notifyEvent(new OnFinishedEvent()); + notifyEvent(new OnChainEndEvent()); } } diff --git a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnFinishedEvent.java b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnChainEndEvent.java similarity index 93% rename from agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnFinishedEvent.java rename to agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnChainEndEvent.java index b5fa933..5fc9e28 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnFinishedEvent.java +++ b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnChainEndEvent.java @@ -17,6 +17,6 @@ package com.agentsflex.core.chain.event; import com.agentsflex.core.chain.ChainEvent; -public class OnFinishedEvent implements ChainEvent { +public class OnChainEndEvent implements ChainEvent { } diff --git a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnStartEvent.java b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnChainStartEvent.java similarity index 93% rename from agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnStartEvent.java rename to agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnChainStartEvent.java index f0dd4c6..28db999 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnStartEvent.java +++ b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnChainStartEvent.java @@ -17,6 +17,6 @@ package com.agentsflex.core.chain.event; import com.agentsflex.core.chain.ChainEvent; -public class OnStartEvent implements ChainEvent { +public class OnChainStartEvent implements ChainEvent { } diff --git a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnNodeFinishedEvent.java b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnNodeEndEvent.java similarity index 88% rename from agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnNodeFinishedEvent.java rename to agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnNodeEndEvent.java index 4244982..9481ee6 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnNodeFinishedEvent.java +++ b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnNodeEndEvent.java @@ -20,13 +20,13 @@ import com.agentsflex.core.chain.ChainNode; import java.util.Map; -public class OnNodeFinishedEvent implements ChainEvent { +public class OnNodeEndEvent implements ChainEvent { private ChainNode node; private Map result; - public OnNodeFinishedEvent(ChainNode node, Map result) { + public OnNodeEndEvent(ChainNode node, Map result) { this.node = node; this.result = result; } @@ -49,7 +49,7 @@ public class OnNodeFinishedEvent implements ChainEvent { @Override public String toString() { - return "OnNodeFinishedEvent{" + + return "OnNodeEndEvent{" + "node=" + node + ", result=" + result + '}'; diff --git a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnStatusChangeEvent.java b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnStatusChangeEvent.java index a5f4d62..8a19124 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnStatusChangeEvent.java +++ b/agents-flex-core/src/main/java/com/agentsflex/core/chain/event/OnStatusChangeEvent.java @@ -15,19 +15,29 @@ */ package com.agentsflex.core.chain.event; +import com.agentsflex.core.chain.Chain; import com.agentsflex.core.chain.ChainEvent; import com.agentsflex.core.chain.ChainStatus; public class OnStatusChangeEvent implements ChainEvent { + private Chain chain; private ChainStatus status; private ChainStatus before; - public OnStatusChangeEvent(ChainStatus status, ChainStatus before) { + public OnStatusChangeEvent(Chain chain,ChainStatus status, ChainStatus before) { this.status = status; this.before = before; } + public Chain getChain() { + return chain; + } + + public void setChain(Chain chain) { + this.chain = chain; + } + public ChainStatus getStatus() { return status; } @@ -47,7 +57,8 @@ public class OnStatusChangeEvent implements ChainEvent { @Override public String toString() { return "OnStatusChangeEvent{" + - "status=" + status + + "chain=" + chain + + ", status=" + status + ", before=" + before + '}'; }