X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fexample%2FMain.java;fp=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fexample%2FMain.java;h=27d083f2b38f60998721eb0025a949854ec1d394;hb=fdab53ef9033fc83c812f7d3d6d3327d3d176f0f;hp=0000000000000000000000000000000000000000;hpb=a0c5aba42aa36337ff1c6760175918b786897c9e;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/Main.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/Main.java new file mode 100644 index 0000000000..27d083f2b3 --- /dev/null +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/Main.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014 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 akka.actor.ActorSystem; +import org.opendaylight.controller.cluster.example.messages.KeyValue; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +public class Main { + private static final ActorSystem actorSystem = ActorSystem.create(); + // Create three example actors + private static Map allPeers = new HashMap<>(); + + static { + allPeers.put("example-1", "akka://default/user/example-1"); + allPeers.put("example-2", "akka://default/user/example-2"); + allPeers.put("example-3", "akka://default/user/example-3"); + } + + public static void main(String[] args) throws Exception{ + ActorRef example1Actor = + actorSystem.actorOf(ExampleActor.props("example-1", + withoutPeer("example-1")), "example-1"); + + ActorRef example2Actor = + actorSystem.actorOf(ExampleActor.props("example-2", + withoutPeer("example-2")), "example-2"); + + ActorRef example3Actor = + actorSystem.actorOf(ExampleActor.props("example-3", + withoutPeer("example-3")), "example-3"); + + ActorRef clientActor = actorSystem.actorOf(ClientActor.props(example1Actor)); + BufferedReader br = + new BufferedReader(new InputStreamReader(System.in)); + + while(true) { + System.out.print("Enter Integer (0 to exit):"); + try { + int i = Integer.parseInt(br.readLine()); + if(i == 0){ + System.exit(0); + } + clientActor.tell(new KeyValue("key " + i, "value " + i), null); + } catch (NumberFormatException nfe) { + System.err.println("Invalid Format!"); + } + } + } + + private static Map withoutPeer(String peerId) { + Map without = new HashMap<>(allPeers); + without.remove(peerId); + return without; + } +}