Class RaftActorContextImpl
- java.lang.Object
-
- org.opendaylight.controller.cluster.raft.RaftActorContextImpl
-
- All Implemented Interfaces:
RaftActorContext
public class RaftActorContextImpl extends Object implements RaftActorContext
Implementation of the RaftActorContext interface.- Author:
- Moiz Raja, Thomas Pantelis
-
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ActorRef
actorOf(Props props)
Creates a new local actor.ActorSelection
actorSelection(String path)
Creates an actor selection.void
addToPeers(String peerId, String address, VotingState votingState)
Adds a new peer.boolean
anyVotingPeers()
Determines if there are any voting peers.ActorRef
getActor()
Returns the reference to the RaftActor.ActorSystem
getActorSystem()
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.long
getCommitIndex()
Returns the index of highest log entry known to be committed.ConfigParams
getConfigParams()
Returns the ConfigParams instance.RaftActorBehavior
getCurrentBehavior()
Returns the current behavior attached to the RaftActor.Executor
getExecutor()
Return an Executor which is guaranteed to run tasks in the context ofRaftActorContext.getActor()
.FileBackedOutputStreamFactory
getFileBackedOutputStreamFactory()
Returns theFileBackedOutputStreamFactory
instance with a common configuration.String
getId()
Returns the identifier for the RaftActor.long
getLastApplied()
Returns index of highest log entry applied to state machine.Logger
getLogger()
Returns the logger to be used for logging messages.short
getPayloadVersion()
Returns the payload version to be used when replicating data.ActorSelection
getPeerActorSelection(String peerId)
Returns an ActorSelection for a peer.String
getPeerAddress(String peerId)
Gets the address of a peer as a String.Collection<String>
getPeerIds()
Returns the id's for each peer.PeerInfo
getPeerInfo(String peerId)
Returns the PeerInfo for the given peer.Collection<PeerInfo>
getPeers()
Returns the PeerInfo instances for each peer.ServerConfigurationPayload
getPeerServerInfo(boolean includeSelf)
Returns the peer information as a ServerConfigurationPayload if dynamic server configurations have been applied.DataPersistenceProvider
getPersistenceProvider()
Returns the DataPersistenceProvider instance.RaftActorLeadershipTransferCohort
getRaftActorLeadershipTransferCohort()
Returns the RaftActorLeadershipTransferCohort if leadership transfer is in progress.RaftPolicy
getRaftPolicy()
Returns the RaftPolicy used to determine certain Raft behaviors.ReplicatedLog
getReplicatedLog()
Returns the ReplicatedLog instance.SnapshotManager
getSnapshotManager()
Returns the SnapshotManager instance.ElectionTerm
getTermInformation()
Returns the current ElectionTerm information.long
getTotalMemory()
Returns the total available memory for use in calculations.boolean
hasFollowers()
Determines if there are any peer followers.boolean
isDynamicServerConfigurationInUse()
Determines if there have been any dynamic server configuration changes applied.boolean
isVotingMember()
Determines if this peer is a voting member of the cluster.void
removePeer(String name)
Removes a peer.void
setCommitIndex(long commitIndex)
Sets the index of highest log entry known to be committed.void
setConfigParams(ConfigParams configParams)
void
setDynamicServerConfigurationInUse()
Sets that dynamic server configuration changes have been applied.void
setLastApplied(long lastApplied)
Sets index of highest log entry applied to state machine.void
setPayloadVersion(short payloadVersion)
void
setPeerAddress(String peerId, String peerAddress)
Sets the address of a peer.void
setRaftActorLeadershipTransferCohort(RaftActorLeadershipTransferCohort leadershipTransferCohort)
Sets the RaftActorLeadershipTransferCohort for transferring leadership.void
setReplicatedLog(ReplicatedLog replicatedLog)
Sets the ReplicatedLog instance.void
setTotalMemoryRetriever(LongSupplier retriever)
Sets the retriever of the total memory metric.void
updatePeerIds(ServerConfigurationPayload serverConfig)
Updates the peers and information to match the given ServerConfigurationPayload.
-
-
-
Constructor Detail
-
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 Detail
-
setPayloadVersion
public void setPayloadVersion(short payloadVersion)
-
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
public void setConfigParams(ConfigParams configParams)
-
actorOf
public ActorRef actorOf(Props props)
Description copied from interface:RaftActorContext
Creates a new local actor.- Specified by:
actorOf
in interfaceRaftActorContext
- Parameters:
props
- the Props used to create the actor.- Returns:
- a reference to the newly created actor.
-
actorSelection
public ActorSelection actorSelection(String path)
Description copied from interface:RaftActorContext
Creates an actor selection.- Specified by:
actorSelection
in interfaceRaftActorContext
- Parameters:
path
- the path.- Returns:
- an actor selection for the given actor path.
-
getId
public String 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 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
public final Executor 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.
-
getCluster
public Optional<Cluster> getCluster()
Description copied from interface:RaftActorContext
The akka Cluster singleton for the actor system if one is configured.- Specified by:
getCluster
in interfaceRaftActorContext
- Returns:
- an Optional containing the Cluster instance is present.
-
getTermInformation
public ElectionTerm getTermInformation()
Description copied from interface:RaftActorContext
Returns the current ElectionTerm information.- Specified by:
getTermInformation
in interfaceRaftActorContext
- Returns:
- the ElectionTerm.
-
getCommitIndex
public long getCommitIndex()
Description copied from interface:RaftActorContext
Returns the index of highest log entry known to be committed.- Specified by:
getCommitIndex
in interfaceRaftActorContext
- Returns:
- index of highest log entry known to be committed.
-
setCommitIndex
public void setCommitIndex(long commitIndex)
Description copied from interface:RaftActorContext
Sets the index of highest log entry known to be committed.- Specified by:
setCommitIndex
in interfaceRaftActorContext
- Parameters:
commitIndex
- new commit index
-
getLastApplied
public long getLastApplied()
Description copied from interface:RaftActorContext
Returns index of highest log entry applied to state machine.- Specified by:
getLastApplied
in interfaceRaftActorContext
- Returns:
- index of highest log entry applied to state machine.
-
setLastApplied
public void setLastApplied(long lastApplied)
Description copied from interface:RaftActorContext
Sets index of highest log entry applied to state machine.- Specified by:
setLastApplied
in interfaceRaftActorContext
- Parameters:
lastApplied
- the new applied index.
-
setReplicatedLog
public void setReplicatedLog(ReplicatedLog replicatedLog)
Description copied from interface:RaftActorContext
Sets the ReplicatedLog instance.- Specified by:
setReplicatedLog
in interfaceRaftActorContext
- Parameters:
replicatedLog
- the ReplicatedLog instance.
-
getReplicatedLog
public ReplicatedLog getReplicatedLog()
Description copied from interface:RaftActorContext
Returns the ReplicatedLog instance.- Specified by:
getReplicatedLog
in interfaceRaftActorContext
- Returns:
- the ReplicatedLog instance.
-
getActorSystem
public ActorSystem getActorSystem()
Description copied from interface:RaftActorContext
Returns the The ActorSystem associated with this context.- Specified by:
getActorSystem
in interfaceRaftActorContext
- Returns:
- the ActorSystem.
-
getLogger
public Logger getLogger()
Description copied from interface:RaftActorContext
Returns the logger to be used for logging messages.- Specified by:
getLogger
in interfaceRaftActorContext
- Returns:
- the logger.
-
getPeerIds
public Collection<String> 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
public Collection<PeerInfo> getPeers()
Description copied from interface:RaftActorContext
Returns the PeerInfo instances for each peer.- Specified by:
getPeers
in interfaceRaftActorContext
- Returns:
- list of PeerInfo
-
getPeerInfo
public PeerInfo getPeerInfo(String peerId)
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
public String getPeerAddress(String peerId)
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.
-
updatePeerIds
public void updatePeerIds(ServerConfigurationPayload serverConfig)
Description copied from interface:RaftActorContext
Updates the peers and information to match the given ServerConfigurationPayload.- Specified by:
updatePeerIds
in interfaceRaftActorContext
- Parameters:
serverConfig
- the ServerConfigurationPayload.
-
getConfigParams
public ConfigParams getConfigParams()
Description copied from interface:RaftActorContext
Returns the ConfigParams instance.- Specified by:
getConfigParams
in interfaceRaftActorContext
- Returns:
- the ConfigParams instance.
-
addToPeers
public void addToPeers(String peerId, String address, VotingState votingState)
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
public void removePeer(String name)
Description copied from interface:RaftActorContext
Removes a peer.- Specified by:
removePeer
in interfaceRaftActorContext
- Parameters:
name
- the id of the peer to remove.
-
getPeerActorSelection
public ActorSelection getPeerActorSelection(String peerId)
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
public void setPeerAddress(String peerId, String peerAddress)
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
public SnapshotManager 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
public void setTotalMemoryRetriever(LongSupplier retriever)
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
public DataPersistenceProvider getPersistenceProvider()
Description copied from interface:RaftActorContext
Returns the DataPersistenceProvider instance.- Specified by:
getPersistenceProvider
in interfaceRaftActorContext
- Returns:
- the DataPersistenceProvider instance.
-
getRaftPolicy
public RaftPolicy 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
public ServerConfigurationPayload getPeerServerInfo(boolean includeSelf)
Description copied from interface:RaftActorContext
Returns the peer information as a ServerConfigurationPayload 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 ServerConfigurationPayload 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
public RaftActorBehavior getCurrentBehavior()
Description copied from interface:RaftActorContext
Returns the current behavior attached to the RaftActor.- Specified by:
getCurrentBehavior
in interfaceRaftActorContext
- Returns:
- current behavior.
-
getApplyStateConsumer
public Consumer<ApplyState> getApplyStateConsumer()
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:
getApplyStateConsumer
in interfaceRaftActorContext
- Returns:
- the Consumer
-
getFileBackedOutputStreamFactory
public FileBackedOutputStreamFactory getFileBackedOutputStreamFactory()
Description copied from interface:RaftActorContext
Returns theFileBackedOutputStreamFactory
instance with a common configuration.- Specified by:
getFileBackedOutputStreamFactory
in interfaceRaftActorContext
- Returns:
- the
FileBackedOutputStreamFactory
;
-
getRaftActorLeadershipTransferCohort
public RaftActorLeadershipTransferCohort 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
-
-