Skip to content

Commit

Permalink
Modify the method modifier of NacosApplicationListener to default (al…
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xiao-shuang authored Nov 4, 2022
1 parent 0aeb2bd commit e8d7135
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,55 @@ 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}.
*
* @param context context
* @param exception exception
*/
void failed(ConfigurableApplicationContext context, Throwable exception);
default void failed(ConfigurableApplicationContext context, Throwable exception) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ public void contextPrepared(ConfigurableApplicationContext context) {
logStarting();
}

@Override
public void contextLoaded(ConfigurableApplicationContext context) {

}

@Override
public void started(ConfigurableApplicationContext context) {
starting = false;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e8d7135

Please sign in to comment.