Interface RaftActorContext
-
- All Known Implementing Classes:
RaftActorContextImpl
public interface RaftActorContextThe 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ActorRefactorOf(Props props)Creates a new local actor.ActorSelectionactorSelection(String path)Creates an actor selection.voidaddToPeers(String id, String address, VotingState votingState)Adds a new peer.booleananyVotingPeers()Determines if there are any voting peers.ActorRefgetActor()Returns the reference to the RaftActor.@NonNull ActorSystemgetActorSystem()Returns the The ActorSystem associated with this context.Consumer<ApplyState>getApplyStateConsumer()Returns the consumer of ApplyState operations.Optional<Cluster>getCluster()The akka Cluster singleton for the actor system if one is configured.longgetCommitIndex()Returns the index of highest log entry known to be committed.@NonNull ConfigParamsgetConfigParams()Returns the ConfigParams instance.RaftActorBehaviorgetCurrentBehavior()Returns the current behavior attached to the RaftActor.@NonNull ExecutorgetExecutor()Return an Executor which is guaranteed to run tasks in the context ofgetActor().@NonNull FileBackedOutputStreamFactorygetFileBackedOutputStreamFactory()Returns theFileBackedOutputStreamFactoryinstance with a common configuration.StringgetId()Returns the identifier for the RaftActor.longgetLastApplied()Returns index of highest log entry applied to state machine.@NonNull LoggergetLogger()Returns the logger to be used for logging messages.shortgetPayloadVersion()Returns 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.@NonNull Collection<String>getPeerIds()Returns the id's for each peer.@Nullable PeerInfogetPeerInfo(String peerId)Returns the PeerInfo for the given peer.@NonNull Collection<PeerInfo>getPeers()Returns the PeerInfo instances for each peer.@Nullable ServerConfigurationPayloadgetPeerServerInfo(boolean includeSelf)Returns the peer information as a ServerConfigurationPayload if dynamic server configurations have been applied.@NonNull DataPersistenceProvidergetPersistenceProvider()Returns the DataPersistenceProvider instance.@Nullable RaftActorLeadershipTransferCohortgetRaftActorLeadershipTransferCohort()Returns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.@NonNull RaftPolicygetRaftPolicy()Returns the RaftPolicy used to determine certain Raft behaviors.@NonNull ReplicatedLoggetReplicatedLog()Returns the ReplicatedLog instance.@NonNull SnapshotManagergetSnapshotManager()Returns the SnapshotManager instance.@NonNull ElectionTermgetTermInformation()Returns the current ElectionTerm information.longgetTotalMemory()Returns the total available memory for use in calculations.booleanhasFollowers()Determines if there are any peer followers.booleanisDynamicServerConfigurationInUse()Determines if there have been any dynamic server configuration changes applied.booleanisVotingMember()Determines if this peer is a voting member of the cluster.voidremovePeer(String id)Removes a peer.voidsetCommitIndex(long commitIndex)Sets the index of highest log entry known to be committed.voidsetDynamicServerConfigurationInUse()Sets that dynamic server configuration changes have been applied.voidsetLastApplied(long lastApplied)Sets index of highest log entry applied to state machine.voidsetPeerAddress(String peerId, String peerAddress)Sets the address of a peer.voidsetRaftActorLeadershipTransferCohort(@Nullable RaftActorLeadershipTransferCohort leadershipTransferCohort)Sets the RaftActorLeadershipTransferCohort for transferring leadership.voidsetReplicatedLog(@NonNull ReplicatedLog replicatedLog)Sets the ReplicatedLog instance.voidsetTotalMemoryRetriever(LongSupplier retriever)Sets the retriever of the total memory metric.voidupdatePeerIds(ServerConfigurationPayload serverCfgPayload)Updates the peers and information to match the given ServerConfigurationPayload.
-
-
-
Method Detail
-
actorOf
ActorRef actorOf(Props props)
Creates a new local actor.- Parameters:
props- the Props used to create the actor.- Returns:
- a reference to the newly created actor.
-
actorSelection
ActorSelection actorSelection(String path)
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
Optional<Cluster> 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
void setReplicatedLog(@NonNull ReplicatedLog replicatedLog)
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
@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.
-
updatePeerIds
void updatePeerIds(ServerConfigurationPayload serverCfgPayload)
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
@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
void addToPeers(String id, String address, VotingState votingState)
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
void removePeer(String id)
Removes a peer.- Parameters:
id- the id of the peer to remove.
-
getPeerActorSelection
@Nullable 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
@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
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 ServerConfigurationPayload getPeerServerInfo(boolean includeSelf)
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 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
-
-