* 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.ActorSystem;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.typesafe.config.ConfigFactory;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.opendaylight.controller.cluster.example.messages.PrintRole;
import org.opendaylight.controller.cluster.example.messages.PrintState;
* AbstractUptypedActor and AbstractUptypedPersistentActor would need to be commented out.
* Also RaftActor handleCommand(), debug log which prints for every command other than AE/AER
*/
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
actorSystem = ActorSystem.create("raft-test", ConfigFactory
.load().getConfig("raft-test"));
System.out.println("Enter command (type bye to exit):");
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
while (true) {
String command = br.readLine();
+ if (command == null) {
+ continue;
+ }
if (command.startsWith("bye")) {
System.exit(0);
}
// create the listener using a separate actor system for each example actor
- private static void createClusterRoleChangeListener(List<String> memberIds) {
+ private static void createClusterRoleChangeListener(final List<String> memberIds) {
System.out.println("memberIds=" + memberIds);
for (String memberId : memberIds) {
ActorRef listenerActor = listenerActorSystem.actorOf(
}
}
- public static ActorRef createExampleActor(String name) {
+ public static ActorRef createExampleActor(final String name) {
return actorSystem.actorOf(ExampleActor.props(name, withoutPeer(name),
Optional.of(configParams)), name);
}
- public void createNodes(int num) {
+ public void createNodes(final int num) {
for (int i = 0; i < num; i++) {
nameCounter = nameCounter + 1;
allPeers.put("example-" + nameCounter, "akka://raft-test/user/example-" + nameCounter);
}
// add num clients to all nodes in the system
- public void addClients(int num) {
+ public void addClients(final int num) {
for (Map.Entry<String, ActorRef> actorRefEntry : actorRefs.entrySet()) {
for (int i = 0; i < num; i++) {
String clientName = "client-" + i + "-" + actorRefEntry.getKey();
}
// add num clients to a node
- public void addClientsToNode(String actorName, int num) {
+ public void addClientsToNode(final String actorName, final int num) {
ActorRef actorRef = actorRefs.get(actorName);
for (int i = 0; i < num; i++) {
String clientName = "client-" + i + "-" + actorName;
}
}
- public void stopNode(String actorName) {
+ public void stopNode(final String actorName) {
ActorRef actorRef = actorRefs.get(actorName);
for (Map.Entry<String,ActorRef> entry : clientActorRefs.entrySet()) {
allPeers.remove(actorName);
}
- public void reinstateNode(String actorName) {
+ public void reinstateNode(final String actorName) {
String address = "akka://default/user/" + actorName;
allPeers.put(actorName, address);
}
}
- public void startLoggingForClient(ActorRef client) {
+ public void startLoggingForClient(final ActorRef client) {
logGenerator.startLoggingForClient(client);
}
}
}
- public void stopLoggingForClient(ActorRef client) {
+ public void stopLoggingForClient(final ActorRef client) {
logGenerator.stopLoggingForClient(client);
}
}
- private static Map<String, String> withoutPeer(String peerId) {
+ private static Map<String, String> withoutPeer(final String peerId) {
Map<String, String> without = new ConcurrentHashMap<>(allPeers);
without.remove(peerId);