diff --git a/core/src/main/java/com/alibaba/nacos/core/listener/LoggingApplicationListener.java b/core/src/main/java/com/alibaba/nacos/core/listener/LoggingApplicationListener.java index d0968b13b3e..9391a26fd11 100644 --- a/core/src/main/java/com/alibaba/nacos/core/listener/LoggingApplicationListener.java +++ b/core/src/main/java/com/alibaba/nacos/core/listener/LoggingApplicationListener.java @@ -18,7 +18,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import static org.springframework.boot.context.logging.LoggingApplicationListener.CONFIG_PROPERTY; @@ -36,11 +35,6 @@ public class LoggingApplicationListener implements NacosApplicationListener { private static final Logger LOGGER = LoggerFactory.getLogger(LoggingApplicationListener.class); - @Override - public void starting() { - - } - @Override public void environmentPrepared(ConfigurableEnvironment environment) { if (!environment.containsProperty(CONFIG_PROPERTY)) { @@ -52,29 +46,4 @@ public void environmentPrepared(ConfigurableEnvironment environment) { } } } - - @Override - public void contextPrepared(ConfigurableApplicationContext context) { - - } - - @Override - public void contextLoaded(ConfigurableApplicationContext context) { - - } - - @Override - public void started(ConfigurableApplicationContext context) { - - } - - @Override - public void running(ConfigurableApplicationContext context) { - - } - - @Override - public void failed(ConfigurableApplicationContext context, Throwable exception) { - - } } diff --git a/core/src/main/java/com/alibaba/nacos/core/listener/NacosApplicationListener.java b/core/src/main/java/com/alibaba/nacos/core/listener/NacosApplicationListener.java index 08f74f5551f..bfb520bb629 100644 --- a/core/src/main/java/com/alibaba/nacos/core/listener/NacosApplicationListener.java +++ b/core/src/main/java/com/alibaba/nacos/core/listener/NacosApplicationListener.java @@ -31,42 +31,48 @@ public interface NacosApplicationListener { /** * {@link SpringApplicationRunListener#starting}. */ - void starting(); + default void starting() { + } /** * {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#environmentPrepared}. * * @param environment environment */ - void environmentPrepared(ConfigurableEnvironment environment); + default void environmentPrepared(ConfigurableEnvironment environment) { + } /** * {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#contextLoaded}. * * @param context context */ - void contextPrepared(ConfigurableApplicationContext context); + default void contextPrepared(ConfigurableApplicationContext context) { + } /** * {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#contextLoaded}. * * @param context context */ - void contextLoaded(ConfigurableApplicationContext context); + default void contextLoaded(ConfigurableApplicationContext context) { + } /** * {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#started}. * * @param context context */ - void started(ConfigurableApplicationContext context); + default void started(ConfigurableApplicationContext context) { + } /** * {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#running}. * * @param context context */ - void running(ConfigurableApplicationContext context); + default void running(ConfigurableApplicationContext context) { + } /** * {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#failed}. @@ -74,5 +80,6 @@ public interface NacosApplicationListener { * @param context context * @param exception exception */ - void failed(ConfigurableApplicationContext context, Throwable exception); + default void failed(ConfigurableApplicationContext context, Throwable exception) { + } } diff --git a/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java b/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java index fa1e21b6130..9555418d79f 100644 --- a/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java +++ b/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java @@ -109,11 +109,6 @@ public void contextPrepared(ConfigurableApplicationContext context) { logStarting(); } - @Override - public void contextLoaded(ConfigurableApplicationContext context) { - - } - @Override public void started(ConfigurableApplicationContext context) { starting = false; @@ -124,10 +119,6 @@ public void started(ConfigurableApplicationContext context) { judgeStorageMode(context.getEnvironment()); } - @Override - public void running(ConfigurableApplicationContext context) { - } - @Override public void failed(ConfigurableApplicationContext context, Throwable exception) { starting = false; @@ -233,8 +224,8 @@ private void makeWorkDir() { private void logStarting() { if (!EnvUtil.getStandaloneMode()) { - scheduledExecutorService = ExecutorFactory - .newSingleScheduledExecutorService(new NameThreadFactory("com.alibaba.nacos.core.nacos-starting")); + scheduledExecutorService = ExecutorFactory.newSingleScheduledExecutorService( + new NameThreadFactory("com.alibaba.nacos.core.nacos-starting")); scheduledExecutorService.scheduleWithFixedDelay(() -> { if (starting) { @@ -247,7 +238,8 @@ private void logStarting() { private void judgeStorageMode(ConfigurableEnvironment env) { // External data sources are used by default in cluster mode - boolean useExternalStorage = (DEFAULT_DATABASE.equalsIgnoreCase(env.getProperty(DATASOURCE_PLATFORM_PROPERTY, DEFAULT_DATASOURCE_PLATFORM))); + boolean useExternalStorage = (DEFAULT_DATABASE.equalsIgnoreCase( + env.getProperty(DATASOURCE_PLATFORM_PROPERTY, DEFAULT_DATASOURCE_PLATFORM))); // must initialize after setUseExternalDB // This value is true in stand-alone mode and false in cluster mode @@ -264,6 +256,7 @@ private void judgeStorageMode(ConfigurableEnvironment env) { } LOGGER.info("Nacos started successfully in {} mode. use {} storage", - System.getProperty(MODE_PROPERTY_KEY_STAND_MODE), useExternalStorage ? DATASOURCE_MODE_EXTERNAL : DATASOURCE_MODE_EMBEDDED); + System.getProperty(MODE_PROPERTY_KEY_STAND_MODE), + useExternalStorage ? DATASOURCE_MODE_EXTERNAL : DATASOURCE_MODE_EMBEDDED); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/GracefulShutdownListener.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/GracefulShutdownListener.java index 667bbb1dcbe..693f281d03a 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/GracefulShutdownListener.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/GracefulShutdownListener.java @@ -18,45 +18,15 @@ import com.alibaba.nacos.core.listener.NacosApplicationListener; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.env.ConfigurableEnvironment; /** * graceful shutdown listenner. + * * @author Weizhanâ–ªYun * @date 2022/11/2 14:40 */ public class GracefulShutdownListener implements NacosApplicationListener { - @Override - public void starting() { - - } - - @Override - public void environmentPrepared(ConfigurableEnvironment environment) { - - } - - @Override - public void contextPrepared(ConfigurableApplicationContext context) { - - } - - @Override - public void contextLoaded(ConfigurableApplicationContext context) { - - } - - @Override - public void started(ConfigurableApplicationContext context) { - - } - - @Override - public void running(ConfigurableApplicationContext context) { - - } - @Override public void failed(ConfigurableApplicationContext context, Throwable exception) { try {