internal

package
v0.0.0-...-1e91e80 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package historyserver with methods for storage, iteration and querying of thing values

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HistoryServiceImpl

type HistoryServiceImpl struct {
	// this is a service
	*thing.ExposedThing
	// contains filtered or unexported fields
}

HistoryServiceImpl provides storage for request and notification history.

Requests received are forwarded to the registered sink and stored if they pass the filter. Storage is done using the NotificationMessage envelope. Similarly, notifications are forwarded as-is and stored if they pass the notification filter.

Each Thing has a bucket with events and actions. This implements the IHistoryService and IHiveCell interface

func NewHistoryServiceImpl

func NewHistoryServiceImpl(config history.HistoryConfig) (*HistoryServiceImpl, error)

NewHistoryServiceImpl creates a ready-to-use instance for the history service using the given configuration. Call Start to publish the TD.

A configuration can be created using: config.NewHistoryConfig(storeDirectory, backend)

func (*HistoryServiceImpl) AddValue

func (svc *HistoryServiceImpl) AddValue(value *msg.NotificationMessage) error

AddValue adds a Thing value from a sender to the action history The caller must validate the SenderID in the tv.

func (*HistoryServiceImpl) CreateCursor

func (svc *HistoryServiceImpl) CreateCursor(clientID string, thingID string, affName string) (cursorKey string, err error)

CreateCursor returns a new iterator for history ThingMessage objects.

Unused cursors have a limited lifespan after which they are discarded. The default of the store is set to 1 minute. It is better to release the cursor after use.

clientID is the owner that must match iteration requests
thingID is the Thing whose data to iteration
affName of affordance to filter on or "" for any value from the thing

func (*HistoryServiceImpl) First

func (svc *HistoryServiceImpl) First(clientID string, cursorKey string) (
	value *msg.NotificationMessage, valid bool, err error)

First returns the oldest value in the history

If an affordance name is provided it forwards to the first value for that affordance.

clientID must match the owner of the cursor
cursorKey is the cursor to iterate.
affName is the optional affordance name to search for, or "" for any

func (*HistoryServiceImpl) HandleNotification

func (svc *HistoryServiceImpl) HandleNotification(notif *msg.NotificationMessage)

Forward notifications to the registered sink and record it if they pass the filter.

func (*HistoryServiceImpl) HandleRequest

func (svc *HistoryServiceImpl) HandleRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) (err error)

HandleRequest handles incoming requests for reading the history

func (*HistoryServiceImpl) Last

func (svc *HistoryServiceImpl) Last(clientID string, cursorKey string) (
	value *msg.NotificationMessage, valid bool, err error)

Last positions the cursor at the last key in the ordered list If an affordance name is provided then it rewinds to the first available value for that affordance.

func (*HistoryServiceImpl) Next

func (svc *HistoryServiceImpl) Next(clientID string, cursorKey string) (
	value *msg.NotificationMessage, valid bool, err error)

Next moves the cursor to the next key from the current cursor. If affName is provided then continue iterating until the affordance name matches. First() or Seek must have been called first. This returns an error if the cursor is not found.

func (*HistoryServiceImpl) NextN

func (svc *HistoryServiceImpl) NextN(
	clientID string, cursorKey string, until time.Time, limit int) (
	valueList []*msg.NotificationMessage, itemsRemaining bool, err error)

NextN moves the cursor to the next N places from the current cursor and return a list with N values in incremental time order.

This returns the list with values and itemsRemaining, which is false if the iterator has reached the end. Intended to speed up with batch iterations over rpc.

func (*HistoryServiceImpl) Prev

func (svc *HistoryServiceImpl) Prev(clientID string, cursorKey string) (
	value *msg.NotificationMessage, valid bool, err error)

Prev moves the cursor to the previous key from the current cursor Last() or Seek must have been called first. This returns an error if the cursor is not found.

func (*HistoryServiceImpl) PrevN

func (svc *HistoryServiceImpl) PrevN(
	clientID string, cursorKey string, until time.Time, limit int) (
	valueList []*msg.NotificationMessage, itemsRemaining bool, err error)

PrevN moves the cursor to the previous N places from the current cursor and return a list with N values in reverse time order.

itemsRemaining returns false if the iterator has reached the beginning. Intended to speed up with batch iterations over rpc.

func (*HistoryServiceImpl) ReadHistory

func (svc *HistoryServiceImpl) ReadHistory(
	thingID string, affName string, timestamp time.Time, durationSec int, limit int) (
	values []*msg.NotificationMessage, itemsRemaining bool, err error)

ReadHistory returns the history for the given thingID, name and time range

func (*HistoryServiceImpl) ReleaseCursor

func (svc *HistoryServiceImpl) ReleaseCursor(clientID string, cursorKey string) error

ReleaseCursor frees the cursor resources. This invalidates all values obtained from the cursor

func (*HistoryServiceImpl) Seek

func (svc *HistoryServiceImpl) Seek(
	clientID string, cursorKey string, ts time.Time) (
	value *msg.NotificationMessage, valid bool, err error)

Seek positions the cursor at the given time stamp and affordance name. If the key is not found, the next key is returned. This returns an error if the cursor is not valid.

func (*HistoryServiceImpl) Start

func (svc *HistoryServiceImpl) Start()

Write TD when ready

func (*HistoryServiceImpl) Stop

func (svc *HistoryServiceImpl) Stop()

Stop using the history service and release resources

func (*HistoryServiceImpl) StoreNotification

func (svc *HistoryServiceImpl) StoreNotification(notif *msg.NotificationMessage) error

Store notifications for later retrieval

func (*HistoryServiceImpl) StoreRequest

func (svc *HistoryServiceImpl) StoreRequest(req *msg.RequestMessage) error

Store requests for later retrieval

Jump to

Keyboard shortcuts

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