Interface RaftActorContext

All Known Implementing Classes:
RaftActorContextImpl

public interface RaftActorContext
The RaftActorContext contains that portion of the RaftActors state that needs to be shared with it's behaviors. A RaftActorContext should NEVER be used in any actor context outside the RaftActor that constructed it.
  • Method Details

    • getId

      @NonNull String getId()
      Returns the identifier for the RaftActor. This identifier represents the name of the actor whose common state is being shared.
      Returns:
      the identifier
    • getActor

      org.apache.pekko.actor.ActorRef getActor()
      Returns the reference to the RaftActor.
      Returns:
      the reference to the RaftActor itself. This can be used to send messages to the RaftActor
    • getExecutor

      @NonNull Executor getExecutor()
      Return an Executor which is guaranteed to run tasks in the context of getActor().
      Returns:
      An executor.
    • cluster

      @Nullable org.apache.pekko.cluster.Cluster cluster()
      The Pekko Cluster singleton for the actor system if one is configured.
      Returns:
      the Cluster instance, or null
    • currentTerm

      default long currentTerm()
      Return current term. This method is equivalent to termInfo().term().
      Returns:
      current term
    • termInfo

      @NonNull TermInfo termInfo()
      Returns the current term TermInfo.
      Returns:
      the TermInfo
    • setTermInfo

      void setTermInfo(@NonNull TermInfo termInfo)
      Sets, but does not persist, a TermInfo, so that termInfo() returns it, unless we undergo recovery, in which case a prior TermInfo may be returned.
      Parameters:
      termInfo - TermInfo to set
      Implementation Requirements:
      Implementations need to route this request to the underlying TermInfoStore.setTerm(TermInfo).
    • persistTermInfo

      void persistTermInfo(@NonNull TermInfo termInfo) throws IOException
      Sets and persists a TermInfo, so that termInfo() returns it, even if we undergo recovery.
      Parameters:
      termInfo - TermInfo to persist
      Throws:
      IOException - when an I/O error occurs
      Implementation Requirements:
      Implementations need to route this request to the underlying TermInfoStore.storeAndSetTerm(TermInfo).
    • getReplicatedLog

      @NonNull ReplicatedLog getReplicatedLog()
      Returns the ReplicatedLog instance.
      Returns:
      the ReplicatedLog instance.
    • getActorSystem

      @NonNull org.apache.pekko.actor.ActorSystem getActorSystem()
      Returns the The ActorSystem associated with this context.
      Returns:
      the ActorSystem.
    • getPeerAddress

      @NonNullByDefault @Nullable String getPeerAddress(String peerId)
      Gets the address of a peer as a String. This is the same format in which a consumer would provide the address.
      Parameters:
      peerId - the id of the peer.
      Returns:
      the address of the peer or null if the address has not yet been resolved.
    • updateVotingConfig

      @NonNullByDefault void updateVotingConfig(VotingConfig votingConfig)
      Updates the peers and information to match the given VotingConfig.
      Parameters:
      votingConfig - the VotingConfig
    • getPeers

      @NonNullByDefault Collection<PeerInfo> getPeers()
      Returns the PeerInfo instances for each peer.
      Returns:
      list of PeerInfo
    • getPeerIds

      @NonNullByDefault Collection<String> getPeerIds()
      Returns the id's for each peer.
      Returns:
      the list of peer id's.
    • getPeerInfo

      @NonNullByDefault @Nullable PeerInfo getPeerInfo(String peerId)
      Returns the PeerInfo for the given peer.
      Parameters:
      peerId - the id of the peer
      Returns:
      the PeerInfo or null if not found
    • addToPeers

      @NonNullByDefault void addToPeers(String peerId, @Nullable String address, VotingState votingState)
      Adds a new peer.
      Parameters:
      peerId - the id of the new peer.
      address - the address of the new peer.
      votingState - the VotingState of the new peer.
    • removePeer

      @NonNullByDefault void removePeer(String peerId)
      Removes a peer.
      Parameters:
      peerId - the id of the peer to remove.
    • getPeerActorSelection

      @Nullable org.apache.pekko.actor.ActorSelection getPeerActorSelection(String peerId)
      Returns an ActorSelection for a peer.
      Parameters:
      peerId - the id of the peer.
      Returns:
      the actorSelection corresponding to the peer or null if the address has not yet been resolved.
    • setPeerAddress

      void setPeerAddress(String peerId, String peerAddress)
      Sets the address of a peer.
      Parameters:
      peerId - the id of the peer.
      peerAddress - the address of the peer.
    • getConfigParams

      @NonNull ConfigParams getConfigParams()
      Returns the ConfigParams instance.
      Returns:
      the ConfigParams instance.
    • getSnapshotManager

      @NonNull SnapshotManager getSnapshotManager()
      Returns the SnapshotManager instance.
      Returns:
      the SnapshotManager instance.
    • getPersistenceProvider

      @Deprecated(since="11.0.0", forRemoval=true) @NonNull PersistenceProvider getPersistenceProvider()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the DataPersistenceProvider instance.
      Returns:
      the DataPersistenceProvider instance.
    • entryStore

      @NonNull EntryStore entryStore()
      Returns the EntryStore.
      Returns:
      the EntryStore
    • snapshotStore

      @NonNull SnapshotStore snapshotStore()
      Returns the SnapshotStore.
      Returns:
      the SnapshotStore
    • hasFollowers

      boolean hasFollowers()
      Determines if there are any peer followers.
      Returns:
      true if there are followers otherwise false.
    • getTotalMemory

      long getTotalMemory()
      Returns the total available memory for use in calculations. Normally this returns JVM's max memory but can be overridden for unit tests.
      Returns:
      the total memory.
    • setTotalMemoryRetriever

      void setTotalMemoryRetriever(LongSupplier retriever)
      Sets the retriever of the total memory metric.
      Parameters:
      retriever - a supplier of the total memory metric.
    • getPayloadVersion

      short getPayloadVersion()
      Returns the payload version to be used when replicating data.
      Returns:
      the payload version.
    • getRaftPolicy

      @NonNull RaftPolicy getRaftPolicy()
      Returns the RaftPolicy used to determine certain Raft behaviors.
      Returns:
      the RaftPolicy instance.
    • isDynamicServerConfigurationInUse

      boolean isDynamicServerConfigurationInUse()
      Determines if there have been any dynamic server configuration changes applied.
      Returns:
      true if dynamic server configuration changes have been applied, false otherwise, meaning that static peer configuration is still in use.
    • setDynamicServerConfigurationInUse

      void setDynamicServerConfigurationInUse()
      Sets that dynamic server configuration changes have been applied.
    • getPeerServerInfo

      @Nullable VotingConfig getPeerServerInfo(boolean includeSelf)
      Returns the peer information as a ClusterConfig if dynamic server configurations have been applied.
      Parameters:
      includeSelf - include this peer's info.
      Returns:
      the peer information as a ClusterConfig or null if no dynamic server configurations have been applied.
    • isVotingMember

      boolean isVotingMember()
      Determines if this peer is a voting member of the cluster.
      Returns:
      true if this peer is a voting member, false otherwise.
    • anyVotingPeers

      boolean anyVotingPeers()
      Determines if there are any voting peers.
      Returns:
      true if there are any voting peers, false otherwise.
    • getCurrentBehavior

      RaftActorBehavior getCurrentBehavior()
      Returns the current behavior attached to the RaftActor.
      Returns:
      current behavior.
    • applyEntryMethod

      ApplyEntryMethod applyEntryMethod()
      Returns the consumer of ApplyState operations. This is invoked by a behavior when a log entry needs to be applied to the state.
      Returns:
      the ApplyEntryMethod
    • getFileBackedOutputStreamFactory

      @NonNull FileBackedOutputStreamFactory getFileBackedOutputStreamFactory()
      Returns the FileBackedOutputStreamFactory instance with a common configuration.
      Returns:
      the FileBackedOutputStreamFactory
    • getRaftActorLeadershipTransferCohort

      @Nullable RaftActorLeadershipTransferCohort getRaftActorLeadershipTransferCohort()
      Returns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.
      Returns:
      the RaftActorLeadershipTransferCohort if leadership transfer is in progress, null otherwise
    • setRaftActorLeadershipTransferCohort

      void setRaftActorLeadershipTransferCohort(@Nullable RaftActorLeadershipTransferCohort leadershipTransferCohort)
      Sets the RaftActorLeadershipTransferCohort for transferring leadership.
      Parameters:
      leadershipTransferCohort - the RaftActorLeadershipTransferCohort or null to clear the existing one