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 TypeMethodDescriptionCreates a new local actor.actorSelection
(String path) Creates an actor selection.void
addToPeers
(String id, String address, VotingState votingState) Adds a new peer.boolean
Determines if there are any voting peers.getActor()
Returns the reference to the RaftActor.@NonNull ActorSystem
Returns the The ActorSystem associated with this context.Returns the consumer of ApplyState operations.The akka Cluster singleton for the actor system if one is configured.long
Returns the index of highest log entry known to be committed.@NonNull ConfigParams
Returns the ConfigParams instance.Returns the current behavior attached to the RaftActor.@NonNull Executor
Return an Executor which is guaranteed to run tasks in the context ofgetActor()
.@NonNull FileBackedOutputStreamFactory
Returns theFileBackedOutputStreamFactory
instance with a common configuration.getId()
Returns the identifier for the RaftActor.long
Returns index of highest log entry applied to state machine.@NonNull Logger
Returns the logger to be used for logging messages.short
Returns the payload version to be used when replicating data.@Nullable ActorSelection
getPeerActorSelection
(String peerId) Returns an ActorSelection for a peer.@Nullable String
getPeerAddress
(String peerId) Gets the address of a peer as a String.@NonNull Collection<String>
Returns the id's for each peer.@Nullable PeerInfo
getPeerInfo
(String peerId) Returns the PeerInfo for the given peer.@NonNull Collection<PeerInfo>
getPeers()
Returns the PeerInfo instances for each peer.@Nullable ServerConfigurationPayload
getPeerServerInfo
(boolean includeSelf) Returns the peer information as a ServerConfigurationPayload if dynamic server configurations have been applied.@NonNull DataPersistenceProvider
Returns the DataPersistenceProvider instance.@Nullable RaftActorLeadershipTransferCohort
Returns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.@NonNull RaftPolicy
Returns the RaftPolicy used to determine certain Raft behaviors.@NonNull ReplicatedLog
Returns the ReplicatedLog instance.@NonNull SnapshotManager
Returns the SnapshotManager instance.@NonNull ElectionTerm
Returns the current ElectionTerm information.long
Returns the total available memory for use in calculations.boolean
Determines if there are any peer followers.boolean
Determines if there have been any dynamic server configuration changes applied.boolean
Determines if this peer is a voting member of the cluster.void
removePeer
(String id) Removes a peer.void
setCommitIndex
(long commitIndex) Sets the index of highest log entry known to be committed.void
Sets that dynamic server configuration changes have been applied.void
setLastApplied
(long lastApplied) Sets index of highest log entry applied to state machine.void
setPeerAddress
(String peerId, String peerAddress) Sets the address of a peer.void
setRaftActorLeadershipTransferCohort
(@Nullable RaftActorLeadershipTransferCohort leadershipTransferCohort) Sets the RaftActorLeadershipTransferCohort for transferring leadership.void
setReplicatedLog
(@NonNull ReplicatedLog replicatedLog) Sets the ReplicatedLog instance.void
setTotalMemoryRetriever
(LongSupplier retriever) Sets the retriever of the total memory metric.void
updatePeerIds
(ServerConfigurationPayload serverCfgPayload) Updates the peers and information to match the given ServerConfigurationPayload.
-
Method Details
-
actorOf
Creates a new local actor.- Parameters:
props
- the Props used to create the actor.- Returns:
- a reference to the newly created actor.
-
actorSelection
Creates an actor selection.- Parameters:
path
- the path.- Returns:
- an actor selection for the given actor path.
-
getId
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
-
getExecutor
@NonNull Executor getExecutor()Return an Executor which is guaranteed to run tasks in the context ofgetActor()
.- Returns:
- An executor.
-
getCluster
The akka Cluster singleton for the actor system if one is configured.- Returns:
- an Optional containing the Cluster instance is present.
-
getTermInformation
@NonNull ElectionTerm getTermInformation()Returns the current ElectionTerm information.- Returns:
- the ElectionTerm.
-
getCommitIndex
long getCommitIndex()Returns the index of highest log entry known to be committed.- Returns:
- index of highest log entry known to be committed.
-
setCommitIndex
void setCommitIndex(long commitIndex) Sets the index of highest log entry known to be committed.- Parameters:
commitIndex
- new commit index
-
getLastApplied
long getLastApplied()Returns index of highest log entry applied to state machine.- Returns:
- index of highest log entry applied to state machine.
-
setLastApplied
void setLastApplied(long lastApplied) Sets index of highest log entry applied to state machine.- Parameters:
lastApplied
- the new applied index.
-
setReplicatedLog
Sets the ReplicatedLog instance.- Parameters:
replicatedLog
- the ReplicatedLog instance.
-
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.
-
getLogger
@NonNull Logger getLogger()Returns the logger to be used for logging messages.- Returns:
- the logger.
-
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.
-
updatePeerIds
Updates the peers and information to match the given ServerConfigurationPayload.- Parameters:
serverCfgPayload
- the ServerConfigurationPayload.
-
getPeers
@NonNull Collection<PeerInfo> getPeers()Returns the PeerInfo instances for each peer.- Returns:
- list of PeerInfo
-
getPeerIds
@NonNull Collection<String> 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:
id
- 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:
id
- 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
@NonNull DataPersistenceProvider getPersistenceProvider()Returns the DataPersistenceProvider instance.- Returns:
- the DataPersistenceProvider instance.
-
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 ServerConfigurationPayload if dynamic server configurations have been applied.- Parameters:
includeSelf
- include this peer's info.- Returns:
- the peer information as a ServerConfigurationPayload 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.
-
getApplyStateConsumer
Consumer<ApplyState> getApplyStateConsumer()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 Consumer
-
getFileBackedOutputStreamFactory
@NonNull FileBackedOutputStreamFactory getFileBackedOutputStreamFactory()Returns theFileBackedOutputStreamFactory
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
-