X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FRedirManager.java;h=b4a3f0a7a45354ef4386676e4bf8c52cfb35ccf3;hb=8280a5e1a6cfd155edfafe882439b8c04c6a4509;hp=83e3c30d628b29867beeec814a4bf525f65a3e14;hpb=52c5c5ab9ba33755e26f06f41de608f825866a53;p=dmaap%2Fdatarouter.git diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java index 83e3c30d..b4a3f0a7 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java @@ -35,12 +35,12 @@ import java.util.Map; import java.util.Timer; /** - * Track redirections of subscriptions + * Track redirections of subscriptions. */ -public class RedirManager { +class RedirManager { private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(RedirManager.class); - RateLimitedOperation op; + private RateLimitedOperation op; private HashMap sid2primary = new HashMap<>(); private HashMap sid2secondary = new HashMap<>(); private String redirfile; @@ -52,17 +52,17 @@ public class RedirManager { * @param mininterval The minimum number of milliseconds between writes to the redirection information file. * @param timer The timer thread used to run delayed file writes. */ - public RedirManager(String redirfile, long mininterval, Timer timer) { + RedirManager(String redirfile, long mininterval, Timer timer) { this.redirfile = redirfile; op = new RateLimitedOperation(mininterval, timer) { public void run() { try { StringBuilder sb = new StringBuilder(); for (Map.Entry entry : sid2primary.entrySet()) { - String s = entry.getKey(); + String key = entry.getKey(); String value = entry.getValue(); - sb.append(s).append(' ').append(value).append(' ') - .append(sid2secondary.get(s)).append('\n'); + sb.append(key).append(' ').append(value).append(' ') + .append(sid2secondary.get(key)).append('\n'); } try (OutputStream os = new FileOutputStream(RedirManager.this.redirfile)) { os.write(sb.toString().getBytes()); @@ -73,10 +73,10 @@ public class RedirManager { } }; try { - String s; + String line; try (BufferedReader br = new BufferedReader(new FileReader(redirfile))) { - while ((s = br.readLine()) != null) { - addSubRedirInfo(s); + while ((line = br.readLine()) != null) { + addSubRedirInfo(line); } } } catch (Exception e) { @@ -92,7 +92,7 @@ public class RedirManager { * @param primary The URL associated with that subscription ID * @param secondary The replacement URL to use instead */ - public synchronized void redirect(String sid, String primary, String secondary) { + synchronized void redirect(String sid, String primary, String secondary) { sid2primary.put(sid, primary); sid2secondary.put(sid, secondary); op.request(); @@ -103,7 +103,7 @@ public class RedirManager { * * @param sid The subscription ID to remove from the table. */ - public synchronized void forget(String sid) { + synchronized void forget(String sid) { sid2primary.remove(sid); sid2secondary.remove(sid); op.request(); @@ -117,7 +117,7 @@ public class RedirManager { * @param primary The configured primary URL. * @return The destination URL to really use. */ - public synchronized String lookup(String sid, String primary) { + synchronized String lookup(String sid, String primary) { String oprim = sid2primary.get(sid); if (primary.equals(oprim)) { return (sid2secondary.get(sid)); @@ -128,16 +128,16 @@ public class RedirManager { } /** - * Is a subscription redirected? + * Is a subscription redirected. */ - public synchronized boolean isRedirected(String sid) { + synchronized boolean isRedirected(String sid) { return (sid != null && sid2secondary.get(sid) != null); } - private void addSubRedirInfo(String s) { - s = s.trim(); - String[] sx = s.split(" "); - if (s.startsWith("#") || sx.length != 3) { + private void addSubRedirInfo(String subRedirInfo) { + subRedirInfo = subRedirInfo.trim(); + String[] sx = subRedirInfo.split(" "); + if (subRedirInfo.startsWith("#") || sx.length != 3) { return; } sid2primary.put(sx[0], sx[1]);