bg

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ComponentToId = map[string]int{} //Gives the component id (int) when the name is passed
View Source
var IdToComponent = map[int]string{} //Gives the component name (string)

Functions

func CountPaths

func CountPaths(g *simple.DirectedGraph)

CountPaths calculates the waiting count for each component based on its dependencies

func DFSWithMemoization

func DFSWithMemoization(g *simple.DirectedGraph, nodeID int64, memo map[int64]map[int64]int)

DFSWithMemoization performs a DFS to calculate paths from the node to its ancestors.

func ParseYAML

func ParseYAML(filePath string) (*simple.DirectedGraph, map[int64][]int64, error)

Types

type BasicComponent

type BasicComponent struct {
	CompId     int
	InChannel  chan interface{}
	OutChannel []chan interface{}
	State      ComponentState // Field to track component state
	StateMutex sync.Mutex     // Mutex to protect state changes
	DirtyFlag  bool
}

BasicComponent represents a single component with channels and implements the Component interface.

func (*BasicComponent) Cancel added in v1.0.11

func (c *BasicComponent) Cancel()

Cancel is a placeholder for the user-defined request cancellation method.

func (*BasicComponent) GetLiveVersion

func (c *BasicComponent) GetLiveVersion() int

func (*BasicComponent) GetStagingData

func (c *BasicComponent) GetStagingData() interface{}

func (*BasicComponent) GetStagingVersion

func (c *BasicComponent) GetStagingVersion() int

func (*BasicComponent) ProcessReq

func (c *BasicComponent) ProcessReq(req Request[interface{}])

ProcessReq processes requests

func (*BasicComponent) Sync

func (c *BasicComponent) Sync()

Sync is a placeholder for the user-defined synchronization method.

type Component

type Component interface {
	GetLiveVersion() int
	GetStagingVersion() int
	GetStagingData() interface{}
	ProcessReq(req Request[interface{}])
	Cancel()
	Sync()
	// contains filtered or unexported methods
}

Component interface defines the behavior that all components must implement.

type ComponentDependency

type ComponentDependency struct {
	Components map[string][]string `yaml:"components"`
}

type ComponentState

type ComponentState int

ComponentState defines the possible states of a component

const (
	Idle ComponentState = iota
	Running
	Cancelled
)

type CompositeKey

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

type LiveVersion

type LiveVersion int
const (
	Blue LiveVersion = iota
	Green
)

type OperationType

type OperationType int
const (
	Create OperationType = iota
	Update
	Delete
)

type Request

type Request[T any] struct {
	ReqType       RequestType
	SourceCompId  int
	ComponentName string
	Operation     OperationType
	Data          T
	Index         int
}

Request encapsulates the details of a request being sent.

type RequestType

type RequestType int
const (
	Operation RequestType = iota
	Switch
	Cancel
)

type Signal

type Signal struct {
	SigType      RequestType
	SourceCompId int
	CompId       int
	State        ComponentState
}

Signal represents a signal sent between component and Supervisor

type Supervisor

type Supervisor struct {
	CompId        int
	InChannel     chan interface{}
	OutChannelMap map[int]chan interface{}
	RequestQueue  []Request[interface{}]
	QueueMutex    sync.Mutex    // To protect access to the queue
	TaskList      map[int][]int //Maintains current ongoing tasks
	DoneList      map[int][]int
	SwitchList    map[int][]int //Contains the list of components that are done switching
	// contains filtered or unexported fields
}

func InitializeComponents

func InitializeComponents(filePath string, userComps []Component, switchCount int) *Supervisor

InitializeComponents initializes and starts the components based on dependencies.

func (*Supervisor) CancelReq

func (s *Supervisor) CancelReq(componentName string)

func (*Supervisor) SendReq

func (s *Supervisor) SendReq(compName string, operation OperationType, data interface{}, index int) bool

SendReq adds the request to the queue

type SupervisorInterface

type SupervisorInterface interface {
	SendReq(compName string, operation OperationType, data interface{}, index int) bool
	CancelReq(componentName string)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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