-
Notifications
You must be signed in to change notification settings - Fork 641
Description
Search before asking
- I had searched in the issues and found no similar issues.
Enhancement Request
I have seen multiple properties of EventMeshServer, such as Acl or MetaStorage, which are actually wrappers for declaring the cycle state of specific services. There are several properties that indicate the current state, such as initialized, started, etc. There are also methods for state transition, such as # init. So, I wonder if it's possible to change these classes to LifeCircle form for management, At that time, there will be a superclass such as AbstractEventMeshInitializerLifeCircle, which implements management of properties such as initiate and calls to # init. Therefore, EventMeshServer only needs to maintain one
我感觉英文有点词不达意
我看到 EventMeshServer 的多个属性,如 Acl 或 MetaStorage 等,其实都是对于具体服务附加声明周期状态的包装,会有几个标志当前状态的属性,如 inited、started等,还有有状态转换的方法如 #init 等,那我想可以不可以把这些类都改成 LifeCircle 形式管理,到时候会有一个比如AbstractEventMeshInitalizerLifeCircle 之类的超类,实现了对于inited等属性等管理和对#init的调用,那么 EventMeshServer 只需要维护一个 LifeCircleList 就可以管理这些对象了
Describe the solution you'd like
`
public abstract class AbstractDemoLifeCircle {
private final AtomicBoolean inited = new AtomicBoolean(false);
private final AtomicBoolean started = new AtomicBoolean(false);
private final AtomicBoolean shutdown = new AtomicBoolean(false);
public void init() throws Exception {
if (!inited.compareAndSet(false, true)) {
return;
}
componentInit();
}
abstract void componentInit();
public void start() throws Exception {
if (!started.compareAndSet(false, true)) {
return;
}
componentStart();
}
abstract void componentStart();
public void shutdown() throws AclException {
inited.compareAndSet(true, false);
started.compareAndSet(true, false);
if (!shutdown.compareAndSet(false, true)) {
return;
}
componentStop();
}
abstract void componentStop();
}
`
`
public class Acl extends AbstractDemoLifeCircle {}
`
`
public class EventMeshServer {
...
private List components;
...
public void init() throws Exception {
components.forEach(component -> component .init());
}
}
`
As for the special handling of EventMeshBootstrap, it is completely possible to wait for init before executing the original logic
至于 EventMeshBootstrap 这种特殊处理,完全可以等init之后再执行原逻辑
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct *