2 * Copyright (c) 2015 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.raft.utils;
11 import static org.junit.Assert.assertTrue;
12 import akka.actor.Props;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
17 public class ForwardMessageToBehaviorActor extends MessageCollectorActor {
18 private volatile RaftActorBehavior behavior;
19 private final List<RaftActorBehavior> behaviorChanges = new ArrayList<>();
22 public void onReceive(Object message) throws Exception {
23 if(behavior != null) {
24 behaviorChanges.add(behavior.handleMessage(sender(), message));
26 super.onReceive(message);
29 public static Props props() {
30 return Props.create(ForwardMessageToBehaviorActor.class);
33 public void setBehavior(RaftActorBehavior behavior){
34 this.behavior = behavior;
37 public RaftActorBehavior getFirstBehaviorChange() {
38 assertTrue("no behavior changes present", behaviorChanges.size() > 0);
39 return behaviorChanges.get(0);
42 public RaftActorBehavior getLastBehaviorChange() {
43 assertTrue("no behavior changes present", behaviorChanges.size() > 0);
44 return behaviorChanges.get(behaviorChanges.size() - 1);
47 public List<RaftActorBehavior> getBehaviorChanges(){
48 return behaviorChanges;
54 behaviorChanges.clear();