This is an automated email from the ASF dual-hosted git repository. zhangliang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new 69e9cf4b92f Refactor ContextManager (#35015) 69e9cf4b92f is described below commit 69e9cf4b92fd9851f0b1c079e90ef78cd9580e84 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Sun Mar 16 23:38:11 2025 +0800 Refactor ContextManager (#35015) --- .../org/apache/shardingsphere/mode/manager/ContextManager.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java index fbaa7a8edce..c2fcf3bc097 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java @@ -80,10 +80,8 @@ public final class ContextManager implements AutoCloseable { persistServiceFacade = new PersistServiceFacade(repository, computeNodeInstanceContext.getModeConfiguration(), metaDataContextManager); stateContext = new StateContext(persistServiceFacade.getStateService().load()); executorEngine = ExecutorEngine.createExecutorEngineWithSize(metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)); - for (ContextManagerLifecycleListener each : ShardingSphereServiceLoader.getServiceInstances(ContextManagerLifecycleListener.class)) { - if (computeNodeInstanceContext.getModeConfiguration().isCluster()) { - each.onInitialized(this); - } + if (computeNodeInstanceContext.getModeConfiguration().isCluster()) { + ShardingSphereServiceLoader.getServiceInstances(ContextManagerLifecycleListener.class).forEach(each -> each.onInitialized(this)); } } @@ -233,8 +231,8 @@ public final class ContextManager implements AutoCloseable { @Override public void close() { - for (ContextManagerLifecycleListener each : ShardingSphereServiceLoader.getServiceInstances(ContextManagerLifecycleListener.class)) { - each.onDestroyed(this); + if (computeNodeInstanceContext.getModeConfiguration().isCluster()) { + ShardingSphereServiceLoader.getServiceInstances(ContextManagerLifecycleListener.class).forEach(each -> each.onDestroyed(this)); } executorEngine.close(); metaDataContexts.getMetaData().close();