clientstate

package
v0.0.0-...-2a45ea8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package clientstate provides means to interact with a representation of the state maintained by the replica for each client instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option represents a parameter to initialize State with.

func WithTimerProvider

func WithTimerProvider(timerProvider timer.Provider) Option

WithTimerProvider specifies the abstract timer implementation to use. Standard timer implementation is used by default.

type Provider

type Provider interface {
	ClientState(clientID uint32) State
	Clients() (clientIDs []uint32)
}

Provider represents the replica state maintained for the clients. It is safe to use concurrently.

ClientState method returns the piece of replica state associated with a client, given the client ID.

Clients method returns a slice of maintained client IDs.

func NewProvider

func NewProvider(requestTimeout func() time.Duration, prepareTimeout func() time.Duration, args ...Option) Provider

NewProvider creates an instance of Provider. Optional parameters can be specified as args.

type State

type State interface {
	CaptureRequestSeq(seq uint64) (new bool, release func())
	PrepareRequestSeq(seq uint64) (new bool, err error)
	RetireRequestSeq(seq uint64) (new bool, err error)
	UnprepareRequestSeq()

	AddReply(reply messages.Reply)
	ReplyChannel(seq uint64, cancel <-chan struct{}) <-chan messages.Reply

	StartRequestTimer(seq uint64, handleTimeout func())
	StopRequestTimer(seq uint64)

	StartPrepareTimer(seq uint64, handleTimeout func())
	StopPrepareTimer(seq uint64)

	StopAllTimers()
}

State represents the state maintained by the replica for each client instance. All methods are safe to invoke concurrently.

CaptureRequestSeq captures a request identifier seq. The greatest captured identifier has to be released before a new identifier can be captured. A new captured identifier has to be released before any identifier that is greater than the last released can be captured. An identifier is new if it is greater than the greatest captured. If an identifier cannot be captured immediately, it will block until the identifier can be captured. The return value new indicates if the supplied identifier was new. In that case, the newly captured request identifier has to be released by invoking the returned release function.

PrepareRequestSeq records the request identifier seq as prepared. An identifier can only be prepared if it is greater than the last prepared and has been captured before.

RetireRequestSeq records the request identifier seq as retired. An identifier can only be retired if it is greater than the last retired and has been prepared before.

UnprepareRequestSeq un-prepares any previously prepared but not yet retired request identifier seq.

AddReply accepts a Reply message. Only the Reply message referring to the highest request identifier is accepted. It will never be blocked by any of the channels returned from ReplyChannel.

ReplyChannel returns a channel to receive the Reply message corresponding to the supplied request identifier. The returned channel will be closed after the Reply message is sent to it or there will be no Reply message to be added for the supplied request identifier.

StartRequestTimer starts a timer for the supplied request identifier to expire after the duration of request timeout. The supplied callback function handleTimeout is invoked asynchronously upon timer expiration. If the previous timer started for any request identifier has not yet expired, it will be canceled and a new timer started.

StopRequestTimer stops timer started for the same request identifier by StartRequestTimer, if any.

StartPrepareTimer starts a timer for the supplied request identifier to expire after the duration of prepare timeout. The supplied callback function handleTimeout is invoked asynchronously upon timer expiration. If the previous timer started for any request identifier has not yet expired, it will be canceled and a new timer started.

StopPrepareTimer stops timer started for the same request identifier by StartPrepareTimer, if any.

StopAllTimers stops any timer maintained in the client state.

Directories

Path Synopsis
Package mock_clientstate is a generated GoMock package.
Package mock_clientstate is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL