Documentation ¶
Index ¶
- Constants
- type AddHistory
- type GetPropertiesFunc
- type HistoryService
- type LatestPropertiesStore
- func (srv *LatestPropertiesStore) GetProperties(thingAddr string, names []string) (propList []*thing.ThingValue)
- func (srv *LatestPropertiesStore) HandleAddValue(event *thing.ThingValue, isAction bool)
- func (srv *LatestPropertiesStore) LoadProps(thingAddr string) (found bool)
- func (srv *LatestPropertiesStore) SaveChanges() (err error)
- type ManageHistory
- func (svc *ManageHistory) GetRetentionRule(ctx hubclient.ServiceContext, args *historyapi.GetRetentionRuleArgs) (resp *historyapi.GetRetentionRuleResp, err error)
- func (svc *ManageHistory) GetRetentionRules() (*historyapi.GetRetentionRulesResp, error)
- func (svc *ManageHistory) SetRetentionRules(ctx hubclient.ServiceContext, args *historyapi.SetRetentionRulesArgs) error
- func (svc *ManageHistory) Start() (err error)
- func (svc *ManageHistory) Stop()
- type ReadHistoryService
- func (svc *ReadHistoryService) First(ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
- func (svc *ReadHistoryService) GetCursor(ctx hubclient.ServiceContext, args historyapi.GetCursorArgs) (*historyapi.GetCursorResp, error)
- func (svc *ReadHistoryService) GetLatest(ctx hubclient.ServiceContext, args *historyapi.GetLatestArgs) (*historyapi.GetLatestResp, error)
- func (svc *ReadHistoryService) Last(ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
- func (svc *ReadHistoryService) Next(ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
- func (svc *ReadHistoryService) NextN(ctx hubclient.ServiceContext, args historyapi.CursorNArgs) (*historyapi.CursorNResp, error)
- func (svc *ReadHistoryService) Prev(ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
- func (svc *ReadHistoryService) PrevN(ctx hubclient.ServiceContext, args historyapi.CursorNArgs) (*historyapi.CursorNResp, error)
- func (svc *ReadHistoryService) Release(ctx hubclient.ServiceContext, args historyapi.CursorReleaseArgs) error
- func (svc *ReadHistoryService) Seek(ctx hubclient.ServiceContext, args historyapi.CursorSeekArgs) (*historyapi.CursorSingleResp, error)
- func (svc *ReadHistoryService) Stop()
- type ThingPropertyValues
Constants ¶
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 ¶
func (svc *ManageHistory) GetRetentionRule( ctx hubclient.ServiceContext, args *historyapi.GetRetentionRuleArgs) (resp *historyapi.GetRetentionRuleResp, err error)
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
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 ¶
func (svc *ReadHistoryService) First( ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
First returns the oldest value in the history
func (*ReadHistoryService) GetCursor ¶
func (svc *ReadHistoryService) GetCursor( ctx hubclient.ServiceContext, args historyapi.GetCursorArgs) (*historyapi.GetCursorResp, error)
GetCursor returns an iterator for ThingValues containing a TD document The inactivity lifespan is currently fixed to 1 minute.
func (*ReadHistoryService) GetLatest ¶
func (svc *ReadHistoryService) GetLatest( ctx hubclient.ServiceContext, args *historyapi.GetLatestArgs) (*historyapi.GetLatestResp, error)
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 ¶
func (svc *ReadHistoryService) Last( ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
Last positions the cursor at the last key in the ordered list
func (*ReadHistoryService) Next ¶
func (svc *ReadHistoryService) Next( ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
Next moves the cursor to the next key from the current cursor First() or Seek must have been called first.
func (*ReadHistoryService) NextN ¶
func (svc *ReadHistoryService) NextN( ctx hubclient.ServiceContext, args historyapi.CursorNArgs) (*historyapi.CursorNResp, 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. itemsRemaining is false if the iterator has reached the end. Intended to speed up with batch iterations over rpc.
func (*ReadHistoryService) Prev ¶
func (svc *ReadHistoryService) Prev( ctx hubclient.ServiceContext, args historyapi.CursorArgs) (*historyapi.CursorSingleResp, error)
Prev moves the cursor to the previous key from the current cursor Last() or Seek must have been called first.
func (*ReadHistoryService) PrevN ¶
func (svc *ReadHistoryService) PrevN( ctx hubclient.ServiceContext, args historyapi.CursorNArgs) (*historyapi.CursorNResp, error)
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 ¶
func (svc *ReadHistoryService) Release( ctx hubclient.ServiceContext, args historyapi.CursorReleaseArgs) error
Release closes the bucket and cursor This invalidates all values obtained from the cursor
func (*ReadHistoryService) Seek ¶
func (svc *ReadHistoryService) Seek( ctx hubclient.ServiceContext, args historyapi.CursorSeekArgs) (*historyapi.CursorSingleResp, error)
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