Skip to content

Commit

Permalink
Support for Targeted Property Refresh in /actuator/refresh Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelj90 committed Aug 28, 2024
1 parent aa04daa commit b60d76f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ protected RefreshScope getScope() {
return this.scope;
}

public synchronized Set<String> refresh() {
Set<String> keys = refreshEnvironment();
this.scope.refreshAll();
return keys;
public Set<String> refresh(Set<String> propertiesToRefresh, RefreshStrategy strategy) {
return strategy.refresh(this, propertiesToRefresh);
}

public synchronized Set<String> refreshSpecificEnvironment(Set<String> propertiesToRefresh){
//TODO: Implement this.
return propertiesToRefresh;
}

public synchronized Set<String> refreshEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.springframework.cloud.context.refresh;

import java.util.Set;

public class RefreshAllStrategy implements RefreshStrategy {
@Override
public Set<String> refresh(ContextRefresher contextRefresher, Set<String> propertiesToRefresh) {
return contextRefresher.refreshEnvironment();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.springframework.cloud.context.refresh;

import java.util.Set;

public class RefreshSpecificPropertiesStrategy implements RefreshStrategy {
@Override
public Set<String> refresh(ContextRefresher contextRefresher, Set<String> propertiesToRefresh) {
return contextRefresher.refreshSpecificEnvironment(propertiesToRefresh);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.springframework.cloud.context.refresh;

import java.util.Set;

public interface RefreshStrategy {
Set<String> refresh(ContextRefresher contextRefresher, Set<String> propertiesToRefresh);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ public RefreshEndpoint(ContextRefresher contextRefresher) {
}

@WriteOperation
public Collection<String> refresh() {
Set<String> keys = this.contextRefresher.refresh();
public Collection<String> refresh(Set<String> propertiesToRefresh) {
RefreshStrategy strategy = (propertiesToRefresh != null && !propertiesToRefresh.isEmpty())
? new RefreshSpecificPropertiesStrategy()
: new RefreshAllStrategy();
Set<String> keys = this.contextRefresher.refresh(propertiesToRefresh, strategy);
LOG.info("Refreshed keys : " + keys);
return keys;
}
Expand Down

0 comments on commit b60d76f

Please sign in to comment.