Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
1. Renamed RefreshSupport to ContextRefresher.
2. Moved ContextSupport bean creation to RefreshAutoConfiguration.
  • Loading branch information
venilnoronha committed Mar 22, 2016
commit d1b1f59bf9a663a942330017adf40f83f8ab9cfa
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.cloud.context.environment.EnvironmentManager;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.cloud.logging.LoggingRebinder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
Expand All @@ -33,7 +35,7 @@
* the Environment (e.g. rebinding logger levels).
*
* @author Dave Syer
*
* @author Venil Noronha
*/
@Configuration
@ConditionalOnClass(RefreshScope.class)
Expand All @@ -58,4 +60,11 @@ public EnvironmentManager environmentManager(ConfigurableEnvironment environment
return new EnvironmentManager(environment);
}

@Bean
@ConditionalOnMissingBean
public ContextRefresher contextRefresher(ConfigurableApplicationContext context,
RefreshScope scope) {
return new ContextRefresher(context, scope);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@
import org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
import org.springframework.cloud.context.refresh.RefreshSupport;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.restart.RestartEndpoint;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.cloud.endpoint.RefreshEndpoint;
import org.springframework.cloud.endpoint.event.RefreshEventListener;
import org.springframework.cloud.health.RefreshScopeHealthIndicator;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
Expand Down Expand Up @@ -117,15 +116,8 @@ protected static class RefreshEndpointConfiguration {

@Bean
@ConditionalOnMissingBean
public RefreshSupport refreshSupport(ConfigurableApplicationContext context,
RefreshScope scope) {
return new RefreshSupport(context, scope);
}

@Bean
@ConditionalOnMissingBean
public RefreshEndpoint refreshEndpoint(RefreshSupport refreshSupport) {
RefreshEndpoint endpoint = new RefreshEndpoint(refreshSupport);
public RefreshEndpoint refreshEndpoint(ContextRefresher contextRefresher) {
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
return endpoint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author Venil Noronha
*/
public class RefreshSupport {
public class ContextRefresher {

private static final String REFRESH_ARGS_PROPERTY_SOURCE = "refreshArgs";

Expand All @@ -42,7 +42,7 @@ public class RefreshSupport {
private ConfigurableApplicationContext context;
private RefreshScope scope;

public RefreshSupport(ConfigurableApplicationContext context, RefreshScope scope) {
public ContextRefresher(ConfigurableApplicationContext context, RefreshScope scope) {
this.context = context;
this.scope = scope;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.refresh.RefreshSupport;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;

Expand All @@ -34,16 +34,16 @@
@ManagedResource
public class RefreshEndpoint extends AbstractEndpoint<Collection<String>> {

private RefreshSupport refreshSupport;
private ContextRefresher contextRefresher;

public RefreshEndpoint(RefreshSupport refreshSupport) {
public RefreshEndpoint(ContextRefresher contextRefresher) {
super("refresh");
this.refreshSupport = refreshSupport;
this.contextRefresher = contextRefresher;
}

@ManagedOperation
public String[] refresh() {
Set<String> keys = refreshSupport.refresh();
Set<String> keys = contextRefresher.refresh();
return keys.toArray(new String[keys.size()]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.refresh.RefreshSupport;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.context.ApplicationEvent;
Expand Down Expand Up @@ -71,8 +71,8 @@ public void keysComputedWhenAdded() throws Exception {
RefreshScope scope = new RefreshScope();
scope.setApplicationContext(this.context);
EnvironmentTestUtils.addEnvironment(this.context, "spring.profiles.active=local");
RefreshSupport refreshSupport = new RefreshSupport(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(refreshSupport);
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
Collection<String> keys = endpoint.invoke();
assertTrue("Wrong keys: " + keys, keys.contains("added"));
}
Expand All @@ -86,8 +86,8 @@ public void keysComputedWhenOveridden() throws Exception {
scope.setApplicationContext(this.context);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.profiles.active=override");
RefreshSupport refreshSupport = new RefreshSupport(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(refreshSupport);
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
Collection<String> keys = endpoint.invoke();
assertTrue("Wrong keys: " + keys, keys.contains("message"));
}
Expand All @@ -102,8 +102,8 @@ public void keysComputedWhenChangesInExternalProperties() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.cloud.bootstrap.sources="
+ ExternalPropertySourceLocator.class.getName());
RefreshSupport refreshSupport = new RefreshSupport(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(refreshSupport);
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
Collection<String> keys = endpoint.invoke();
assertTrue("Wrong keys: " + keys, keys.contains("external.message"));
}
Expand All @@ -120,8 +120,8 @@ public void springMainSourcesEmptyInRefreshCycle() throws Exception {
// construct the environment for refresh)
EnvironmentTestUtils.addEnvironment(this.context,
"spring.main.sources=" + ExternalPropertySourceLocator.class.getName());
RefreshSupport refreshSupport = new RefreshSupport(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(refreshSupport);
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
Collection<String> keys = endpoint.invoke();
assertFalse("Wrong keys: " + keys, keys.contains("external.message"));
}
Expand All @@ -132,8 +132,8 @@ public void eventsPublishedInOrder() throws Exception {
.bannerMode(Mode.OFF).run();
RefreshScope scope = new RefreshScope();
scope.setApplicationContext(this.context);
RefreshSupport refreshSupport = new RefreshSupport(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(refreshSupport);
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
Empty empty = this.context.getBean(Empty.class);
endpoint.invoke();
int after = empty.events.size();
Expand All @@ -147,8 +147,8 @@ public void shutdownHooksCleaned() {
.web(false).bannerMode(Mode.OFF).run();
RefreshScope scope = new RefreshScope();
scope.setApplicationContext(context);
RefreshSupport refreshSupport = new RefreshSupport(context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(refreshSupport);
ContextRefresher contextRefresher = new ContextRefresher(context, scope);
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
int count = countShutdownHooks();
endpoint.invoke();
int after = countShutdownHooks();
Expand Down