Merge pull request #110 from cfritz0127/cleaner-shutdown-on-deregistration-error

* cleaner-shutdown-on-deregistration-error:
  Catch and log exceptions that occur when attempting to deregister a service during shutdown.
This commit is contained in:
Spencer Gibb
2016-05-04 14:38:49 -06:00

View File

@@ -16,8 +16,13 @@
package org.springframework.cloud.client.discovery;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.PreDestroy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
@@ -26,9 +31,6 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Lifecycle methods that may be useful and common to various DiscoveryClient implementations.
* @author Spencer Gibb
@@ -36,6 +38,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
ApplicationContextAware, ApplicationListener<EmbeddedServletContainerInitializedEvent> {
private static final Log logger = LogFactory.getLog(AbstractDiscoveryLifecycle.class);
private boolean autoStartup = true;
private AtomicBoolean running = new AtomicBoolean(false);
@@ -74,7 +78,11 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
@Override
public void stop(Runnable callback) {
stop();
try {
stop();
} catch (Exception e) {
logger.error("A problem occurred attempting to stop discovery lifecycle", e);
}
callback.run();
}