Documentation
¶
Overview ¶
Package module with methods for storage, iteration and querying of thing values
Index ¶
- type HistoryModule
- func (svc *HistoryModule) AddValue(tv *msg.ThingValue) error
- func (svc *HistoryModule) CreateCursor(clientID string, thingID string, affName string) (cursorKey string, err error)
- func (svc *HistoryModule) First(clientID string, cursorKey string) (value *msg.ThingValue, valid bool, err error)
- func (m *HistoryModule) HandleNotification(notif *msg.NotificationMessage)
- func (m *HistoryModule) HandleRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) error
- func (svc *HistoryModule) Last(clientID string, cursorKey string) (tv *msg.ThingValue, valid bool, err error)
- func (svc *HistoryModule) Next(clientID string, cursorKey string) (tv *msg.ThingValue, valid bool, err error)
- func (svc *HistoryModule) NextN(clientID string, cursorKey string, until time.Time, limit int) (tvList []*msg.ThingValue, itemsRemaining bool, err error)
- func (svc *HistoryModule) Prev(clientID string, cursorKey string) (tv *msg.ThingValue, valid bool, err error)
- func (svc *HistoryModule) PrevN(clientID string, cursorKey string, until time.Time, limit int) (tvList []*msg.ThingValue, itemsRemaining bool, err error)
- func (svc *HistoryModule) ReadHistory(thingID string, affName string, timestamp time.Time, durationSec int, ...) (values []*msg.ThingValue, itemsRemaining bool, err error)
- func (svc *HistoryModule) ReleaseCursor(clientID string, cursorKey string) error
- func (svc *HistoryModule) Seek(clientID string, cursorKey string, ts time.Time) (tv *msg.ThingValue, valid bool, err error)
- func (m *HistoryModule) Start(yamlConfig string) (err error)
- func (m *HistoryModule) Stop()
- func (m *HistoryModule) StoreNotification(notif *msg.NotificationMessage) error
- func (m *HistoryModule) StoreRequest(req *msg.RequestMessage) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HistoryModule ¶
type HistoryModule struct {
modules.HiveModuleBase
// contains filtered or unexported fields
}
HistoryService provides storage for request and notification history.
Requests received are forwarded to the registered sink and stored if they pass the filter. 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 interface
func NewHistoryModule ¶
func NewHistoryModule(storeDirectory string, backend string) *HistoryModule
NewHistoryModule creates a new instance for the history module using the given storage bucket.
func (*HistoryModule) AddValue ¶
func (svc *HistoryModule) AddValue(tv *msg.ThingValue) error
AddValue adds a Thing value from a sender to the action history The caller must validate the SenderID in the tv.
func (*HistoryModule) CreateCursor ¶
func (svc *HistoryModule) 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 (*HistoryModule) First ¶
func (svc *HistoryModule) First(clientID string, cursorKey string) ( value *msg.ThingValue, 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 (*HistoryModule) HandleNotification ¶
func (m *HistoryModule) HandleNotification(notif *msg.NotificationMessage)
Forward notifications to the registered sink and record it if they pass the filter.
func (*HistoryModule) HandleRequest ¶
func (m *HistoryModule) HandleRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) error
HandleRequest handles request for this module. If not a module request then record it in the history store if it passes the filters and forward the request to the registered sink.
func (*HistoryModule) Last ¶
func (svc *HistoryModule) Last(clientID string, cursorKey string) ( tv *msg.ThingValue, 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 (*HistoryModule) Next ¶
func (svc *HistoryModule) Next(clientID string, cursorKey string) ( tv *msg.ThingValue, 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 (*HistoryModule) NextN ¶
func (svc *HistoryModule) NextN( clientID string, cursorKey string, until time.Time, limit int) ( tvList []*msg.ThingValue, 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 (*HistoryModule) Prev ¶
func (svc *HistoryModule) Prev(clientID string, cursorKey string) ( tv *msg.ThingValue, 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 (*HistoryModule) PrevN ¶
func (svc *HistoryModule) PrevN( clientID string, cursorKey string, until time.Time, limit int) ( tvList []*msg.ThingValue, 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 (*HistoryModule) ReadHistory ¶
func (svc *HistoryModule) ReadHistory( thingID string, affName string, timestamp time.Time, durationSec int, limit int) ( values []*msg.ThingValue, itemsRemaining bool, err error)
ReadHistory returns the history for the given thingID, name and time range
func (*HistoryModule) ReleaseCursor ¶
func (svc *HistoryModule) ReleaseCursor(clientID string, cursorKey string) error
ReleaseCursor frees the cursor resources. This invalidates all values obtained from the cursor
func (*HistoryModule) Seek ¶
func (svc *HistoryModule) Seek( clientID string, cursorKey string, ts time.Time) ( tv *msg.ThingValue, 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 (*HistoryModule) Start ¶
func (m *HistoryModule) Start(yamlConfig string) (err error)
Start the history module and open the store this loads the filters
func (*HistoryModule) Stop ¶
func (m *HistoryModule) Stop()
Stop using the history service and release resources
func (*HistoryModule) StoreNotification ¶
func (m *HistoryModule) StoreNotification(notif *msg.NotificationMessage) error
Store notifications for later retrieval
func (*HistoryModule) StoreRequest ¶
func (m *HistoryModule) StoreRequest(req *msg.RequestMessage) error
Store notifications for later retrieval