Test RaftActor using a simple program
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / example / ClientActor.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.cluster.example;
10
11 import akka.actor.ActorRef;
12 import akka.actor.Props;
13 import akka.actor.UntypedActor;
14 import akka.event.Logging;
15 import akka.event.LoggingAdapter;
16 import akka.japi.Creator;
17 import org.opendaylight.controller.cluster.example.messages.KeyValue;
18 import org.opendaylight.controller.cluster.example.messages.KeyValueSaved;
19
20 public class ClientActor extends UntypedActor {
21     protected final LoggingAdapter LOG =
22         Logging.getLogger(getContext().system(), this);
23
24     private final ActorRef target;
25
26     public ClientActor(ActorRef target){
27         this.target = target;
28     }
29
30     public static Props props(final ActorRef target){
31         return Props.create(new Creator<ClientActor>(){
32
33             @Override public ClientActor create() throws Exception {
34                 return new ClientActor(target);
35             }
36         });
37     }
38
39     @Override public void onReceive(Object message) throws Exception {
40         if(message instanceof KeyValue) {
41             target.tell(message, getSelf());
42         } else if(message instanceof KeyValueSaved){
43             LOG.info("KeyValue saved");
44         }
45     }
46 }