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%2FLogGenerator.java;h=96712eef4159542dd30726a2e9389f26821a5cb9;hb=12fcdfe39aa26dcba7fd3bb4d4c68e3d02e65c51;hp=fbe1447c72d9f10843ba94bbcedbf5a03d007e06;hpb=2727bea09c83646b6cbd2ef9672d0b7f6cf3b22f;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/LogGenerator.java b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/LogGenerator.java index fbe1447c72..96712eef41 100644 --- a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/LogGenerator.java +++ b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/LogGenerator.java @@ -1,23 +1,29 @@ +/* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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 org.opendaylight.controller.cluster.example.messages.KeyValue; - import java.util.HashMap; import java.util.Map; import java.util.Random; +import org.opendaylight.controller.cluster.example.messages.KeyValue; /** * Created by kramesha on 7/16/14. */ public class LogGenerator { - private Map clientToLoggingThread = new HashMap(); + private final Map clientToLoggingThread = new HashMap<>(); public void startLoggingForClient(ActorRef client) { LoggingThread lt = new LoggingThread(client); clientToLoggingThread.put(client, lt); - Thread t = new Thread(lt); - t.start(); + new Thread(lt).start(); } public void stopLoggingForClient(ActorRef client) { @@ -25,27 +31,29 @@ public class LogGenerator { clientToLoggingThread.remove(client); } - public class LoggingThread implements Runnable { + public static class LoggingThread implements Runnable { - private ActorRef clientActor; + private final ActorRef clientActor; private volatile boolean stopLogging = false; public LoggingThread(ActorRef clientActor) { this.clientActor = clientActor; } + @Override + @SuppressWarnings("checkstyle:RegexpSingleLineJava") public void run() { - Random r = new Random(); + Random random = new Random(); while (true) { if (stopLogging) { System.out.println("Logging stopped for client:" + clientActor.path()); break; } String key = clientActor.path().name(); - int random = r.nextInt(100); - clientActor.tell(new KeyValue(key+"-key-" + random, "value-" + random), null); + int randomInt = random.nextInt(100); + clientActor.tell(new KeyValue(key + "-key-" + randomInt, "value-" + randomInt), null); try { - Thread.sleep((random%10) * 1000); + Thread.sleep(randomInt % 10 * 1000L); } catch (InterruptedException e) { e.printStackTrace(); } @@ -59,9 +67,5 @@ public class LogGenerator { public void startLogging() { stopLogging = false; } - - } - - }