X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft-example%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fexample%2FTestDriver.java;h=ab980f77835d038b8d127fce286343416be58bc0;hp=74ded5f606f4dbbc182ed1697a01085810846339;hb=1984e660ade65e692708722d21cbbbf76701151c;hpb=a52d25ffbfe41e0b2f507efdef1ebee6bbc771c1 diff --git a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/TestDriver.java b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/TestDriver.java index 74ded5f606..ab980f7783 100644 --- a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/TestDriver.java +++ b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/TestDriver.java @@ -29,12 +29,11 @@ import org.opendaylight.controller.cluster.raft.ConfigParams; * Each ExampleActor can have one or more ClientActors. Each ClientActor spawns * a thread and starts push logs to the actor its assigned to. */ +@SuppressWarnings("checkstyle:RegexpSingleLineJava") public class TestDriver { - - private static Map allPeers = new HashMap<>(); - private static Map clientActorRefs = new HashMap(); - private static Map actorRefs = new HashMap(); + private static Map clientActorRefs = new HashMap<>(); + private static Map actorRefs = new HashMap<>(); private static LogGenerator logGenerator = new LogGenerator(); private int nameCounter = 0; private static ConfigParams configParams = new ExampleConfigParamsImpl(); @@ -58,12 +57,10 @@ public class TestDriver { * printNodes * printState * + *

* Note: when run on IDE and on debug log level, the debug logs in * AbstractUptypedActor and AbstractUptypedPersistentActor would need to be commented out. * Also RaftActor handleCommand(), debug log which prints for every command other than AE/AER - * - * @param args - * @throws Exception */ public static void main(String[] args) throws Exception { @@ -79,26 +76,26 @@ public class TestDriver { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - while(true) { + while (true) { String command = br.readLine(); if (command.startsWith("bye")) { System.exit(0); } else if (command.startsWith("createNodes")) { String[] arr = command.split(":"); - int n = Integer.parseInt(arr[1]); - td.createNodes(n); + int num = Integer.parseInt(arr[1]); + td.createNodes(num); } else if (command.startsWith("addClients")) { String[] arr = command.split(":"); - int n = Integer.parseInt(arr[1]); - td.addClients(n); + int num = Integer.parseInt(arr[1]); + td.addClients(num); } else if (command.startsWith("addClientsToNode")) { String[] arr = command.split(":"); String nodeName = arr[1]; - int n = Integer.parseInt(arr[1]); - td.addClientsToNode(nodeName, n); + int num = Integer.parseInt(arr[1]); + td.addClientsToNode(nodeName, num); } else if (command.startsWith("stopNode")) { String[] arr = command.split(":"); @@ -135,7 +132,7 @@ public class TestDriver { // create the listener using a separate actor system for each example actor private static void createClusterRoleChangeListener(List memberIds) { - System.out.println("memberIds="+memberIds); + System.out.println("memberIds=" + memberIds); for (String memberId : memberIds) { ActorRef listenerActor = listenerActorSystem.actorOf( ExampleRoleChangeListener.getProps(memberId), memberId + "-role-change-listener"); @@ -149,16 +146,15 @@ public class TestDriver { } public void createNodes(int num) { - for (int i=0; i < num; i++) { + for (int i = 0; i < num; i++) { nameCounter = nameCounter + 1; - allPeers.put("example-"+nameCounter, "akka://raft-test/user/example-"+nameCounter); + allPeers.put("example-" + nameCounter, "akka://raft-test/user/example-" + nameCounter); } for (String s : allPeers.keySet()) { ActorRef exampleActor = createExampleActor(s); actorRefs.put(s, exampleActor); - System.out.println("Created node:"+s); - + System.out.println("Created node:" + s); } createClusterRoleChangeListener(Lists.newArrayList(allPeers.keySet())); @@ -166,8 +162,8 @@ public class TestDriver { // add num clients to all nodes in the system public void addClients(int num) { - for(Map.Entry actorRefEntry : actorRefs.entrySet()) { - for (int i=0; i < num; i++) { + for (Map.Entry actorRefEntry : actorRefs.entrySet()) { + for (int i = 0; i < num; i++) { String clientName = "client-" + i + "-" + actorRefEntry.getKey(); ActorRef clientActor = actorSystem.actorOf( ClientActor.props(actorRefEntry.getValue()), clientName); @@ -180,7 +176,7 @@ public class TestDriver { // add num clients to a node public void addClientsToNode(String actorName, int num) { ActorRef actorRef = actorRefs.get(actorName); - for (int i=0; i < num; i++) { + for (int i = 0; i < num; i++) { String clientName = "client-" + i + "-" + actorName; clientActorRefs.put(clientName, actorSystem.actorOf(ClientActor.props(actorRef), clientName)); @@ -203,7 +199,7 @@ public class TestDriver { } public void reinstateNode(String actorName) { - String address = "akka://default/user/"+actorName; + String address = "akka://default/user/" + actorName; allPeers.put(actorName, address); ActorRef exampleActor = createExampleActor(actorName); @@ -213,15 +209,16 @@ public class TestDriver { } public void startAllLogging() { - if(!clientActorRefs.isEmpty()) { - for(Map.Entry client : clientActorRefs.entrySet()) { + if (!clientActorRefs.isEmpty()) { + for (Map.Entry client : clientActorRefs.entrySet()) { logGenerator.startLoggingForClient(client.getValue()); - System.out.println("Started logging for client:"+client.getKey()); + System.out.println("Started logging for client:" + client.getKey()); } } else { - System.out.println("There are no clients for any nodes. First create clients using commands- addClients: or addClientsToNode::"); + System.out.println( + "There are no clients for any nodes. First create clients using commands- addClients: or " + + "addClientsToNode::"); } - } public void startLoggingForClient(ActorRef client) { @@ -229,7 +226,7 @@ public class TestDriver { } public void stopAllLogging() { - for(Map.Entry client : clientActorRefs.entrySet()) { + for (Map.Entry client : clientActorRefs.entrySet()) { logGenerator.stopLoggingForClient(client.getValue()); } }