dependencies

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNodeType     = errors.New("unsupported node type")
	ErrNodeNotFound = errors.New("node not found")
)

Functions

func ResetManagerFromTests

func ResetManagerFromTests()

ResetManagerFromTests is a workaround for tests to reset the manager instance. TODO: remove this when the manager is refactored to be thread-safe.

Types

type Action

type Action interface{}

Action is a struct representing a request by a watcher function to interact with the tree.

Actions can perform various tasks, including but not limited to modifying the tree. Utilizing Actions ensures that operations are executed in the proper order, avoiding potential bugs related to operation sequencing. All interactions with the tree which might modify the tree should be carried out through Actions, rather than directly within a watcher's scope.

type CancelNodeAddAction

type CancelNodeAddAction struct {
	Reason error
}

CancelNodeAddAction cancels the process of adding a node to the manager.

This method will: 1. Cancel the addition of the specified node. 2. Cancel the addition of all dependent nodes. 3. Remove any dependencies that are no longer referenced by other nodes.

The overall effect is similar to calling RemoveEvent directly on the manager, but with additional safeguards and order of operations to ensure proper cleanup and consistency within the system.

Note: - This action does not prevent other watchers from being notified. - When the node addition is cancelled, event removal watchers will be invoked to allow for cleanup operations.

It is recommended to use CancelNodeAddAction instead of directly calling RemoveEvent to ensure that the cancellation and cleanup processes are handled in the correct order.

func NewCancelNodeAddAction

func NewCancelNodeAddAction(reason error) *CancelNodeAddAction

type ErrNodeAddCancelled

type ErrNodeAddCancelled struct {
	Reasons []error
}

ErrNodeAddCancelled is the error produced when cancelling a node add to the manager using the CancelNodeAddAction Action.

func NewErrNodeAddCancelled

func NewErrNodeAddCancelled(reasons []error) *ErrNodeAddCancelled

func (*ErrNodeAddCancelled) AddReason

func (cancelErr *ErrNodeAddCancelled) AddReason(reason error)

func (*ErrNodeAddCancelled) Error

func (cancelErr *ErrNodeAddCancelled) Error() string

type EventNode

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

EventNode represent an event in the dependencies tree. It should be read-only for other packages, as it is internally managed.

func (*EventNode) GetDependencies

func (en *EventNode) GetDependencies() events.Dependencies

func (*EventNode) GetDependents

func (en *EventNode) GetDependents() []events.ID

func (*EventNode) GetID

func (en *EventNode) GetID() events.ID

func (*EventNode) IsDependencyOf

func (en *EventNode) IsDependencyOf(dependent events.ID) bool

type Manager

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

Manager is a management tree for the current dependencies of events. As events can depend on multiple things (e.g events, probes), it manages their connections in the form of a tree. The tree supports watcher functions for adding and removing nodes. The watchers should be used as the way to handle changes in events, probes or any other node type in Tracker. The manager is *NOT* thread-safe.

func GetManagerInstance

func GetManagerInstance() *Manager

func NewDependenciesManager

func NewDependenciesManager(dependenciesGetter func(events.ID) events.Dependencies) *Manager

func (*Manager) GetEvent

func (m *Manager) GetEvent(id events.ID) (*EventNode, error)

GetEvent returns the dependencies of the given event.

func (*Manager) GetProbe

func (m *Manager) GetProbe(handle probes.Handle) (*ProbeNode, error)

GetProbe returns the given probe node managed by the Manager

func (*Manager) RemoveEvent

func (m *Manager) RemoveEvent(id events.ID) error

RemoveEvent removes the given event from the management tree. It removes its reference from its dependencies. If these events were added to the tree only as dependencies, they will be removed as well if they are not referenced by any other event anymore and not explicitly selected. It also removes all the events that depend on the given event (as their dependencies are no longer valid). It returns if managed to remove the event, as it might not be present in the tree.

func (*Manager) SelectEvent

func (m *Manager) SelectEvent(id events.ID) (*EventNode, error)

SelectEvent adds the given event to the management tree with default dependencies and marks it as explicitly selected. It also recursively adds all events that this event depends on (its dependencies) to the tree. This function has no effect if the event is already added.

func (*Manager) SubscribeAdd

func (m *Manager) SubscribeAdd(subscribeType NodeType, onAdd func(node interface{}) []Action)

SubscribeAdd adds a watcher function called upon the addition of an event to the tree. Add watcher are called in the order of their subscription.

func (*Manager) SubscribeRemove

func (m *Manager) SubscribeRemove(subscribeType NodeType, onRemove func(node interface{}) []Action)

SubscribeRemove adds a watcher function called upon the removal of an event from the tree. Remove watchers are called in reverse order of their subscription.

func (*Manager) UnselectEvent

func (m *Manager) UnselectEvent(id events.ID) bool

UnselectEvent marks the event as not explicitly selected. If the event is not a dependency of another event, it will be removed from the tree, and its dependencies will be cleaned if they are not referenced or explicitly selected. Returns whether it was removed.

type NodeType

type NodeType string
const (
	EventNodeType   NodeType = "event"
	ProbeNodeType   NodeType = "probe"
	AllNodeTypes    NodeType = "all"
	IllegalNodeType NodeType = "illegal"
)

type ProbeNode

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

func NewProbeNode

func NewProbeNode(handle probes.Handle, dependents []events.ID) *ProbeNode

func (*ProbeNode) GetDependents

func (hn *ProbeNode) GetDependents() []events.ID

func (*ProbeNode) GetHandle

func (hn *ProbeNode) GetHandle() probes.Handle

Jump to

Keyboard shortcuts

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