X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft-example%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fexample%2FExampleRoleChangeListener.java;h=6b4c17addc4b202cf262f6bc30999158e7d606f7;hb=d0f46920468c8e4b67c68bd9058572b2d10d75f1;hp=0d11d7201d7cbd18efa2909128c5ea2b1d3482a9;hpb=1984e660ade65e692708722d21cbbbf76701151c;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java index 0d11d7201d..6b4c17addc 100644 --- a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java +++ b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java @@ -5,12 +5,12 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.example; import akka.actor.ActorRef; import akka.actor.Cancellable; import akka.actor.Props; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -47,7 +47,7 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A private static final FiniteDuration SCHEDULER_DURATION = new FiniteDuration(1, TimeUnit.SECONDS); private static final String[] SHARDS_TO_MONITOR = new String[] {"example"}; - public ExampleRoleChangeListener(String memberName) { + public ExampleRoleChangeListener(final String memberName) { scheduleRegistrationListener(SCHEDULER_DURATION); populateRegistry(memberName); } @@ -57,7 +57,7 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A } @Override - protected void handleReceive(Object message) throws Exception { + protected void handleReceive(final Object message) { if (message instanceof RegisterListener) { // called by the scheduler at intervals to register any unregistered notifiers sendRegistrationRequests(); @@ -79,7 +79,7 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A } } - private void scheduleRegistrationListener(FiniteDuration interval) { + private void scheduleRegistrationListener(final FiniteDuration interval) { LOG.debug("--->scheduleRegistrationListener called."); registrationSchedule = getContext().system().scheduler().schedule( interval, interval, getSelf(), new RegisterListener(), @@ -87,14 +87,12 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A } - private void populateRegistry(String memberName) { - for (String shard: SHARDS_TO_MONITOR) { - String notifier = new StringBuilder().append(NOTIFIER_AKKA_URL).append(memberName) + private void populateRegistry(final String memberName) { + String notifier = new StringBuilder().append(NOTIFIER_AKKA_URL).append(memberName) .append("/").append(memberName).append("-notifier").toString(); - if (!notifierRegistrationStatus.containsKey(notifier)) { - notifierRegistrationStatus.put(notifier, false); - } + if (!notifierRegistrationStatus.containsKey(notifier)) { + notifierRegistrationStatus.put(notifier, false); } if (!registrationSchedule.isCancelled()) { @@ -103,6 +101,7 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A } @SuppressWarnings("checkstyle:IllegalCatch") + @SuppressFBWarnings("REC_CATCH_EXCEPTION") private void sendRegistrationRequests() { for (Map.Entry entry : notifierRegistrationStatus.entrySet()) { if (!entry.getValue()) { @@ -114,13 +113,13 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A notifier.tell(new RegisterRoleChangeListener(), getSelf()); } catch (Exception e) { - LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey()); + LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey(), e); } } } } - private void handleRegisterRoleChangeListenerReply(String senderId) { + private void handleRegisterRoleChangeListenerReply(final String senderId) { if (notifierRegistrationStatus.containsKey(senderId)) { notifierRegistrationStatus.put(senderId, true); @@ -143,7 +142,7 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A @Override - public void close() throws Exception { + public void close() { registrationSchedule.cancel(); } }