Make REUSABLE_*_TL final
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / programs / appendentries / Server.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.programs.appendentries;
10
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;
19
20 public class Server {
21
22     private static ActorSystem actorSystem;
23
24     public static class ServerActor extends UntypedActor {
25
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);
30
31                 Payload data = appendEntries.getEntries()
32                     .get(0).getData();
33                 if(data instanceof KeyValue){
34                     System.out.println("Received : " + ((KeyValue) appendEntries.getEntries().get(0).getData()).getKey());
35                 } else {
36                     System.out.println("Received :" +
37                         ((CompositeModificationPayload) appendEntries
38                             .getEntries()
39                             .get(0).getData()).getModification().toString());
40                 }
41             } else if(message instanceof String){
42                 System.out.println(message);
43             }
44         }
45     }
46
47     public static void main(String[] args){
48         actorSystem = ActorSystem.create("appendentries", ConfigFactory
49             .load().getConfig("ODLCluster"));
50
51         actorSystem.actorOf(Props.create(ServerActor.class), "server");
52     }
53 }