Skip to content

Commit 137d98a

Browse files
committed
refactor(aa): policy string representation
Make a method cachedPoliciesRepresentation to make printing of cachedPolicies more DRY
1 parent ca32ec8 commit 137d98a

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

‎src/main/java/org/phoebus/channelfinder/configuration/AAChannelProcessor.java‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ public void scheduledPolicyRefresh() {
105105

106106
@Override
107107
public ChannelProcessorInfo processorInfo() {
108-
String policyCounts =
109-
cachedPolicies.entrySet().stream()
110-
.map(e -> e.getKey() + "=" + e.getValue())
111-
.collect(Collectors.joining(", "));
108+
String cachedPoliciesStringValue = cachedPoliciesRepresentation(cachedPolicies);
112109
return new ChannelProcessorInfo(
113110
"AAChannelProcessor",
114111
aaEnabled,
@@ -128,7 +125,7 @@ public ChannelProcessorInfo processorInfo() {
128125
"lastPolicyRefresh",
129126
lastPolicyRefresh == null ? "never" : lastPolicyRefresh.toString(),
130127
"cachedPoliciesPerArchiver",
131-
policyCounts.isEmpty() ? "none" : policyCounts));
128+
cachedPoliciesStringValue.isEmpty() ? "none" : cachedPoliciesStringValue));
132129
}
133130

134131
/**
@@ -393,6 +390,12 @@ private Map<String, ArchiverInfo> getArchiversInfoFromCache() {
393390
e.getKey(), e.getValue(), snapshot.get(e.getKey()).policies())));
394391
}
395392

393+
private static String cachedPoliciesRepresentation(Map<String, ArchiverPolicies> policies) {
394+
return policies.entrySet().stream()
395+
.map(e -> e.getKey() + "=" + e.getValue())
396+
.collect(Collectors.joining(", "));
397+
}
398+
396399
private void refreshPolicies() {
397400
if (aaURLs.isEmpty()) {
398401
logger.log(Level.FINE, "No archivers configured; skipping policy cache refresh.");
@@ -426,11 +429,7 @@ private void refreshPolicies() {
426429
if (!changed.isEmpty()) {
427430
cachedPolicies = Collections.unmodifiableMap(updated);
428431
logger.log(
429-
Level.INFO,
430-
"AA policy cache updated: {0}",
431-
cachedPolicies.entrySet().stream()
432-
.map(e -> e.getKey() + "=" + e.getValue())
433-
.collect(Collectors.joining(", ")));
432+
Level.INFO, "AA policy cache updated: {0}", cachedPoliciesRepresentation(cachedPolicies));
434433
} else {
435434
logger.log(Level.FINE, "AA policy cache unchanged after refresh.");
436435
}

‎src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchiverPolicies.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@
22

33
import java.util.List;
44

5-
public record ArchiverPolicies(List<String> policies) {
6-
@Override
7-
public String toString() {
8-
return policies.size() + " policies";
9-
}
10-
}
5+
public record ArchiverPolicies(List<String> policies) {}

0 commit comments

Comments
 (0)