refactor: optimize Chain events name

This commit is contained in:
Michael Yang 2024-11-20 10:23:28 +08:00
parent a1be752d92
commit ca6385776e
5 changed files with 22 additions and 11 deletions

View File

@ -139,7 +139,7 @@ public class Chain extends ChainNode {
this.status = status; this.status = status;
if (before != 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 { } finally {
onNodeExecuteEnd(nodeContext); onNodeExecuteEnd(nodeContext);
ChainContext.clearNode(); ChainContext.clearNode();
notifyEvent(new OnNodeFinishedEvent(currentNode, executeResult)); notifyEvent(new OnNodeEndEvent(currentNode, executeResult));
} }
if (executeResult != null && !executeResult.isEmpty()) { if (executeResult != null && !executeResult.isEmpty()) {
@ -371,7 +371,7 @@ public class Chain extends ChainNode {
} }
try { try {
ChainContext.setChain(this); ChainContext.setChain(this);
notifyEvent(new OnStartEvent()); notifyEvent(new OnChainStartEvent());
try { try {
setStatus(ChainStatus.RUNNING); setStatus(ChainStatus.RUNNING);
runnable.run(); runnable.run();
@ -386,7 +386,7 @@ public class Chain extends ChainNode {
} }
} finally { } finally {
ChainContext.clearChain(); ChainContext.clearChain();
notifyEvent(new OnFinishedEvent()); notifyEvent(new OnChainEndEvent());
} }
} }

View File

@ -17,6 +17,6 @@ package com.agentsflex.core.chain.event;
import com.agentsflex.core.chain.ChainEvent; import com.agentsflex.core.chain.ChainEvent;
public class OnFinishedEvent implements ChainEvent { public class OnChainEndEvent implements ChainEvent {
} }

View File

@ -17,6 +17,6 @@ package com.agentsflex.core.chain.event;
import com.agentsflex.core.chain.ChainEvent; import com.agentsflex.core.chain.ChainEvent;
public class OnStartEvent implements ChainEvent { public class OnChainStartEvent implements ChainEvent {
} }

View File

@ -20,13 +20,13 @@ import com.agentsflex.core.chain.ChainNode;
import java.util.Map; import java.util.Map;
public class OnNodeFinishedEvent implements ChainEvent { public class OnNodeEndEvent implements ChainEvent {
private ChainNode node; private ChainNode node;
private Map<String, Object> result; private Map<String, Object> result;
public OnNodeFinishedEvent(ChainNode node, Map<String, Object> result) { public OnNodeEndEvent(ChainNode node, Map<String, Object> result) {
this.node = node; this.node = node;
this.result = result; this.result = result;
} }
@ -49,7 +49,7 @@ public class OnNodeFinishedEvent implements ChainEvent {
@Override @Override
public String toString() { public String toString() {
return "OnNodeFinishedEvent{" + return "OnNodeEndEvent{" +
"node=" + node + "node=" + node +
", result=" + result + ", result=" + result +
'}'; '}';

View File

@ -15,19 +15,29 @@
*/ */
package com.agentsflex.core.chain.event; package com.agentsflex.core.chain.event;
import com.agentsflex.core.chain.Chain;
import com.agentsflex.core.chain.ChainEvent; import com.agentsflex.core.chain.ChainEvent;
import com.agentsflex.core.chain.ChainStatus; import com.agentsflex.core.chain.ChainStatus;
public class OnStatusChangeEvent implements ChainEvent { public class OnStatusChangeEvent implements ChainEvent {
private Chain chain;
private ChainStatus status; private ChainStatus status;
private ChainStatus before; private ChainStatus before;
public OnStatusChangeEvent(ChainStatus status, ChainStatus before) { public OnStatusChangeEvent(Chain chain,ChainStatus status, ChainStatus before) {
this.status = status; this.status = status;
this.before = before; this.before = before;
} }
public Chain getChain() {
return chain;
}
public void setChain(Chain chain) {
this.chain = chain;
}
public ChainStatus getStatus() { public ChainStatus getStatus() {
return status; return status;
} }
@ -47,7 +57,8 @@ public class OnStatusChangeEvent implements ChainEvent {
@Override @Override
public String toString() { public String toString() {
return "OnStatusChangeEvent{" + return "OnStatusChangeEvent{" +
"status=" + status + "chain=" + chain +
", status=" + status +
", before=" + before + ", before=" + before +
'}'; '}';
} }