service

package
v0.0.0-...-147f0cf Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PropertiesBucketName = "properties"

Variables

This section is empty.

Functions

This section is empty.

Types

type AddHistory

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

AddHistory adds events and actions of any Thing

func NewAddHistory

func NewAddHistory(
	store buckets.IBucketStore,
	retentionMgr *ManageHistory,
	onAddedValue func(value *thing.ThingValue, isAction bool)) *AddHistory

NewAddHistory provides the capability to add values to Thing history buckets

store with a bucket for each Thing
retentionMgr is optional and used to apply constraints to the events to add
onAddedValue is optional and invoked after the value is added to the bucket.

func (*AddHistory) AddAction

func (svc *AddHistory) AddAction(actionValue *thing.ThingValue) error

AddAction adds a Thing action with the given name and value to the action history value is json encoded. Optionally include a 'created' ISO8601 timestamp

func (*AddHistory) AddEvent

func (svc *AddHistory) AddEvent(eventValue *thing.ThingValue) error

AddEvent adds an event to the event history Only events that pass retention rules are stored. If the event has no created time, it will be set to 'now'

func (*AddHistory) AddEvents

func (svc *AddHistory) AddEvents(eventValues []*thing.ThingValue) (err error)

AddEvents provides a bulk-add of events to the event history Events that are invalid are skipped.

type GetPropertiesFunc

type GetPropertiesFunc func(thingAddr string, names []string) []*thing.ThingValue

GetPropertiesFunc is a callback function to retrieve latest properties of a Thing latest properties are stored separate from the history.

type HistoryService

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

HistoryService provides storage for action and event history using the bucket store Each Thing has a bucket with events and actions. This implements the IHistoryService interface

func NewHistoryService

func NewHistoryService(
	hc *hubclient.HubClient, store buckets.IBucketStore) *HistoryService

NewHistoryService creates a new instance for the history service using the given storage bucket.

config optional configuration or nil to use defaults
store contains an opened bucket store to use.
hc connection with the hub

func (*HistoryService) GetAddHistory

func (svc *HistoryService) GetAddHistory() *AddHistory

GetAddHistory returns the handler for adding history. Intended for testing.

func (*HistoryService) Start

func (svc *HistoryService) Start() (err error)

Start using the history service This will open the store and panic if the store cannot be opened.

func (*HistoryService) Stop

func (svc *HistoryService) Stop() error

Stop using the history service and release resources

type LatestPropertiesStore

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

LatestPropertiesStore holds the most recent property and event values of things. It persists a record for each Thing containing a map of the most recent properties.

func NewPropertiesStore

func NewPropertiesStore(storage buckets.IBucket) *LatestPropertiesStore

NewPropertiesStore creates a new instance of the storage for Thing's latest property values

func (*LatestPropertiesStore) GetProperties

func (srv *LatestPropertiesStore) GetProperties(thingAddr string, names []string) (propList []*thing.ThingValue)

GetProperties returns the latest value of thing properties and events as a list of properties

 thingAddr is the address the thing is reachable at. Usually the agentID/thingID.
	names is optional and can be used to limit the resulting array of values. Use nil to get all properties.

func (*LatestPropertiesStore) HandleAddValue

func (srv *LatestPropertiesStore) HandleAddValue(event *thing.ThingValue, isAction bool)

HandleAddValue is the handler of update to a thing's event/property values used to update the properties cache. isAction indicates the value is an action.

func (*LatestPropertiesStore) LoadProps

func (srv *LatestPropertiesStore) LoadProps(thingAddr string) (found bool)

LoadProps loads the cached value of a Thing properties on demand. To be invoked before reading and writing Thing properties to ensure the cache is loaded. This immediately returns if a record for the Thing was already loaded. Returns true if a cache value exists, false if the thing address was added to the cache

func (*LatestPropertiesStore) SaveChanges

func (srv *LatestPropertiesStore) SaveChanges() (err error)

SaveChanges writes modified cached properties to the underlying store. this returns the last encountered error, although writing is attempted for all changes

type ManageHistory

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

ManageHistory provides the capability to manage how history is captured

func NewManageRetention

func NewManageRetention(
	hc *hubclient.HubClient, defaultRules historyapi.RetentionRuleSet) *ManageHistory

NewManageRetention creates a new instance that implements IManageRetention

defaultRules with rules from config

func (*ManageHistory) GetRetentionRule

GetRetentionRule returns the first retention rule that applies to the given value. This returns nil without error if no retention rules are defined.

eventName whose retention to return

func (*ManageHistory) GetRetentionRules

func (svc *ManageHistory) GetRetentionRules() (*historyapi.GetRetentionRulesResp, error)

GetRetentionRules returns all retention rules

func (*ManageHistory) SetRetentionRules

func (svc *ManageHistory) SetRetentionRules(
	ctx hubclient.ServiceContext, args *historyapi.SetRetentionRulesArgs) error

SetRetentionRules updates the retention rules set

func (*ManageHistory) Start

func (svc *ManageHistory) Start() (err error)

Start the history management handler. This loads the retention configuration

func (*ManageHistory) Stop

func (svc *ManageHistory) Stop()

Stop using the retention manager

type ReadHistoryService

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

ReadHistoryService provides read access to the history of thing values.

func StartReadHistoryService

func StartReadHistoryService(
	hc *hubclient.HubClient, bucketStore buckets.IBucketStore, getPropertiesFunc GetPropertiesFunc,
) (svc *ReadHistoryService, err error)

StartReadHistoryService starts the capability to read from a thing's history

hc with the message bus connection. Its ID will be used as the agentID that provides the capability.
thingBucket is the open bucket used to store history data
getPropertiesFunc implements the aggregation of the Thing's most recent property values

func (*ReadHistoryService) First

First returns the oldest value in the history

func (*ReadHistoryService) GetCursor

GetCursor returns an iterator for ThingValues containing a TD document The inactivity lifespan is currently fixed to 1 minute.

func (*ReadHistoryService) GetLatest

GetLatest returns the most recent property and event values of the Thing. Latest Properties are tracked in a 'latest' record which holds a map of propertyName:ThingValue records

providing 'names' can speed up read access significantly

func (*ReadHistoryService) Last

Last positions the cursor at the last key in the ordered list

func (*ReadHistoryService) Next

Next moves the cursor to the next key from the current cursor First() or Seek must have been called first.

func (*ReadHistoryService) NextN

NextN moves the cursor to the next N places from the current cursor and return a list with N values in incremental time order. itemsRemaining is false if the iterator has reached the end. Intended to speed up with batch iterations over rpc.

func (*ReadHistoryService) Prev

Prev moves the cursor to the previous key from the current cursor Last() or Seek must have been called first.

func (*ReadHistoryService) PrevN

PrevN moves the cursor back N places from the current cursor and return a list with N values in decremental time order. itemsRemaining is true if the iterator has reached the beginning Intended to speed up with batch iterations over rpc.

func (*ReadHistoryService) Release

Release closes the bucket and cursor This invalidates all values obtained from the cursor

func (*ReadHistoryService) Seek

Seek positions the cursor at the given searchKey and corresponding value. If the key is not found, the next key is returned.

func (*ReadHistoryService) Stop

func (svc *ReadHistoryService) Stop()

Stop the read history capability this unsubscribes from requests and stops the cursor cleanup task.

type ThingPropertyValues

type ThingPropertyValues map[string]*thing.ThingValue

ThingPropertyValues is a map of Thing property name to value

Jump to

Keyboard shortcuts

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