Support keep running on spring closed with properties (#12912)
* Support keep running on spring closed with properties * name
This commit is contained in:
parent
972a0814b9
commit
85b03bca56
|
|
@ -24,4 +24,6 @@ public interface ModelConstants {
|
|||
* Keep Dubbo running when spring is stopped
|
||||
*/
|
||||
String KEEP_RUNNING_ON_SPRING_CLOSED = "keepRunningOnSpringClosed";
|
||||
|
||||
String KEEP_RUNNING_ON_SPRING_CLOSED_KEY = "dubbo.module.keepRunningOnSpringClosed";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring.context;
|
||||
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.deploy.DeployListenerAdapter;
|
||||
import org.apache.dubbo.common.deploy.DeployState;
|
||||
import org.apache.dubbo.common.deploy.ModuleDeployer;
|
||||
|
|
@ -169,6 +170,9 @@ public class DubboDeployApplicationListener implements ApplicationListener<Appli
|
|||
private void onContextClosedEvent(ContextClosedEvent event) {
|
||||
try {
|
||||
Object value = moduleModel.getAttribute(ModelConstants.KEEP_RUNNING_ON_SPRING_CLOSED);
|
||||
if (value == null) {
|
||||
value = ConfigurationUtils.getProperty(moduleModel, ModelConstants.KEEP_RUNNING_ON_SPRING_CLOSED_KEY);
|
||||
}
|
||||
boolean keepRunningOnClosed = Boolean.parseBoolean(String.valueOf(value));
|
||||
if (!keepRunningOnClosed && !moduleModel.isDestroyed()) {
|
||||
moduleModel.destroy();
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ package org.apache.dubbo.qos.command.impl;
|
|||
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
|
||||
import org.apache.dubbo.common.utils.ArrayUtils;
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
import org.apache.dubbo.qos.api.BaseCommand;
|
||||
import org.apache.dubbo.qos.api.CommandContext;
|
||||
import org.apache.dubbo.registry.Registry;
|
||||
|
|
@ -35,15 +35,14 @@ import java.util.List;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class BaseOffline implements BaseCommand {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BaseOffline.class);
|
||||
public FrameworkServiceRepository serviceRepository;
|
||||
private ExecutorService executorService;
|
||||
|
||||
public BaseOffline(FrameworkModel frameworkModel) {
|
||||
this.serviceRepository = frameworkModel.getServiceRepository();
|
||||
this.executorService = frameworkModel.getBeanFactory().getBean(FrameworkExecutorRepository.class).getSharedExecutor();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -70,6 +69,7 @@ public class BaseOffline implements BaseCommand {
|
|||
public boolean offline(String servicePattern) {
|
||||
boolean hasService = false;
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(Math.min(Runtime.getRuntime().availableProcessors(), 4), new NamedThreadFactory("Dubbo-Offline"));
|
||||
try {
|
||||
List<CompletableFuture<Void>> futures = new LinkedList<>();
|
||||
Collection<ProviderModel> providerModelList = serviceRepository.allProviderModels();
|
||||
|
|
@ -92,6 +92,8 @@ public class BaseOffline implements BaseCommand {
|
|||
}
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
return hasService;
|
||||
|
|
|
|||
Loading…
Reference in New Issue