Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Bump upstream SNAPSHOTS
[controller.git]
/
opendaylight
/
md-sal
/
sal-akka-raft-example
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
cluster
/
example
/
LogGenerator.java
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 b2fc19f6e0b5cb8ac26caf4f7213d452a7add8dc..9559f1cff422c75fc116ffbfa321338eda320175 100644
(file)
--- 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
@@
-5,57
+5,60
@@
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* 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;
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 java.util.HashMap;
import java.util.Map;
import java.util.Random;
+import org.opendaylight.controller.cluster.example.messages.KeyValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by kramesha on 7/16/14.
*/
public class LogGenerator {
/**
* Created by kramesha on 7/16/14.
*/
public class LogGenerator {
- private Map<ActorRef, LoggingThread> clientToLoggingThread = new HashMap<ActorRef, LoggingThread>();
+ private static final Logger LOG = LoggerFactory.getLogger(LogGenerator.class);
+
+ private final Map<ActorRef, LoggingThread> clientToLoggingThread = new HashMap<>();
- public void startLoggingForClient(ActorRef client) {
+ public void startLoggingForClient(
final
ActorRef client) {
LoggingThread lt = new LoggingThread(client);
clientToLoggingThread.put(client, lt);
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) {
+ public void stopLoggingForClient(
final
ActorRef client) {
clientToLoggingThread.get(client).stopLogging();
clientToLoggingThread.remove(client);
}
clientToLoggingThread.get(client).stopLogging();
clientToLoggingThread.remove(client);
}
- public class LoggingThread implements Runnable {
+ public static class LoggingThread implements Runnable {
+ private final Random random = new Random();
+ private final ActorRef clientActor;
- private ActorRef clientActor;
private volatile boolean stopLogging = false;
private volatile boolean stopLogging = false;
- public LoggingThread(ActorRef clientActor) {
+ public LoggingThread(
final
ActorRef clientActor) {
this.clientActor = clientActor;
}
this.clientActor = clientActor;
}
+ @Override
public void run() {
public void run() {
- Random r = new Random();
while (true) {
if (stopLogging) {
while (true) {
if (stopLogging) {
-
System.out.println("Logging stopped for client:" +
clientActor.path());
+
LOG.info("Logging stopped for client: {}",
clientActor.path());
break;
}
String key = clientActor.path().name();
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 {
try {
- Thread.sleep(
(random%10) * 1000
);
+ Thread.sleep(
randomInt % 10 * 1000L
);
} catch (InterruptedException e) {
} catch (InterruptedException e) {
-
e.printStackTrace(
);
+
LOG.info("Interrupted while sleeping", e
);
}
}
}
}
}
}
@@
-67,9
+70,5
@@
public class LogGenerator {
public void startLogging() {
stopLogging = false;
}
public void startLogging() {
stopLogging = false;
}
-
-
}
}
-
-
}
}