fsm

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBaseFSMSnapshot

func NewBaseFSMSnapshot(fsm *RoutingFSM) raft.FSMSnapshot

Types

type BaseFSMSnapshot

type BaseFSMSnapshot struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*BaseFSMSnapshot) Persist

func (i *BaseFSMSnapshot) Persist(sink raft.SnapshotSink) error

func (*BaseFSMSnapshot) Release

func (i *BaseFSMSnapshot) Release()

type FSM

type FSM interface {
	raft.FSM

	// Init is used to pass the original serializer from EasyRaft Node to be able to deserialize messages
	// coming from other nodes
	Init(ser serializer.Serializer)
}

FSM is the interface for using Finite State Machine in Raft Cluster

func NewRoutingFSM

func NewRoutingFSM(services []FSMService) FSM

type FSMService

type FSMService interface {
	// Name returns the unique ID/Name which will identify the FSM Service when it comes to routing incoming messages
	Name() string

	// NewLog is called when a new raft log message is committed in the cluster and matched with any of the GetReqDataTypes returned types
	// in this method we can handle what should happen when we got a new raft log regarding our FSM service
	NewLog(requestType interface{}, request map[string]interface{}) interface{}

	// GetReqDataTypes returns all the request structs which are used by this FSMService
	GetReqDataTypes() []interface{}

	// ApplySnapshot is used to decode and apply a snapshot to the FSMService
	ApplySnapshot(input interface{}) error
}

FSMService interface makes it easier to build State Machines

func NewInMemoryMapService

func NewInMemoryMapService() FSMService

type InMemoryMapService

type InMemoryMapService struct {
	sync.RWMutex
	Maps map[string]*Map
}

func (*InMemoryMapService) ApplySnapshot

func (m *InMemoryMapService) ApplySnapshot(input interface{}) error

func (*InMemoryMapService) Get

func (m *InMemoryMapService) Get(mapName string, key string) interface{}

func (*InMemoryMapService) GetReqDataTypes

func (m *InMemoryMapService) GetReqDataTypes() []interface{}

func (*InMemoryMapService) Name

func (m *InMemoryMapService) Name() string

func (*InMemoryMapService) NewLog

func (m *InMemoryMapService) NewLog(requestType interface{}, request map[string]interface{}) interface{}

func (*InMemoryMapService) Put

func (m *InMemoryMapService) Put(mapName string, key string, value interface{})

func (*InMemoryMapService) Remove

func (m *InMemoryMapService) Remove(mapName string, key string)

type Map

type Map struct {
	sync.RWMutex
	Data map[string]interface{}
}

type MapGetRequest

type MapGetRequest struct {
	MapName string
	Key     string
}

type MapPutRequest

type MapPutRequest struct {
	MapName string
	Key     string
	Value   interface{}
}

type MapRemoveRequest

type MapRemoveRequest struct {
	MapName string
	Key     string
}

type RoutingFSM

type RoutingFSM struct {
	// contains filtered or unexported fields
}

func (*RoutingFSM) Apply

func (i *RoutingFSM) Apply(log *raft.Log) interface{}

func (*RoutingFSM) Init

func (i *RoutingFSM) Init(ser serializer.Serializer)

func (*RoutingFSM) Restore

func (i *RoutingFSM) Restore(closer io.ReadCloser) error

func (*RoutingFSM) Snapshot

func (i *RoutingFSM) Snapshot() (raft.FSMSnapshot, error)

Jump to

Keyboard shortcuts

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