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
(org.apache.pekko.actor.ActorRef actor, org.apache.pekko.actor.ActorContext context, @NonNull LocalAccess localStore, @NonNull Map<String, String> peerAddresses, @NonNull ConfigParams configParams, short payloadVersion, @NonNull PersistenceProvider persistenceProvider, @NonNull ApplyEntryMethod applyEntryMethod, @NonNull Executor executor) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToPeers
(String peerId, String address, VotingState votingState) Adds a new peer.boolean
Determines if there are any voting peers.Returns the consumer of ApplyState operations.final org.apache.pekko.cluster.Cluster
cluster()
The PekkoCluster
singleton for the actor system if one is configured.Returns theEntryStore
.org.apache.pekko.actor.ActorRef
getActor()
Returns the reference to the RaftActor.org.apache.pekko.actor.ActorSystem
Returns the The ActorSystem associated with this context.Returns the ConfigParams instance.Returns the current behavior attached to the RaftActor.final Executor
Return an Executor which is guaranteed to run tasks in the context ofRaftActorContext.getActor()
.Returns theFileBackedOutputStreamFactory
instance with a common configuration.getId()
Returns the identifier for the RaftActor.short
Returns the payload version to be used when replicating data.final org.apache.pekko.actor.ActorSelection
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 ClusterConfig if dynamic server configurations have been applied.Deprecated, for removal: This API element is subject to removal in a future version.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.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
persistTermInfo
(TermInfo newElectionInfo) Sets and persists aTermInfo
, so thatRaftActorContext.termInfo()
returns it, even if we undergo recovery.void
removePeer
(String name) Removes a peer.final void
resetReplicatedLog
(@NonNull ReplicatedLog newState) Deprecated, for removal: This API element is subject to removal in a future version.void
setConfigParams
(ConfigParams configParams) void
Sets that dynamic server configuration changes have been applied.void
setPeerAddress
(String peerId, String peerAddress) Sets the address of a peer.void
setRaftActorLeadershipTransferCohort
(RaftActorLeadershipTransferCohort leadershipTransferCohort) Sets the RaftActorLeadershipTransferCohort for transferring leadership.void
setTermInfo
(TermInfo newElectionInfo) Sets, but does not persist, aTermInfo
, so thatRaftActorContext.termInfo()
returns it, unless we undergo recovery, in which case a priorTermInfo
may be returned.void
setTotalMemoryRetriever
(LongSupplier retriever) Sets the retriever of the total memory metric.Returns theSnapshotStore
.termInfo()
Returns the current termTermInfo
.void
updateVotingConfig
(VotingConfig votingConfig) Updates the peers and information to match the givenVotingConfig
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opendaylight.controller.cluster.raft.RaftActorContext
currentTerm
-
Constructor Details
-
RaftActorContextImpl
public RaftActorContextImpl(org.apache.pekko.actor.ActorRef actor, org.apache.pekko.actor.ActorContext context, @NonNull LocalAccess localStore, @NonNull Map<String, String> peerAddresses, @NonNull ConfigParams configParams, short payloadVersion, @NonNull PersistenceProvider persistenceProvider, @NonNull ApplyEntryMethod applyEntryMethod, @NonNull Executor executor)
-
-
Method Details
-
getPayloadVersion
public short getPayloadVersion()Description copied from interface:RaftActorContext
Returns the payload version to be used when replicating data.- Specified by:
getPayloadVersion
in interfaceRaftActorContext
- Returns:
- the payload version.
-
setConfigParams
-
getId
Description copied from interface:RaftActorContext
Returns the identifier for the RaftActor. This identifier represents the name of the actor whose common state is being shared.- Specified by:
getId
in interfaceRaftActorContext
- Returns:
- the identifier
-
getActor
public org.apache.pekko.actor.ActorRef getActor()Description copied from interface:RaftActorContext
Returns the reference to the RaftActor.- Specified by:
getActor
in interfaceRaftActorContext
- Returns:
- the reference to the RaftActor itself. This can be used to send messages to the RaftActor
-
getExecutor
Description copied from interface:RaftActorContext
Return an Executor which is guaranteed to run tasks in the context ofRaftActorContext.getActor()
.- Specified by:
getExecutor
in interfaceRaftActorContext
- Returns:
- An executor.
-
cluster
public final org.apache.pekko.cluster.Cluster cluster()Description copied from interface:RaftActorContext
The PekkoCluster
singleton for the actor system if one is configured.- Specified by:
cluster
in interfaceRaftActorContext
- Returns:
- the Cluster instance, or
null
-
termInfo
Description copied from interface:RaftActorContext
Returns the current termTermInfo
.- Specified by:
termInfo
in interfaceRaftActorContext
- Returns:
- the
TermInfo
-
setTermInfo
Description copied from interface:RaftActorContext
Sets, but does not persist, aTermInfo
, so thatRaftActorContext.termInfo()
returns it, unless we undergo recovery, in which case a priorTermInfo
may be returned.- Specified by:
setTermInfo
in interfaceRaftActorContext
- Parameters:
newElectionInfo
-TermInfo
to set
-
persistTermInfo
Description copied from interface:RaftActorContext
Sets and persists aTermInfo
, so thatRaftActorContext.termInfo()
returns it, even if we undergo recovery.- Specified by:
persistTermInfo
in interfaceRaftActorContext
- Parameters:
newElectionInfo
-TermInfo
to persist- Throws:
IOException
- when an I/O error occurs
-
resetReplicatedLog
Deprecated, for removal: This API element is subject to removal in a future version. -
getReplicatedLog
Description copied from interface:RaftActorContext
Returns the ReplicatedLog instance.- Specified by:
getReplicatedLog
in interfaceRaftActorContext
- Returns:
- the ReplicatedLog instance.
-
getActorSystem
public org.apache.pekko.actor.ActorSystem getActorSystem()Description copied from interface:RaftActorContext
Returns the The ActorSystem associated with this context.- Specified by:
getActorSystem
in interfaceRaftActorContext
- Returns:
- the ActorSystem.
-
getPeerIds
Description copied from interface:RaftActorContext
Returns the id's for each peer.- Specified by:
getPeerIds
in interfaceRaftActorContext
- Returns:
- the list of peer id's.
-
getPeers
Description copied from interface:RaftActorContext
Returns the PeerInfo instances for each peer.- Specified by:
getPeers
in interfaceRaftActorContext
- Returns:
- list of PeerInfo
-
getPeerInfo
Description copied from interface:RaftActorContext
Returns the PeerInfo for the given peer.- Specified by:
getPeerInfo
in interfaceRaftActorContext
- Parameters:
peerId
- the id of the peer- Returns:
- the PeerInfo or null if not found
-
getPeerAddress
Description copied from interface:RaftActorContext
Gets the address of a peer as a String. This is the same format in which a consumer would provide the address.- Specified by:
getPeerAddress
in interfaceRaftActorContext
- Parameters:
peerId
- the id of the peer.- Returns:
- the address of the peer or null if the address has not yet been resolved.
-
updateVotingConfig
Description copied from interface:RaftActorContext
Updates the peers and information to match the givenVotingConfig
.- Specified by:
updateVotingConfig
in interfaceRaftActorContext
- Parameters:
votingConfig
- theVotingConfig
-
getConfigParams
Description copied from interface:RaftActorContext
Returns the ConfigParams instance.- Specified by:
getConfigParams
in interfaceRaftActorContext
- Returns:
- the ConfigParams instance.
-
addToPeers
Description copied from interface:RaftActorContext
Adds a new peer.- Specified by:
addToPeers
in 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:RaftActorContext
Removes a peer.- Specified by:
removePeer
in interfaceRaftActorContext
- Parameters:
name
- the id of the peer to remove.
-
getPeerActorSelection
Description copied from interface:RaftActorContext
Returns an ActorSelection for a peer.- Specified by:
getPeerActorSelection
in 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:RaftActorContext
Sets the address of a peer.- Specified by:
setPeerAddress
in interfaceRaftActorContext
- Parameters:
peerId
- the id of the peer.peerAddress
- the address of the peer.
-
getSnapshotManager
Description copied from interface:RaftActorContext
Returns the SnapshotManager instance.- Specified by:
getSnapshotManager
in interfaceRaftActorContext
- Returns:
- the SnapshotManager instance.
-
getTotalMemory
public long getTotalMemory()Description copied from interface:RaftActorContext
Returns the total available memory for use in calculations. Normally this returns JVM's max memory but can be overridden for unit tests.- Specified by:
getTotalMemory
in interfaceRaftActorContext
- Returns:
- the total memory.
-
setTotalMemoryRetriever
Description copied from interface:RaftActorContext
Sets the retriever of the total memory metric.- Specified by:
setTotalMemoryRetriever
in interfaceRaftActorContext
- Parameters:
retriever
- a supplier of the total memory metric.
-
hasFollowers
public boolean hasFollowers()Description copied from interface:RaftActorContext
Determines if there are any peer followers.- Specified by:
hasFollowers
in interfaceRaftActorContext
- Returns:
- true if there are followers otherwise false.
-
getPersistenceProvider
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RaftActorContext
Returns the DataPersistenceProvider instance.- Specified by:
getPersistenceProvider
in interfaceRaftActorContext
- Returns:
- the DataPersistenceProvider instance.
-
entryStore
Description copied from interface:RaftActorContext
Returns theEntryStore
.- Specified by:
entryStore
in interfaceRaftActorContext
- Returns:
- the
EntryStore
-
snapshotStore
Description copied from interface:RaftActorContext
Returns theSnapshotStore
.- Specified by:
snapshotStore
in interfaceRaftActorContext
- Returns:
- the
SnapshotStore
-
getRaftPolicy
Description copied from interface:RaftActorContext
Returns the RaftPolicy used to determine certain Raft behaviors.- Specified by:
getRaftPolicy
in interfaceRaftActorContext
- Returns:
- the RaftPolicy instance.
-
isDynamicServerConfigurationInUse
public boolean isDynamicServerConfigurationInUse()Description copied from interface:RaftActorContext
Determines if there have been any dynamic server configuration changes applied.- Specified by:
isDynamicServerConfigurationInUse
in 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:RaftActorContext
Sets that dynamic server configuration changes have been applied.- Specified by:
setDynamicServerConfigurationInUse
in interfaceRaftActorContext
-
getPeerServerInfo
Description copied from interface:RaftActorContext
Returns the peer information as a ClusterConfig if dynamic server configurations have been applied.- Specified by:
getPeerServerInfo
in interfaceRaftActorContext
- 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
public boolean isVotingMember()Description copied from interface:RaftActorContext
Determines if this peer is a voting member of the cluster.- Specified by:
isVotingMember
in interfaceRaftActorContext
- Returns:
- true if this peer is a voting member, false otherwise.
-
anyVotingPeers
public boolean anyVotingPeers()Description copied from interface:RaftActorContext
Determines if there are any voting peers.- Specified by:
anyVotingPeers
in interfaceRaftActorContext
- Returns:
- true if there are any voting peers, false otherwise.
-
getCurrentBehavior
Description copied from interface:RaftActorContext
Returns the current behavior attached to the RaftActor.- Specified by:
getCurrentBehavior
in interfaceRaftActorContext
- Returns:
- current behavior.
-
applyEntryMethod
Description copied from interface:RaftActorContext
Returns the consumer of ApplyState operations. This is invoked by a behavior when a log entry needs to be applied to the state.- Specified by:
applyEntryMethod
in interfaceRaftActorContext
- Returns:
- the
ApplyEntryMethod
-
getFileBackedOutputStreamFactory
Description copied from interface:RaftActorContext
Returns theFileBackedOutputStreamFactory
instance with a common configuration.- Specified by:
getFileBackedOutputStreamFactory
in interfaceRaftActorContext
- Returns:
- the
FileBackedOutputStreamFactory
-
getRaftActorLeadershipTransferCohort
Description copied from interface:RaftActorContext
Returns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.- Specified by:
getRaftActorLeadershipTransferCohort
in interfaceRaftActorContext
- Returns:
- the RaftActorLeadershipTransferCohort if leadership transfer is in progress, null otherwise
-
setRaftActorLeadershipTransferCohort
public void setRaftActorLeadershipTransferCohort(RaftActorLeadershipTransferCohort leadershipTransferCohort) Description copied from interface:RaftActorContext
Sets the RaftActorLeadershipTransferCohort for transferring leadership.- Specified by:
setRaftActorLeadershipTransferCohort
in interfaceRaftActorContext
- Parameters:
leadershipTransferCohort
- the RaftActorLeadershipTransferCohort or null to clear the existing one
-