github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/clustered_service.go (about)

     1  package cluster
     2  
     3  import (
     4  	"github.com/lirm/aeron-go/aeron"
     5  	"github.com/lirm/aeron-go/aeron/atomic"
     6  	"github.com/lirm/aeron-go/aeron/logbuffer"
     7  	"github.com/lirm/aeron-go/cluster/codecs"
     8  )
     9  
    10  type ClusteredService interface {
    11  	// OnStart is called to initialize the service and load snapshot state, where the snapshot image can be nil if no previous snapshot exists.
    12  	//
    13  	// Note: As this can potentially be a long-running operation, the implementation should use Cluster.IdleStrategy() and
    14  	// occasionally call IdleStrategy.Idle(), especially when polling the Image returns 0
    15  	OnStart(cluster Cluster, image aeron.Image)
    16  
    17  	// OnSessionOpen notifies the clustered service that a session has been opened for a client to the cluster
    18  	OnSessionOpen(session ClientSession, timestamp int64)
    19  
    20  	// OnSessionClose notifies the clustered service that a session has been closed for a client to the cluster
    21  	OnSessionClose(
    22  		session ClientSession,
    23  		timestamp int64,
    24  		closeReason codecs.CloseReasonEnum,
    25  	)
    26  
    27  	// OnSessionMessage notifies the clustered service that a message has been received to be processed by a clustered service
    28  	OnSessionMessage(
    29  		session ClientSession,
    30  		timestamp int64,
    31  		buffer *atomic.Buffer,
    32  		offset int32,
    33  		length int32,
    34  		header *logbuffer.Header,
    35  	)
    36  
    37  	// OnTimerEvent notifies the clustered service that a scheduled timer has expired
    38  	OnTimerEvent(correlationId, timestamp int64)
    39  
    40  	// OnTakeSnapshot instructs the clustered service to take a snapshot and store its state to the provided aeron archive Publication.
    41  	//
    42  	// Note: As this is a potentially long-running operation the implementation should use
    43  	// Cluster.idleStrategy() and then occasionally call IdleStrategy.idle()
    44  	// especially when the snapshot ExclusivePublication returns Publication.BACK_PRESSURED
    45  	OnTakeSnapshot(publication *aeron.Publication)
    46  
    47  	// OnRoleChange notifies the clustered service that the cluster node has changed role
    48  	OnRoleChange(role Role)
    49  
    50  	// OnTerminate notifies the clustered service that the container is going to terminate
    51  	OnTerminate(cluster Cluster)
    52  
    53  	// OnNewLeadershipTermEvent notifies the clustered service that an election has been successful and a leader has entered a new term
    54  	OnNewLeadershipTermEvent(
    55  		leadershipTermId int64,
    56  		logPosition int64,
    57  		timestamp int64,
    58  		termBaseLogPosition int64,
    59  		leaderMemberId int32,
    60  		logSessionId int32,
    61  		timeUnit codecs.ClusterTimeUnitEnum,
    62  		appVersion int32,
    63  	)
    64  }