Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUBBO-2525]: Problems of graceful shutdown in 2.6.3 and some recommendation #2725

Merged
merged 4 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,6 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bootstrap</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-compatible</artifactId>
Expand Down Expand Up @@ -439,7 +432,6 @@
<include>org.apache.dubbo:dubbo-serialization-kryo</include>
<include>org.apache.dubbo:dubbo-serialization-jdk</include>
<include>org.apache.dubbo:dubbo-serialization-protostuff</include>
<include>org.apache.dubbo:dubbo-bootstrap</include>
</includes>
</artifactSet>
<transformers>
Expand Down
5 changes: 0 additions & 5 deletions dubbo-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,6 @@
<artifactId>dubbo-serialization-protostuff</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bootstrap</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-compatible</artifactId>
Expand Down
47 changes: 0 additions & 47 deletions dubbo-bootstrap/pom.xml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,4 @@ public void destroy() {
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(name).destroy();
}
}

/**
* Just for compatibility.
* It should be deleted in the next major version, say 2.7.x.
*/
@Deprecated
public static void destroyAll() {
DubboShutdownHook.getDubboShutdownHook().destroyAll();
}
}
}
7 changes: 1 addition & 6 deletions dubbo-config/dubbo-config-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
<artifactId>dubbo-config-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bootstrap</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
Expand Down Expand Up @@ -157,4 +152,4 @@
-->
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.annotation.Reference;
Expand Down Expand Up @@ -111,17 +110,16 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)

@Override
public void destroy() {

// This will only be called for singleton scope bean, and expected to be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
// We will guarantee dubbo related resources being released with dubbo shutdown hook.

// for (ServiceConfig<?> serviceConfig : serviceConfigs) {
// try {
// serviceConfig.unexport();
// } catch (Throwable e) {
// logger.error(e.getMessage(), e);
// }
// }
// no need to destroy here
// see org.apache.dubbo.config.spring.extension.SpringExtensionFactory.ShutdownHookListener
/*
for (ServiceConfig<?> serviceConfig : serviceConfigs) {
try {
serviceConfig.unexport();
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
for (ReferenceConfig<?> referenceConfig : referenceConfigs.values()) {
try {
Expand All @@ -130,6 +128,7 @@ public void destroy() {
logger.error(e.getMessage(), e);
}
}
*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.AbstractApplicationContext;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.apache.dubbo.config.spring.util.BeanFactoryUtils.addApplicationListener;

/**
* ServiceFactoryBean
*
Expand Down Expand Up @@ -72,23 +72,7 @@ public ServiceBean(Service service) {
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
SpringExtensionFactory.addApplicationContext(applicationContext);
try {
Method method = applicationContext.getClass().getMethod("addApplicationListener", ApplicationListener.class); // backward compatibility to spring 2.0.1
method.invoke(applicationContext, this);
supportedApplicationListener = true;
} catch (Throwable t) {
if (applicationContext instanceof AbstractApplicationContext) {
try {
Method method = AbstractApplicationContext.class.getDeclaredMethod("addListener", ApplicationListener.class); // backward compatibility to spring 2.0.1
if (!method.isAccessible()) {
method.setAccessible(true);
}
method.invoke(applicationContext, this);
supportedApplicationListener = true;
} catch (Throwable t2) {
}
}
}
supportedApplicationListener = addApplicationListener(applicationContext, this);
}

@Override
Expand Down Expand Up @@ -249,9 +233,7 @@ && getInterface() != null && getInterface().length() > 0

@Override
public void destroy() throws Exception {
// This will only be called for singleton scope bean, and expected to be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
// We will guarantee dubbo related resources being released with dubbo shutdown hook.
//unexport();
// no need to export here, see org.apache.dubbo.config.spring.extension.SpringExtensionFactory.ShutdownHookListener
}

// merged from dubbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.config.DubboShutdownHook;
import org.apache.dubbo.config.spring.util.BeanFactoryUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

import java.util.Set;

Expand All @@ -34,9 +39,11 @@ public class SpringExtensionFactory implements ExtensionFactory {
private static final Logger logger = LoggerFactory.getLogger(SpringExtensionFactory.class);

private static final Set<ApplicationContext> contexts = new ConcurrentHashSet<ApplicationContext>();
private static final ApplicationListener shutdownHookListener = new ShutdownHookListener();

public static void addApplicationContext(ApplicationContext context) {
contexts.add(context);
BeanFactoryUtils.addApplicationListener(context, shutdownHookListener);
}

public static void removeApplicationContext(ApplicationContext context) {
Expand Down Expand Up @@ -93,4 +100,16 @@ public <T> T getExtension(Class<T> type, String name) {
return null;
}

private static class ShutdownHookListener implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextClosedEvent) {
// we call it anyway since dubbo shutdown hook make sure its destroyAll() is re-entrant.
// pls. note we should not remove dubbo shutdown hook when spring framework is present, this is because
// its shutdown hook may not be installed.
DubboShutdownHook shutdownHook = DubboShutdownHook.getDubboShutdownHook();
shutdownHook.destroyAll();
}
}
}
}
Loading