modules

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package modules provides interfaces of modules that serve as building blocks of a Node. Implementations of those interfaces are not contained by this package and are expected to be provided by other packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyEventsConcurrently

func ApplyEventsConcurrently(
	eventsIn *events.EventList,
	applyEvent func(*eventpb.Event) (*events.EventList, error),
) (*events.EventList, error)

ApplyEventsConcurrently takes a list of events and applies the given applyEvent function to each event in the list. Processing is performed concurrently on all events in the input list. Thus, the provided applyEvent function must be thread-safe. The EventLists returned by applyEvent are aggregated in a single EventList and returned by ApplyEventsConcurrently. Despite being executed concurrently, the order of the returned results preserves the order of the corresponding input events. Thus, if applyEvent is deterministic, the output of ApplyEventsConcurrently is also deterministic. If one or more errors occur during processing, ApplyEventsConcurrently returns the first of them, along with an empty EventList.

func ApplyEventsSequentially

func ApplyEventsSequentially(
	eventsIn *events.EventList,
	applyEvent func(*eventpb.Event) (*events.EventList, error),
) (*events.EventList, error)

ApplyEventsSequentially takes a list of events and applies the given applyEvent function to each event in the list. Processing is performed sequentially, one event at a time, in the order of the input list. The EventLists returned by applyEvent are aggregated in a single EventList (in order of creation) and returned by ApplyEventsSequentially.

Types

type ActiveModule

type ActiveModule interface {
	Module

	// ApplyEvents applies a list of input events to the module, making it advance its state
	// and potentially write a list of events output events to the ActiveModule's output channel.
	//
	// ApplyEvents takes the following arguments:
	// - ctx: A Context the canceling of which will abort the processing of the module's logic
	//        and releases all associated resources.
	//        In particular, if the processing spawned any goroutines, all those goroutines must terminate,
	//        even if blocked on channel reads/writes or I/O.
	// - events: A list of events to process. The Node will call this function repeatedly,
	//           each time it submits new events to the ActiveModule for processing.
	//
	// If an error occurs during event processing, ApplyEvents returns it. Otherwise, it returns nil.
	//
	// Each invocation of ApplyEvents must be non-blocking.
	// Note that while it is expected that ApplyEvents causes writes to the output channel,
	// there is no guarantee of the channel being also read from, potentially resulting in writes to block.
	// Nevertheless, ApplyEvents must never block.
	// This can be achieved, for example, by having the writes to the output channel happen in a separate goroutine
	// spawned by ApplyEvents.
	//
	// The Node never invokes an ApplyEvents concurrently.
	ApplyEvents(ctx context.Context, events *events.EventList) error

	// EventsOut returns a channel to which output events produced by the ActiveModule's implementation will be written.
	//
	// Note that the implementation may produce output events even without receiving any input.
	//
	// Note also that the Node does not guarantee to always read events from the channel returned by EventsOut.
	// The node might decide at any moment to stop reading from eventsOut for an arbitrary amount of time
	// (e.g. if the Node's internal event buffers become full and the Node needs to wait until they free up).
	// Even then, calls to ApplyEvents must be non-blocking.
	EventsOut() <-chan *events.EventList
}

type Module

type Module interface {

	// ImplementsModule only serves the purpose of indicating that this is a Module and must not be called.
	ImplementsModule()
}

Module generalizes the ActiveModule and PassiveModule types.

type Modules

type Modules map[t.ModuleID]Module

The Modules structs groups the modules a Node consists of.

type NullActive

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

The NullActive module is an ActiveModule that ignores all incoming events and never produces any events.

func (NullActive) ApplyEvents

func (n NullActive) ApplyEvents(_ context.Context, _ *events.EventList) error

func (NullActive) EventsOut

func (n NullActive) EventsOut() <-chan *events.EventList

func (NullActive) ImplementsModule

func (n NullActive) ImplementsModule()

The ImplementsModule method only serves the purpose of indicating that this is a Module and must not be called.

type NullPassive

type NullPassive struct {
}

The NullPassive module is a PassiveModule that ignores all incoming events.

func (NullPassive) ApplyEvents

func (n NullPassive) ApplyEvents(_ *events.EventList) (*events.EventList, error)

func (NullPassive) ImplementsModule

func (n NullPassive) ImplementsModule()

The ImplementsModule method only serves the purpose of indicating that this is a Module and must not be called.

type PassiveModule

type PassiveModule interface {
	Module

	// ApplyEvents applies a list of input events to the module, making it advance its state
	// and returns a (potentially empty) list of output events that the application of the input events results in.
	ApplyEvents(events *events.EventList) (*events.EventList, error)
}

Directories

Path Synopsis
internal/mock_internal
Package mock_internal is a generated GoMock package.
Package mock_internal is a generated GoMock package.

Jump to

Keyboard shortcuts

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