refactor: 修改公共触发监听
This commit is contained in:
parent
c7340cea0a
commit
fb01646f23
|
@ -1,19 +1,5 @@
|
||||||
package io.metersphere.sdk.listener;
|
package io.metersphere.sdk.listener;
|
||||||
|
|
||||||
public class Event {
|
public record Event(String module, String message) {
|
||||||
private String message;
|
|
||||||
private String module;
|
|
||||||
|
|
||||||
public Event(String module, String message) {
|
|
||||||
this.module = module;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getModule() {
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,12 @@ package io.metersphere.sdk.listener;
|
||||||
|
|
||||||
public interface EventSource {
|
public interface EventSource {
|
||||||
/**
|
/**
|
||||||
* @param listener
|
* 注册监听
|
||||||
*/
|
*/
|
||||||
void addListener(EventListener<Event> listener);
|
void addListener(EventListener<Event> listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param module
|
* 触发事件
|
||||||
* @param message
|
|
||||||
*/
|
*/
|
||||||
void fireEvent(String module, String message);
|
void fireEvent(String module, String message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,11 @@ public class EventSourceTests {
|
||||||
// 注册所有监听源
|
// 注册所有监听源
|
||||||
LogUtils.info("初始化接口事件源");
|
LogUtils.info("初始化接口事件源");
|
||||||
APIEventSource apiEventSource = CommonBeanFactory.getBean(APIEventSource.class);
|
APIEventSource apiEventSource = CommonBeanFactory.getBean(APIEventSource.class);
|
||||||
|
assert apiEventSource != null;
|
||||||
apiEventSource.addListener(new EventListener<Event>() {
|
apiEventSource.addListener(new EventListener<Event>() {
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(Event event) {
|
public void onEvent(Event event) {
|
||||||
LogUtils.info("ExecEventListener: " + event.getModule() + ":" + event.getMessage());
|
LogUtils.info("ExecEventListener: " + event.module() + ":" + event.message());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 触发事件
|
// 触发事件
|
||||||
|
|
|
@ -10,6 +10,6 @@ public class ExecEventListener implements EventListener<Event> {
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(Event event) {
|
public void onEvent(Event event) {
|
||||||
// todo: 测试计划事件处理逻辑
|
// todo: 测试计划事件处理逻辑
|
||||||
LogUtils.info("ExecEventListener: " + event.getModule() + ":" + event.getMessage());
|
LogUtils.info("ExecEventListener: " + event.module() + ":" + event.message());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue