engine

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine implements the core.Engine interface and orchestration pipeline.

Index

Constants

View Source
const DefaultSubscriberBuffer = 256

DefaultSubscriberBuffer is the default buffer size for DataBus subscriber channels.

Variables

This section is empty.

Functions

func New

func New() core.Engine

New creates a new CoreC Engine instance.

func NewScheduler

func NewScheduler(
	readFunc func(ctx context.Context, driver string, tags []string) ([]core.TagValue, error),
	onData func(driver string, values []core.TagValue),
	errorThrottleWindow time.Duration,
) *scheduler

NewScheduler creates a new scheduler. readFunc is called to read tags from a driver. onData is called when data is received. errorThrottleWindow is the time window for suppressing repeated error logs; <=0 falls back to core.DefaultErrorThrottleWindow.

Types

type CoreCEngine

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

CoreCEngine implements core.Engine. This is the central orchestrator.

func (*CoreCEngine) AddDriver

func (e *CoreCEngine) AddDriver(config core.DriverConfig) error

func (*CoreCEngine) AddTransport

func (e *CoreCEngine) AddTransport(config core.TransportConfig) error

func (*CoreCEngine) DeadLetterEntries added in v0.0.2

func (e *CoreCEngine) DeadLetterEntries() []core.DeadLetterEntry

DeadLetterEntries returns a copy of the current dead letter queue.

func (*CoreCEngine) GetDriver

func (e *CoreCEngine) GetDriver(name string) (core.Driver, bool)

func (*CoreCEngine) GetRuleStats

func (e *CoreCEngine) GetRuleStats() []core.RuleStat

func (*CoreCEngine) GetTransport

func (e *CoreCEngine) GetTransport(name string) (core.Transport, bool)

func (*CoreCEngine) LatestValues

func (e *CoreCEngine) LatestValues(driver string) map[string]core.DataPoint

func (*CoreCEngine) ListDrivers

func (e *CoreCEngine) ListDrivers() []core.DriverStatus

func (*CoreCEngine) ListTransports

func (e *CoreCEngine) ListTransports() []core.TransportStatus

func (*CoreCEngine) OnAlert

func (e *CoreCEngine) OnAlert(handler func(point core.DataPoint, rule core.Rule))

func (*CoreCEngine) ReadTag

func (e *CoreCEngine) ReadTag(ctx context.Context, driver, tag string) (*core.TagValue, error)

func (*CoreCEngine) Reload

func (e *CoreCEngine) Reload(config *core.Config) error

func (*CoreCEngine) RemoveDriver

func (e *CoreCEngine) RemoveDriver(name string) error

func (*CoreCEngine) RemoveTransport

func (e *CoreCEngine) RemoveTransport(name string) error

func (*CoreCEngine) Resume

func (e *CoreCEngine) Resume() error

func (*CoreCEngine) SetRuleDisabled

func (e *CoreCEngine) SetRuleDisabled(index int, disabled bool) error

func (*CoreCEngine) SetRules

func (e *CoreCEngine) SetRules(rules []core.RuleConfig) error

func (*CoreCEngine) StaleThreshold added in v0.0.2

func (e *CoreCEngine) StaleThreshold() time.Duration

func (*CoreCEngine) Start

func (e *CoreCEngine) Start(ctx context.Context, config *core.Config) error

func (*CoreCEngine) Stats

func (e *CoreCEngine) Stats() core.EngineStats

func (*CoreCEngine) Status

func (e *CoreCEngine) Status() core.EngineStatus

func (*CoreCEngine) Stop

func (e *CoreCEngine) Stop() error

func (*CoreCEngine) Subscribe

func (e *CoreCEngine) Subscribe(filter string) (ch <-chan core.DataPoint, unsub func())

func (*CoreCEngine) SubscribeWithBuffer

func (e *CoreCEngine) SubscribeWithBuffer(filter string, size int) (ch <-chan core.DataPoint, unsub func())

SubscribeWithBuffer is like Subscribe but lets the caller choose the subscriber channel buffer size.

func (*CoreCEngine) Suspend

func (e *CoreCEngine) Suspend() error

func (*CoreCEngine) WriteTag

func (e *CoreCEngine) WriteTag(ctx context.Context, cmd core.WriteCommand) (*core.WriteResult, error)

type DataBus

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

DataBus is the internal data channel that connects drivers to the processing pipeline. It uses Go channels for high-performance, lock-free data flow.

func NewDataBus

func NewDataBus(bufferSize int) *DataBus

NewDataBus creates a new DataBus with the given buffer size.

func (*DataBus) Broadcast

func (b *DataBus) Broadcast(point core.DataPoint)

Broadcast sends a DataPoint to all subscribers.

func (*DataBus) Channel

func (b *DataBus) Channel() <-chan core.DataPoint

Channel returns the main data channel for consumption.

func (*DataBus) Close

func (b *DataBus) Close()

Close closes the data bus.

func (*DataBus) Dropped

func (b *DataBus) Dropped() int64

Dropped returns the total number of messages dropped due to slow subscribers.

func (*DataBus) Push

func (b *DataBus) Push(point core.DataPoint)

Push sends a DataPoint into the bus. It is safe to call Push concurrently with Close; a Push that races with Close is silently dropped instead of panicking.

func (*DataBus) PushDropped

func (b *DataBus) PushDropped() int64

PushDropped returns the number of messages evicted from the main channel because the bus buffer was full (producer faster than consumer).

func (*DataBus) Subscribe

func (b *DataBus) Subscribe(filter string) (events <-chan core.DataPoint, unsub func())

Subscribe creates a new subscriber channel.

func (*DataBus) SubscribeWithBuffer

func (b *DataBus) SubscribeWithBuffer(filter string, size int) (events <-chan core.DataPoint, unsub func())

SubscribeWithBuffer is like Subscribe but lets the caller choose the subscriber channel buffer size. size <=0 falls back to DefaultSubscriberBuffer.

type Discovery added in v0.0.2

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

Discovery manages topology auto-discovery via MQTT heartbeats. Each broker gets its own lightweight MQTT client that publishes the node's identity and subscribes to other nodes' heartbeats.

func NewDiscovery added in v0.0.2

func NewDiscovery(node core.NodeConfig, brokers []brokerEndpoint, addTransport func(core.TransportConfig) error) *Discovery

NewDiscovery creates a discovery module. brokers lists each broker this node connects to and what endpoints it advertises on each.

func (*Discovery) GetDiscoveredNodes added in v0.0.2

func (d *Discovery) GetDiscoveredNodes() []nodeInfo

GetDiscoveredNodes returns a snapshot of all known nodes.

func (*Discovery) Start added in v0.0.2

func (d *Discovery) Start(ctx context.Context) error

Start connects to each broker, subscribes to the discovery topic, and begins broadcasting heartbeats.

func (*Discovery) Stop added in v0.0.2

func (d *Discovery) Stop()

Stop disconnects all broker clients and waits for goroutines to exit.

type LatestCache

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

LatestCache maintains the most recent value for each tag. It is sharded by driver name to reduce mutex contention when multiple processing workers update the cache concurrently.

func NewLatestCache

func NewLatestCache() *LatestCache

NewLatestCache creates a new LatestCache.

func (*LatestCache) Clear

func (c *LatestCache) Clear()

Clear removes all cached data.

func (*LatestCache) Get

func (c *LatestCache) Get(driver, tag string) (core.DataPoint, bool)

Get retrieves the latest value for a specific driver and tag.

func (*LatestCache) GetByDriver

func (c *LatestCache) GetByDriver(driver string) map[string]core.DataPoint

GetByDriver retrieves all latest values for a driver. It returns an atomic snapshot that is reused across calls when the data hasn't changed, avoiding a full map copy.

func (*LatestCache) Update

func (c *LatestCache) Update(point core.DataPoint)

Update stores or updates a DataPoint in the cache.

type OfflineBuffer added in v0.0.2

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

OfflineBuffer stores failed publish batches to disk so they can be replayed after the transport recovers. Each batch is written as a numbered JSON file inside the configured directory, making the storage crash-safe (each file is atomically renamed into place) and easy to inspect or purge manually.

The buffer is bounded by maxEntries; when full, the oldest entries are evicted to make room for newer ones (newer data is more valuable in real-time industrial monitoring).

func NewOfflineBuffer added in v0.0.2

func NewOfflineBuffer(dir string, maxEntries int) (*OfflineBuffer, error)

NewOfflineBuffer creates an OfflineBuffer rooted at dir. If dir does not exist it is created. maxEntries <= 0 defaults to 10000.

func (*OfflineBuffer) Close added in v0.0.2

func (ob *OfflineBuffer) Close() error

Close is a no-op for the file-based buffer; files remain on disk for replay after restart.

func (*OfflineBuffer) Drain added in v0.0.2

func (ob *OfflineBuffer) Drain(tryPublish func([]core.DataPoint) error) (int, error)

Drain attempts to replay all buffered batches. For each batch, it calls tryPublish; if that returns nil the batch is deleted from disk, otherwise draining stops (the transport is likely still down). Returns the number of batches successfully drained.

func (*OfflineBuffer) Len added in v0.0.2

func (ob *OfflineBuffer) Len() int

Len returns the number of buffered batches currently on disk.

func (*OfflineBuffer) Push added in v0.0.2

func (ob *OfflineBuffer) Push(points []core.DataPoint, source string) error

Push writes a failed batch to disk. If the buffer is full, the oldest entries are evicted first.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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