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 Summary
Modifier and TypeMethodDescriptionvoidaddToPeers(String peerId, @Nullable String address, VotingState votingState) Adds a new peer.booleanDetermines if there are any voting peers.Returns the consumer of ApplyState operations.@Nullable Clustercluster()The PekkoClustersingleton for the actor system if one is configured.default longReturn current term.@NonNull EntryStoreReturns theEntryStore.getActor()Returns the reference to the RaftActor.@NonNull ActorSystemReturns the The ActorSystem associated with this context.@NonNull ConfigParamsReturns the ConfigParams instance.Returns the current behavior attached to the RaftActor.@NonNull FileBackedOutputStreamFactoryReturns theFileBackedOutputStreamFactoryinstance with a common configuration.@NonNull StringgetId()Returns the identifier for the RaftActor.shortReturns the payload version to be used when replicating data.@Nullable ActorSelectiongetPeerActorSelection(String peerId) Returns an ActorSelection for a peer.@Nullable StringgetPeerAddress(String peerId) Gets the address of a peer as a String.Returns the id's for each peer.@Nullable PeerInfogetPeerInfo(String peerId) Returns the PeerInfo for the given peer.getPeers()Returns the PeerInfo instances for each peer.@Nullable VotingConfiggetPeerServerInfo(boolean includeSelf) Returns the peer information as a ClusterConfig if dynamic server configurations have been applied.@NonNull PersistenceProviderDeprecated, for removal: This API element is subject to removal in a future version.@Nullable RaftActorLeadershipTransferCohortReturns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.@NonNull RaftPolicyReturns the RaftPolicy used to determine certain Raft behaviors.@NonNull ReplicatedLogReturns the ReplicatedLog instance.@NonNull SnapshotManagerReturns the SnapshotManager instance.longReturns the total available memory for use in calculations.booleanDetermines if there are any peer followers.booleanDetermines if there have been any dynamic server configuration changes applied.booleanDetermines if this peer is a voting member of the cluster.@NonNull RestrictedObjectStreamsReturns theRestrictedObjectStreams.voidpersistTermInfo(@NonNull TermInfo termInfo) Sets and persists aTermInfo, so thattermInfo()returns it, even if we undergo recovery.voidremovePeer(String peerId) Removes a peer.voidSets that dynamic server configuration changes have been applied.voidsetPeerAddress(String peerId, String peerAddress) Sets the address of a peer.voidsetRaftActorLeadershipTransferCohort(@Nullable RaftActorLeadershipTransferCohort leadershipTransferCohort) Sets the RaftActorLeadershipTransferCohort for transferring leadership.voidsetTermInfo(@NonNull TermInfo termInfo) Sets, but does not persist, aTermInfo, so thattermInfo()returns it, unless we undergo recovery, in which case a priorTermInfomay be returned.voidsetTotalMemoryRetriever(LongSupplier retriever) Sets the retriever of the total memory metric.@NonNull SnapshotStoreReturns theSnapshotStore.@NonNull TermInfotermInfo()Returns the current termTermInfo.voidupdateVotingConfig(VotingConfig votingConfig) Updates the peers and information to match the givenVotingConfig.
-
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
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
-
cluster
@Nullable Cluster cluster()The PekkoClustersingleton 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 totermInfo().term().- Returns:
- current term
-
termInfo
@NonNull TermInfo termInfo()Returns the current termTermInfo.- Returns:
- the
TermInfo
-
setTermInfo
Sets, but does not persist, aTermInfo, so thattermInfo()returns it, unless we undergo recovery, in which case a priorTermInfomay be returned.- Parameters:
termInfo-TermInfoto set- Implementation Requirements:
- Implementations need to route this request to the underlying
TermInfoStore.setTerm(TermInfo).
-
persistTermInfo
Sets and persists aTermInfo, so thattermInfo()returns it, even if we undergo recovery.- Parameters:
termInfo-TermInfoto 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 ActorSystem getActorSystem()Returns the The ActorSystem associated with this context.- Returns:
- the ActorSystem.
-
getPeerAddress
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
Updates the peers and information to match the givenVotingConfig.- Parameters:
votingConfig- theVotingConfig
-
getPeers
Returns the PeerInfo instances for each peer.- Returns:
- list of PeerInfo
-
getPeerIds
Returns the id's for each peer.- Returns:
- the list of peer id's.
-
getPeerInfo
Returns the PeerInfo for the given peer.- Parameters:
peerId- the id of the peer- Returns:
- the PeerInfo or null if not found
-
addToPeers
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
Removes a peer.- Parameters:
peerId- the id of the peer to remove.
-
getPeerActorSelection
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
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, 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 theEntryStore.- Returns:
- the
EntryStore
-
snapshotStore
@NonNull SnapshotStore snapshotStore()Returns theSnapshotStore.- Returns:
- the
SnapshotStore
-
objectStreams
@NonNull RestrictedObjectStreams objectStreams()Returns theRestrictedObjectStreams.- Returns:
- the
RestrictedObjectStreams
-
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
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
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 theFileBackedOutputStreamFactoryinstance 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
-