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.programs.appendentries;
11 import akka.actor.ActorSystem;
12 import akka.actor.Props;
13 import akka.actor.UntypedActor;
14 import com.typesafe.config.ConfigFactory;
15 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationPayload;
16 import org.opendaylight.controller.cluster.example.messages.KeyValue;
17 import org.opendaylight.controller.cluster.raft.messages.AppendEntries;
18 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
22 private static ActorSystem actorSystem;
24 public static class ServerActor extends UntypedActor {
26 @Override public void onReceive(Object message) throws Exception {
27 if(AppendEntries.LEGACY_SERIALIZABLE_CLASS.equals(message.getClass())){
28 AppendEntries appendEntries =
29 AppendEntries.fromSerializable(message);
31 Payload data = appendEntries.getEntries()
33 if(data instanceof KeyValue){
34 System.out.println("Received : " + ((KeyValue) appendEntries.getEntries().get(0).getData()).getKey());
36 System.out.println("Received :" +
37 ((CompositeModificationPayload) appendEntries
39 .get(0).getData()).getModification().toString());
41 } else if(message instanceof String){
42 System.out.println(message);
47 public static void main(String[] args){
48 actorSystem = ActorSystem.create("appendentries", ConfigFactory
49 .load().getConfig("ODLCluster"));
51 actorSystem.actorOf(Props.create(ServerActor.class), "server");