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.cluster.raft.behaviors;
11 import akka.actor.ActorRef;
12 import javax.annotation.Nullable;
13 import org.opendaylight.controller.cluster.raft.RaftState;
16 * The interface for a class that implements a specific behavior of a RaftActor. The types of behaviors are enumerated
17 * by {@link RaftState}. Each handles the same Raft messages differently.
19 public interface RaftActorBehavior extends AutoCloseable {
22 * Handle a message. If the processing of the message warrants a state
23 * change then a new behavior should be returned otherwise this method should
24 * return the current behavior.
26 * @param sender The sender of the message
27 * @param message A message that needs to be processed
29 * @return The new behavior or current behavior, or null if the message was not handled.
32 RaftActorBehavior handleMessage(ActorRef sender, Object message);
35 * Returns the state associated with this behavior.
37 * @return the RaftState
42 * Returns the id of the leader.
44 * @return the id of the leader or null if not known
50 * Sets the index of the last log entry that has been replicated to all peers.
52 * @param replicatedToAllIndex the index
54 void setReplicatedToAllIndex(long replicatedToAllIndex);
57 * Returns the index of the last log entry that has been replicated to all peers.
59 * @return the index or -1 if not known
61 long getReplicatedToAllIndex();
64 * Returns the leader's payload data version.
66 * @return a short representing the version
68 short getLeaderPayloadVersion();
71 * Closes the current behavior and switches to the specified behavior, if possible.
73 * @param behavior the new behavior to switch to
74 * @return the new behavior
76 RaftActorBehavior switchBehavior(RaftActorBehavior behavior);