2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.example;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import org.opendaylight.controller.cluster.example.messages.KeyValue;
15 import java.io.BufferedReader;
16 import java.io.InputStreamReader;
17 import java.util.HashMap;
21 private static final ActorSystem actorSystem = ActorSystem.create();
22 // Create three example actors
23 private static Map<String, String> allPeers = new HashMap<>();
26 allPeers.put("example-1", "akka://default/user/example-1");
27 allPeers.put("example-2", "akka://default/user/example-2");
28 allPeers.put("example-3", "akka://default/user/example-3");
31 public static void main(String[] args) throws Exception{
32 ActorRef example1Actor =
33 actorSystem.actorOf(ExampleActor.props("example-1",
34 withoutPeer("example-1")), "example-1");
36 ActorRef example2Actor =
37 actorSystem.actorOf(ExampleActor.props("example-2",
38 withoutPeer("example-2")), "example-2");
40 ActorRef example3Actor =
41 actorSystem.actorOf(ExampleActor.props("example-3",
42 withoutPeer("example-3")), "example-3");
44 ActorRef clientActor = actorSystem.actorOf(ClientActor.props(example1Actor));
46 new BufferedReader(new InputStreamReader(System.in));
49 System.out.print("Enter Integer (0 to exit):");
51 int i = Integer.parseInt(br.readLine());
55 clientActor.tell(new KeyValue("key " + i, "value " + i), null);
56 } catch (NumberFormatException nfe) {
57 System.err.println("Invalid Format!");
62 private static Map<String, String> withoutPeer(String peerId) {
63 Map<String, String> without = new HashMap<>(allPeers);
64 without.remove(peerId);