Class RaftActorContextImpl
java.lang.Object
org.opendaylight.controller.cluster.raft.RaftActorContextImpl
- All Implemented Interfaces:
RaftActorContext
Implementation of the RaftActorContext interface.
- Author:
- Moiz Raja, Thomas Pantelis
-
Constructor Summary
ConstructorsConstructorDescriptionRaftActorContextImpl(ActorRef actor, ActorContext context, String id, @NonNull ElectionTerm termInformation, long commitIndex, long lastApplied, @NonNull Map<String, String> peerAddresses, @NonNull ConfigParams configParams, @NonNull DataPersistenceProvider persistenceProvider, @NonNull Consumer<ApplyState> applyStateConsumer, @NonNull Logger logger, @NonNull Executor executor) -
Method Summary
Modifier and TypeMethodDescriptionCreates a new local actor.actorSelection(String path) Creates an actor selection.voidaddToPeers(String peerId, String address, VotingState votingState) Adds a new peer.booleanDetermines if there are any voting peers.getActor()Returns the reference to the RaftActor.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.longReturns the index of highest log entry known to be committed.Returns the ConfigParams instance.Returns the current behavior attached to the RaftActor.final ExecutorReturn an Executor which is guaranteed to run tasks in the context ofRaftActorContext.getActor().Returns theFileBackedOutputStreamFactoryinstance with a common configuration.getId()Returns the identifier for the RaftActor.longReturns index of highest log entry applied to state machine.Returns the logger to be used for logging messages.shortReturns the payload version to be used when replicating data.getPeerActorSelection(String peerId) Returns an ActorSelection for a peer.getPeerAddress(String peerId) Gets the address of a peer as a String.Returns the id's for each peer.getPeerInfo(String peerId) Returns the PeerInfo for the given peer.getPeers()Returns the PeerInfo instances for each peer.getPeerServerInfo(boolean includeSelf) Returns the peer information as a ServerConfigurationPayload if dynamic server configurations have been applied.Returns the DataPersistenceProvider instance.Returns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.Returns the RaftPolicy used to determine certain Raft behaviors.Returns the ReplicatedLog instance.Returns the SnapshotManager instance.Returns the current ElectionTerm information.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.voidremovePeer(String name) Removes a peer.voidsetCommitIndex(long commitIndex) Sets the index of highest log entry known to be committed.voidsetConfigParams(ConfigParams configParams) voidSets that dynamic server configuration changes have been applied.voidsetLastApplied(long lastApplied) Sets index of highest log entry applied to state machine.voidsetPayloadVersion(short payloadVersion) voidsetPeerAddress(String peerId, String peerAddress) Sets the address of a peer.voidsetRaftActorLeadershipTransferCohort(RaftActorLeadershipTransferCohort leadershipTransferCohort) Sets the RaftActorLeadershipTransferCohort for transferring leadership.voidsetReplicatedLog(ReplicatedLog replicatedLog) Sets the ReplicatedLog instance.voidsetTotalMemoryRetriever(LongSupplier retriever) Sets the retriever of the total memory metric.voidupdatePeerIds(ServerConfigurationPayload serverConfig) Updates the peers and information to match the given ServerConfigurationPayload.
-
Constructor Details
-
RaftActorContextImpl
public RaftActorContextImpl(ActorRef actor, ActorContext context, String id, @NonNull ElectionTerm termInformation, long commitIndex, long lastApplied, @NonNull Map<String, String> peerAddresses, @NonNull ConfigParams configParams, @NonNull DataPersistenceProvider persistenceProvider, @NonNull Consumer<ApplyState> applyStateConsumer, @NonNull Logger logger, @NonNull Executor executor)
-
-
Method Details
-
setPayloadVersion
public void setPayloadVersion(short payloadVersion) -
getPayloadVersion
public short getPayloadVersion()Description copied from interface:RaftActorContextReturns the payload version to be used when replicating data.- Specified by:
getPayloadVersionin interfaceRaftActorContext- Returns:
- the payload version.
-
setConfigParams
-
actorOf
Description copied from interface:RaftActorContextCreates a new local actor.- Specified by:
actorOfin interfaceRaftActorContext- Parameters:
props- the Props used to create the actor.- Returns:
- a reference to the newly created actor.
-
actorSelection
Description copied from interface:RaftActorContextCreates an actor selection.- Specified by:
actorSelectionin interfaceRaftActorContext- Parameters:
path- the path.- Returns:
- an actor selection for the given actor path.
-
getId
Description copied from interface:RaftActorContextReturns the identifier for the RaftActor. This identifier represents the name of the actor whose common state is being shared.- Specified by:
getIdin interfaceRaftActorContext- Returns:
- the identifier
-
getActor
Description copied from interface:RaftActorContextReturns the reference to the RaftActor.- Specified by:
getActorin interfaceRaftActorContext- Returns:
- the reference to the RaftActor itself. This can be used to send messages to the RaftActor
-
getExecutor
Description copied from interface:RaftActorContextReturn an Executor which is guaranteed to run tasks in the context ofRaftActorContext.getActor().- Specified by:
getExecutorin interfaceRaftActorContext- Returns:
- An executor.
-
getCluster
Description copied from interface:RaftActorContextThe akka Cluster singleton for the actor system if one is configured.- Specified by:
getClusterin interfaceRaftActorContext- Returns:
- an Optional containing the Cluster instance is present.
-
getTermInformation
Description copied from interface:RaftActorContextReturns the current ElectionTerm information.- Specified by:
getTermInformationin interfaceRaftActorContext- Returns:
- the ElectionTerm.
-
getCommitIndex
public long getCommitIndex()Description copied from interface:RaftActorContextReturns the index of highest log entry known to be committed.- Specified by:
getCommitIndexin interfaceRaftActorContext- Returns:
- index of highest log entry known to be committed.
-
setCommitIndex
public void setCommitIndex(long commitIndex) Description copied from interface:RaftActorContextSets the index of highest log entry known to be committed.- Specified by:
setCommitIndexin interfaceRaftActorContext- Parameters:
commitIndex- new commit index
-
getLastApplied
public long getLastApplied()Description copied from interface:RaftActorContextReturns index of highest log entry applied to state machine.- Specified by:
getLastAppliedin interfaceRaftActorContext- Returns:
- index of highest log entry applied to state machine.
-
setLastApplied
public void setLastApplied(long lastApplied) Description copied from interface:RaftActorContextSets index of highest log entry applied to state machine.- Specified by:
setLastAppliedin interfaceRaftActorContext- Parameters:
lastApplied- the new applied index.
-
setReplicatedLog
Description copied from interface:RaftActorContextSets the ReplicatedLog instance.- Specified by:
setReplicatedLogin interfaceRaftActorContext- Parameters:
replicatedLog- the ReplicatedLog instance.
-
getReplicatedLog
Description copied from interface:RaftActorContextReturns the ReplicatedLog instance.- Specified by:
getReplicatedLogin interfaceRaftActorContext- Returns:
- the ReplicatedLog instance.
-
getActorSystem
Description copied from interface:RaftActorContextReturns the The ActorSystem associated with this context.- Specified by:
getActorSystemin interfaceRaftActorContext- Returns:
- the ActorSystem.
-
getLogger
Description copied from interface:RaftActorContextReturns the logger to be used for logging messages.- Specified by:
getLoggerin interfaceRaftActorContext- Returns:
- the logger.
-
getPeerIds
Description copied from interface:RaftActorContextReturns the id's for each peer.- Specified by:
getPeerIdsin interfaceRaftActorContext- Returns:
- the list of peer id's.
-
getPeers
Description copied from interface:RaftActorContextReturns the PeerInfo instances for each peer.- Specified by:
getPeersin interfaceRaftActorContext- Returns:
- list of PeerInfo
-
getPeerInfo
Description copied from interface:RaftActorContextReturns the PeerInfo for the given peer.- Specified by:
getPeerInfoin interfaceRaftActorContext- Parameters:
peerId- the id of the peer- Returns:
- the PeerInfo or null if not found
-
getPeerAddress
Description copied from interface:RaftActorContextGets the address of a peer as a String. This is the same format in which a consumer would provide the address.- Specified by:
getPeerAddressin interfaceRaftActorContext- Parameters:
peerId- the id of the peer.- Returns:
- the address of the peer or null if the address has not yet been resolved.
-
updatePeerIds
Description copied from interface:RaftActorContextUpdates the peers and information to match the given ServerConfigurationPayload.- Specified by:
updatePeerIdsin interfaceRaftActorContext- Parameters:
serverConfig- the ServerConfigurationPayload.
-
getConfigParams
Description copied from interface:RaftActorContextReturns the ConfigParams instance.- Specified by:
getConfigParamsin interfaceRaftActorContext- Returns:
- the ConfigParams instance.
-
addToPeers
Description copied from interface:RaftActorContextAdds a new peer.- Specified by:
addToPeersin interfaceRaftActorContext- Parameters:
peerId- the id of the new peer.address- the address of the new peer.votingState- the VotingState of the new peer.
-
removePeer
Description copied from interface:RaftActorContextRemoves a peer.- Specified by:
removePeerin interfaceRaftActorContext- Parameters:
name- the id of the peer to remove.
-
getPeerActorSelection
Description copied from interface:RaftActorContextReturns an ActorSelection for a peer.- Specified by:
getPeerActorSelectionin interfaceRaftActorContext- 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
Description copied from interface:RaftActorContextSets the address of a peer.- Specified by:
setPeerAddressin interfaceRaftActorContext- Parameters:
peerId- the id of the peer.peerAddress- the address of the peer.
-
getSnapshotManager
Description copied from interface:RaftActorContextReturns the SnapshotManager instance.- Specified by:
getSnapshotManagerin interfaceRaftActorContext- Returns:
- the SnapshotManager instance.
-
getTotalMemory
public long getTotalMemory()Description copied from interface:RaftActorContextReturns the total available memory for use in calculations. Normally this returns JVM's max memory but can be overridden for unit tests.- Specified by:
getTotalMemoryin interfaceRaftActorContext- Returns:
- the total memory.
-
setTotalMemoryRetriever
Description copied from interface:RaftActorContextSets the retriever of the total memory metric.- Specified by:
setTotalMemoryRetrieverin interfaceRaftActorContext- Parameters:
retriever- a supplier of the total memory metric.
-
hasFollowers
public boolean hasFollowers()Description copied from interface:RaftActorContextDetermines if there are any peer followers.- Specified by:
hasFollowersin interfaceRaftActorContext- Returns:
- true if there are followers otherwise false.
-
getPersistenceProvider
Description copied from interface:RaftActorContextReturns the DataPersistenceProvider instance.- Specified by:
getPersistenceProviderin interfaceRaftActorContext- Returns:
- the DataPersistenceProvider instance.
-
getRaftPolicy
Description copied from interface:RaftActorContextReturns the RaftPolicy used to determine certain Raft behaviors.- Specified by:
getRaftPolicyin interfaceRaftActorContext- Returns:
- the RaftPolicy instance.
-
isDynamicServerConfigurationInUse
public boolean isDynamicServerConfigurationInUse()Description copied from interface:RaftActorContextDetermines if there have been any dynamic server configuration changes applied.- Specified by:
isDynamicServerConfigurationInUsein interfaceRaftActorContext- Returns:
- true if dynamic server configuration changes have been applied, false otherwise, meaning that static peer configuration is still in use.
-
setDynamicServerConfigurationInUse
public void setDynamicServerConfigurationInUse()Description copied from interface:RaftActorContextSets that dynamic server configuration changes have been applied.- Specified by:
setDynamicServerConfigurationInUsein interfaceRaftActorContext
-
getPeerServerInfo
Description copied from interface:RaftActorContextReturns the peer information as a ServerConfigurationPayload if dynamic server configurations have been applied.- Specified by:
getPeerServerInfoin interfaceRaftActorContext- 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
public boolean isVotingMember()Description copied from interface:RaftActorContextDetermines if this peer is a voting member of the cluster.- Specified by:
isVotingMemberin interfaceRaftActorContext- Returns:
- true if this peer is a voting member, false otherwise.
-
anyVotingPeers
public boolean anyVotingPeers()Description copied from interface:RaftActorContextDetermines if there are any voting peers.- Specified by:
anyVotingPeersin interfaceRaftActorContext- Returns:
- true if there are any voting peers, false otherwise.
-
getCurrentBehavior
Description copied from interface:RaftActorContextReturns the current behavior attached to the RaftActor.- Specified by:
getCurrentBehaviorin interfaceRaftActorContext- Returns:
- current behavior.
-
getApplyStateConsumer
Description copied from interface:RaftActorContextReturns the consumer of ApplyState operations. This is invoked by a behavior when a log entry needs to be applied to the state.- Specified by:
getApplyStateConsumerin interfaceRaftActorContext- Returns:
- the Consumer
-
getFileBackedOutputStreamFactory
Description copied from interface:RaftActorContextReturns theFileBackedOutputStreamFactoryinstance with a common configuration.- Specified by:
getFileBackedOutputStreamFactoryin interfaceRaftActorContext- Returns:
- the
FileBackedOutputStreamFactory;
-
getRaftActorLeadershipTransferCohort
Description copied from interface:RaftActorContextReturns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.- Specified by:
getRaftActorLeadershipTransferCohortin interfaceRaftActorContext- Returns:
- the RaftActorLeadershipTransferCohort if leadership transfer is in progress, null otherwise
-
setRaftActorLeadershipTransferCohort
public void setRaftActorLeadershipTransferCohort(RaftActorLeadershipTransferCohort leadershipTransferCohort) Description copied from interface:RaftActorContextSets the RaftActorLeadershipTransferCohort for transferring leadership.- Specified by:
setRaftActorLeadershipTransferCohortin interfaceRaftActorContext- Parameters:
leadershipTransferCohort- the RaftActorLeadershipTransferCohort or null to clear the existing one
-