* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.raft;
import akka.actor.ActorRef;
import com.google.common.annotations.VisibleForTesting;
import java.util.Collection;
import java.util.Optional;
+import java.util.concurrent.Executor;
+import java.util.function.Consumer;
import java.util.function.LongSupplier;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.cluster.DataPersistenceProvider;
+import org.opendaylight.controller.cluster.io.FileBackedOutputStreamFactory;
+import org.opendaylight.controller.cluster.raft.base.messages.ApplyState;
import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
/**
* Returns the reference to the RaftActor.
*
- * @return A reference to the RaftActor itself. This could be used to send messages
- * to the RaftActor
+ * @return the reference to the RaftActor itself. This can be used to send messages to the RaftActor
*/
ActorRef getActor();
+ /**
+ * Return an Executor which is guaranteed to run tasks in the context of {@link #getActor()}.
+ *
+ * @return An executor.
+ */
+ @NonNull Executor getExecutor();
+
/**
* The akka Cluster singleton for the actor system if one is configured.
*
*
* @return the ElectionTerm.
*/
- @Nonnull
- ElectionTerm getTermInformation();
+ @NonNull ElectionTerm getTermInformation();
/**
* Returns the index of highest log entry known to be committed.
*
* @param replicatedLog the ReplicatedLog instance.
*/
- void setReplicatedLog(@Nonnull ReplicatedLog replicatedLog);
+ void setReplicatedLog(@NonNull ReplicatedLog replicatedLog);
/**
* Returns the ReplicatedLog instance.
*
* @return the ReplicatedLog instance.
*/
- @Nonnull
- ReplicatedLog getReplicatedLog();
+ @NonNull ReplicatedLog getReplicatedLog();
/**
* Returns the The ActorSystem associated with this context.
*
* @return the ActorSystem.
*/
- @Nonnull
- ActorSystem getActorSystem();
+ @NonNull ActorSystem getActorSystem();
/**
* Returns the logger to be used for logging messages.
*
* @return the logger.
*/
- @Nonnull
- Logger getLogger();
+ @NonNull Logger getLogger();
/**
* Gets the address of a peer as a String. This is the same format in which a consumer would provide the address.
* @param peerId the id of the peer.
* @return the address of the peer or null if the address has not yet been resolved.
*/
- @Nullable
- String getPeerAddress(String peerId);
+ @Nullable String getPeerAddress(String peerId);
/**
* Updates the peers and information to match the given ServerConfigurationPayload.
*
* @return list of PeerInfo
*/
- @Nonnull
- Collection<PeerInfo> getPeers();
+ @NonNull Collection<PeerInfo> getPeers();
/**
* Returns the id's for each peer.
*
* @return the list of peer id's.
*/
- @Nonnull
- Collection<String> getPeerIds();
+ @NonNull Collection<String> getPeerIds();
/**
* Returns the PeerInfo for the given peer.
*
- * @param peerId
- * @return the PeerInfo or null if not found.
+ * @param peerId the id of the peer
+ * @return the PeerInfo or null if not found
*/
- @Nullable
- PeerInfo getPeerInfo(String peerId);
+ @Nullable PeerInfo getPeerInfo(String peerId);
/**
* Adds a new peer.
* @param peerId the id of the peer.
* @return the actorSelection corresponding to the peer or null if the address has not yet been resolved.
*/
- @Nullable
- ActorSelection getPeerActorSelection(String peerId);
+ @Nullable ActorSelection getPeerActorSelection(String peerId);
/**
* Sets the address of a peer.
*
* @return the ConfigParams instance.
*/
- @Nonnull
- ConfigParams getConfigParams();
+ @NonNull ConfigParams getConfigParams();
/**
* Returns the SnapshotManager instance.
*
* @return the SnapshotManager instance.
*/
- @Nonnull
- SnapshotManager getSnapshotManager();
+ @NonNull SnapshotManager getSnapshotManager();
/**
* Returns the DataPersistenceProvider instance.
*
* @return the DataPersistenceProvider instance.
*/
- @Nonnull
- DataPersistenceProvider getPersistenceProvider();
+ @NonNull DataPersistenceProvider getPersistenceProvider();
/**
* Determines if there are any peer followers.
*
* @return the RaftPolicy instance.
*/
- @Nonnull
- RaftPolicy getRaftPolicy();
+ @NonNull RaftPolicy getRaftPolicy();
/**
* Determines if there have been any dynamic server configuration changes applied.
* @return the peer information as a ServerConfigurationPayload or null if no dynamic server configurations have
* been applied.
*/
- @Nullable
- ServerConfigurationPayload getPeerServerInfo(boolean includeSelf);
+ @Nullable ServerConfigurationPayload getPeerServerInfo(boolean includeSelf);
/**
* Determines if this peer is a voting member of the cluster.
* @return current behavior.
*/
RaftActorBehavior getCurrentBehavior();
+
+ /**
+ * Returns the consumer of ApplyState operations. This is invoked by a behavior when a log entry needs to be
+ * applied to the state.
+ *
+ * @return the Consumer
+ */
+ Consumer<ApplyState> getApplyStateConsumer();
+
+ /**
+ * Returns the {@link FileBackedOutputStreamFactory} instance with a common configuration.
+ *
+ * @return the {@link FileBackedOutputStreamFactory};
+ */
+ @NonNull FileBackedOutputStreamFactory getFileBackedOutputStreamFactory();
+
+ /**
+ * Returns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.
+ *
+ * @return the RaftActorLeadershipTransferCohort if leadership transfer is in progress, null otherwise
+ */
+ @Nullable RaftActorLeadershipTransferCohort getRaftActorLeadershipTransferCohort();
+
+ /**
+ * Sets the RaftActorLeadershipTransferCohort for transferring leadership.
+ *
+ * @param leadershipTransferCohort the RaftActorLeadershipTransferCohort or null to clear the existing one
+ */
+ void setRaftActorLeadershipTransferCohort(@Nullable RaftActorLeadershipTransferCohort leadershipTransferCohort);
}