Interface ConsensusModuleExtension
- All Superinterfaces:
AutoCloseable
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intconsensusWork(long nowNs) Similar todoWork(long), but executed only when there's no election in progress.intdoWork(long nowNs) An extension should implement this method to do its work.voidonElectionComplete(ConsensusControlState consensusControlState) Cluster election is complete and new publication is added for the leadership term.onIngressExtensionMessage(int actingBlockLength, int templateId, int schemaId, int actingVersion, DirectBuffer buffer, int offset, int length, Header header) Callback for handling messages received as ingress to a cluster.onLogExtensionMessage(int actingBlockLength, int templateId, int schemaId, int actingVersion, DirectBuffer buffer, int offset, int length, Header header) Callback for handling committed log messages (for follower or recovery).voidonNewLeadershipTerm(ConsensusControlState consensusControlState) New Leadership term and the consensus control state has changed.voidCallback when preparing for a new Raft leadership term - before election.voidonSessionClosed(long clusterSessionId, io.aeron.cluster.codecs.CloseReason closeReason) Callback indicating a cluster session has closed.voidonSessionOpened(long clusterSessionId) Callback indicating a cluster session has opened.voidonStart(ConsensusModuleControl consensusModuleControl, Image snapshotImage) Start event where the extension can perform any initialisation required and load snapshot state.voidonTakeSnapshot(ExclusivePublication snapshotPublication) The extension should take a snapshot and store its state to the provided archiveExclusivePublication.intslowTickWork(long nowNs) Similar todoWork(long), but executed less frequently.intSchema supported by this extension.
-
Method Details
-
supportedSchemaId
int supportedSchemaId()Schema supported by this extension.- Returns:
- schema id supported.
-
onStart
Start event where the extension can perform any initialisation required and load snapshot state. The snapshot image can be null if no previous snapshot exists.Note: As this is a potentially long-running operation the implementation should use
Cluster.idleStrategy()and then occasionally callIdleStrategy.idle()orIdleStrategy.idle(int), especially when polling theImagereturns 0.- Parameters:
consensusModuleControl- with which the extension can interact.snapshotImage- from which the extension can load its state which can be null when no snapshot.
-
doWork
int doWork(long nowNs) An extension should implement this method to do its work. Long-running operations should be decomposed.The return value is used for implementing an idle strategy that can be employed when no work is currently available for the extension to process.
If the extension wished to terminate and close then a
AgentTerminationExceptioncan be thrown.- Parameters:
nowNs- is cluster time in nanoseconds.- Returns:
- 0 to indicate no work was currently available, a positive value otherwise.
-
slowTickWork
int slowTickWork(long nowNs) Similar todoWork(long), but executed less frequently.- Parameters:
nowNs- is cluster time in nanoseconds.- Returns:
- 0 to indicate no work was currently available, a positive value otherwise.
-
consensusWork
int consensusWork(long nowNs) Similar todoWork(long), but executed only when there's no election in progress.- Parameters:
nowNs- is cluster time in nanoseconds.- Returns:
- 0 to indicate no work was currently available, a positive value otherwise.
-
onElectionComplete
Cluster election is complete and new publication is added for the leadership term. If the node is a follower then the publication will be null.- Parameters:
consensusControlState- state to allow extension to control the consensus module.
-
onNewLeadershipTerm
New Leadership term and the consensus control state has changed.- Parameters:
consensusControlState- state to allow extension to control the consensus module.
-
onIngressExtensionMessage
ControlledFragmentHandler.Action onIngressExtensionMessage(int actingBlockLength, int templateId, int schemaId, int actingVersion, DirectBuffer buffer, int offset, int length, Header header) Callback for handling messages received as ingress to a cluster.Within this callback reentrant calls to the
Aeronclient are not permitted and will result in undefined behaviour.- Parameters:
actingBlockLength- acting block length.templateId- the message template id (already parsed from header).schemaId- the schema id.actingVersion- acting version from headerbuffer- containing the data.offset- at which the data begins.length- of the data in bytes.header- representing the metadata for the data.- Returns:
- The action to be taken with regard to the stream position after the callback.
-
onLogExtensionMessage
ControlledFragmentHandler.Action onLogExtensionMessage(int actingBlockLength, int templateId, int schemaId, int actingVersion, DirectBuffer buffer, int offset, int length, Header header) Callback for handling committed log messages (for follower or recovery).Within this callback reentrant calls to the
Aeronclient are not permitted and will result in undefined behaviour.- Parameters:
actingBlockLength- acting block length.templateId- the message template id (already parsed from header).schemaId- the schema id.actingVersion- acting version from headerbuffer- containing the data.offset- at which the data begins.length- of the data in bytes.header- representing the metadata for the data.- Returns:
- The action to be taken with regard to the stream position after the callback.
-
close
void close()- Specified by:
closein interfaceAutoCloseable
-
onSessionOpened
void onSessionOpened(long clusterSessionId) Callback indicating a cluster session has opened.- Parameters:
clusterSessionId- of the opened session which is unique and not reused.
-
onSessionClosed
void onSessionClosed(long clusterSessionId, io.aeron.cluster.codecs.CloseReason closeReason) Callback indicating a cluster session has closed.- Parameters:
clusterSessionId- of the opened session which is unique and not reused.closeReason- reason to closing session
-
onPrepareForNewLeadership
void onPrepareForNewLeadership()Callback when preparing for a new Raft leadership term - before election. -
onTakeSnapshot
The extension should take a snapshot and store its state to the provided archiveExclusivePublication.Note: As this is a potentially long-running operation the implementation should use
Cluster.idleStrategy()and then occasionally callIdleStrategy.idle()orIdleStrategy.idle(int), especially when the snapshotExclusivePublicationreturnsPublication.BACK_PRESSURED.- Parameters:
snapshotPublication- to which the state should be recorded.
-