|
|
|
@ -16,42 +16,33 @@
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.polaris.config.listener;
|
|
|
|
|
package com.tencent.cloud.polaris.context.listener;
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
|
|
|
|
|
import com.tencent.polaris.configuration.client.internal.RemoteConfigFileRepo;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
|
|
|
|
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
|
|
|
|
import org.springframework.context.ApplicationEvent;
|
|
|
|
|
import org.springframework.context.ApplicationListener;
|
|
|
|
|
import org.springframework.lang.NonNull;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Polaris config non-daemon thread stop listener
|
|
|
|
|
*
|
|
|
|
|
* @author shuiqingliu
|
|
|
|
|
* @since 2023/8/29
|
|
|
|
|
/**
|
|
|
|
|
* @author frankjlli
|
|
|
|
|
* @since 2023/9/18
|
|
|
|
|
**/
|
|
|
|
|
public class PolarisConfigApplicationEventListener implements ApplicationListener<ApplicationEvent> {
|
|
|
|
|
|
|
|
|
|
public class PolarisContextApplicationEventListener implements ApplicationListener<ApplicationEvent> {
|
|
|
|
|
|
|
|
|
|
private final PolarisSDKContextManager polarisSDKContextManager;
|
|
|
|
|
|
|
|
|
|
public PolarisConfigApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) {
|
|
|
|
|
public PolarisContextApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) {
|
|
|
|
|
this.polarisSDKContextManager = polarisSDKContextManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onApplicationEvent(@NonNull ApplicationEvent event) {
|
|
|
|
|
if (event instanceof ApplicationPreparedEvent) {
|
|
|
|
|
RemoteConfigFileRepo.registerRepoDestroyHook(polarisSDKContextManager.getSDKContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event instanceof ApplicationFailedEvent) {
|
|
|
|
|
RemoteConfigFileRepo.registerRepoDestroyHook(polarisSDKContextManager.getSDKContext());
|
|
|
|
|
//implicit invoke 'destroy' when the spring application fails to start, in order to stop non-daemon threads.
|
|
|
|
|
polarisSDKContextManager.getSDKContext().destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|