Merge remote-tracking branch 'origin/2.2.x'
# Conflicts: # docs/src/main/asciidoc/_configprops.adoc # spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerProperties.java # spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/HealthCheckServiceInstanceListSupplier.java # spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/HealthCheckServiceInstanceListSupplierTests.java
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.autoconfigure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
||||
@@ -29,6 +33,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.cloud.context.restart.PauseHandler;
|
||||
import org.springframework.cloud.context.restart.RestartEndpoint;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.cloud.endpoint.RefreshEndpoint;
|
||||
@@ -36,6 +41,7 @@ import org.springframework.cloud.health.RefreshScopeHealthIndicator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.integration.core.Pausable;
|
||||
import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
|
||||
/**
|
||||
@@ -77,9 +83,17 @@ public class RefreshEndpointAutoConfiguration {
|
||||
@ConditionalOnClass(IntegrationMBeanExporter.class)
|
||||
class RestartEndpointWithIntegrationConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private IntegrationMBeanExporter exporter;
|
||||
|
||||
RestartEndpointWithIntegrationConfiguration(@Autowired(required = false) IntegrationMBeanExporter exporter) {
|
||||
this.exporter = exporter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PauseHandler integrationPauseHandler(ObjectProvider<Pausable> pausables) {
|
||||
return new IntegrationPauseHandler(pausables.orderedStream().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnAvailableEndpoint
|
||||
@ConditionalOnMissingBean
|
||||
@@ -91,6 +105,30 @@ class RestartEndpointWithIntegrationConfiguration {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
private class IntegrationPauseHandler implements PauseHandler {
|
||||
|
||||
private List<Pausable> pausables = new ArrayList<>();
|
||||
|
||||
IntegrationPauseHandler(List<Pausable> pausables) {
|
||||
this.pausables.addAll(pausables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
for (Pausable pausable : this.pausables) {
|
||||
pausable.pause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
for (int i = this.pausables.size(); i-- > 0;) {
|
||||
this.pausables.get(i).resume();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.restart;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public interface PauseHandler {
|
||||
|
||||
void pause();
|
||||
|
||||
void resume();
|
||||
|
||||
}
|
||||
@@ -19,10 +19,12 @@ package org.springframework.cloud.context.restart;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
//
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -63,6 +65,8 @@ public class RestartEndpoint implements ApplicationListener<ApplicationPreparedE
|
||||
|
||||
private IntegrationShutdown integrationShutdown;
|
||||
|
||||
private List<PauseHandler> pauseHandlers = Collections.emptyList();
|
||||
|
||||
private long timeout;
|
||||
|
||||
// @ManagedAttribute
|
||||
@@ -88,6 +92,8 @@ public class RestartEndpoint implements ApplicationListener<ApplicationPreparedE
|
||||
this.args = this.event.getArgs();
|
||||
this.application = this.event.getSpringApplication();
|
||||
this.application.addInitializers(new PostProcessorInitializer());
|
||||
this.pauseHandlers = this.context.getBeanProvider(PauseHandler.class).orderedStream()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,15 +169,16 @@ public class RestartEndpoint implements ApplicationListener<ApplicationPreparedE
|
||||
|
||||
// @ManagedOperation
|
||||
public synchronized void doPause() {
|
||||
if (this.context != null) {
|
||||
this.context.stop();
|
||||
for (PauseHandler handler : this.pauseHandlers) {
|
||||
handler.pause();
|
||||
}
|
||||
}
|
||||
|
||||
// @ManagedOperation
|
||||
public synchronized void doResume() {
|
||||
if (this.context != null) {
|
||||
this.context.start();
|
||||
for (int i = this.pauseHandlers.size(); i-- > 0;) {
|
||||
PauseHandler handler = this.pauseHandlers.get(i);
|
||||
handler.resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user