Interface ConsensusModuleExtension

All Superinterfaces:
AutoCloseable

public interface ConsensusModuleExtension extends AutoCloseable
Extension for handling messages from external schemas unknown to core Aeron Cluster code thus providing an extension to the core ingress consensus module behaviour.
  • Method Details

    • supportedSchemaId

      int supportedSchemaId()
      Schema supported by this extension.
      Returns:
      schema id supported.
    • onStart

      void onStart(ConsensusModuleControl consensusModuleControl, Image snapshotImage)
      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 call IdleStrategy.idle() or IdleStrategy.idle(int), especially when polling the Image returns 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 AgentTerminationException can 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 to doWork(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 to doWork(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

      void onElectionComplete(ConsensusControlState consensusControlState)
      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

      void onNewLeadershipTerm(ConsensusControlState consensusControlState)
      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 Aeron client 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 header
      buffer - 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 Aeron client 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 header
      buffer - 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:
      close in interface AutoCloseable
    • 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

      void onTakeSnapshot(ExclusivePublication snapshotPublication)
      The extension should take a snapshot and store its state to the provided archive ExclusivePublication.

      Note: As this is a potentially long-running operation the implementation should use Cluster.idleStrategy() and then occasionally call IdleStrategy.idle() or IdleStrategy.idle(int), especially when the snapshot ExclusivePublication returns Publication.BACK_PRESSURED.

      Parameters:
      snapshotPublication - to which the state should be recorded.