Documentation
¶
Index ¶
- type HiveModuleBase
- func (m *HiveModuleBase) ForwardNotification(notif *msg.NotificationMessage)
- func (m *HiveModuleBase) ForwardRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) (err error)
- func (m *HiveModuleBase) ForwardRequestWait(req *msg.RequestMessage) (resp *msg.ResponseMessage, err error)
- func (m *HiveModuleBase) GetModuleID() string
- func (m *HiveModuleBase) GetSink() msg.RequestHandler
- func (m *HiveModuleBase) HandleNotification(notif *msg.NotificationMessage)
- func (m *HiveModuleBase) HandleRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) (err error)
- func (m *HiveModuleBase) Rpc(operation, thingID, name string, input any, output any) error
- func (m *HiveModuleBase) SetAppNotificationHook(hook msg.NotificationHandler)
- func (m *HiveModuleBase) SetAppRequestHook(hook msg.RequestHandler)
- func (m *HiveModuleBase) SetNotificationSink(consumer msg.NotificationHandler)
- func (m *HiveModuleBase) SetRequestSink(sink msg.RequestHandler)
- func (m *HiveModuleBase) SetTimeout(rpcTimeout time.Duration)
- func (co *HiveModuleBase) Start() error
- func (co *HiveModuleBase) Stop()
- type IHiveModule
- type ModuleEnv
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HiveModuleBase ¶
type HiveModuleBase struct {
// contains filtered or unexported fields
}
HiveModuleBase implements the boilerplate of running a module. This implements the IHiveModule interface. - define and store properties - manage message sinks - generate TD - send notifications for property changes and events
Call Init(moduleID,sink) after construction
func NewHiveModuleBase ¶
func NewHiveModuleBase(moduleID string, timeout time.Duration) HiveModuleBase
Create a new module
moduleID identifies the parent module rpcTimeout for forwarding request and waiting for the result
func (*HiveModuleBase) ForwardNotification ¶
func (m *HiveModuleBase) ForwardNotification(notif *msg.NotificationMessage)
ForwardNotification (output) passes received notifications to a registered hook and send it to the a registered sink.
Note that only handleNotification passes it to the appNotificationHook.
If none is registered this does nothing. note that the handler is not the downstream sink but the upstream consumer.
func (*HiveModuleBase) ForwardRequest ¶
func (m *HiveModuleBase) ForwardRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) (err error)
ForwardRequest passes the request to the sink's HandleRequest method. If no sink os configured this returns an error This assigns a request correlationID if none is set.
func (*HiveModuleBase) ForwardRequestWait ¶
func (m *HiveModuleBase) ForwardRequestWait( req *msg.RequestMessage) (resp *msg.ResponseMessage, err error)
ForwardRequestWait is a helper function to pass a request to the sink and wait for a response. If no sink os configured this returns an error. If the response contains an error, that error is also returned.
func (*HiveModuleBase) GetModuleID ¶
func (m *HiveModuleBase) GetModuleID() string
GetSink returns the module's ID
func (*HiveModuleBase) GetSink ¶
func (m *HiveModuleBase) GetSink() msg.RequestHandler
GetSink returns the module's request sink
func (*HiveModuleBase) HandleNotification ¶
func (m *HiveModuleBase) HandleNotification(notif *msg.NotificationMessage)
HandleNotification receives an incoming notification from a producer.
The default behavior is to passes the notification to the registered hook and send it upstream to the registered notification handler, if set.
Applications that consume notifications should use SetNotificationHook to register its handler as it leaves the chain intact..
func (*HiveModuleBase) HandleRequest ¶
func (m *HiveModuleBase) HandleRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) (err error)
HandleRequest handles request for this module.
This is just the default implementation. Applications can either set an appRequestHandler or a module can override HandleRequest to do its own thing.
Modules that override HandleRequest should first handle the request itself and only hand it over to this base method when there is nothing for them to do. This method simply forwards the request if no request handler hook is set.
func (*HiveModuleBase) Rpc ¶
func (m *HiveModuleBase) Rpc( operation, thingID, name string, input any, output any) error
Rpc is a convenience function to create and send a request message and decode the a response. This returns an error if the request fails or if the response contains an error
operation is the WoT operation to send thingID is the Thing to address name is the operation name as defined in the TD input are optional input parameters or nil if none output is a pointer to the struct where the result will be decoded
func (*HiveModuleBase) SetAppNotificationHook ¶
func (m *HiveModuleBase) SetAppNotificationHook(hook msg.NotificationHandler)
Set the hook to invoke with received notifications
func (*HiveModuleBase) SetAppRequestHook ¶
func (m *HiveModuleBase) SetAppRequestHook(hook msg.RequestHandler)
Set the hook to invoke when requests are received by this module. The handler must either handle the request or forward it down the chain.
This hook is intended to customize behavior without having to replace the module. This comes in handy to handle requests by a simple agent without having to implement a separate module. Another use-case is to trace requests for logging or other monitoring tasks.
Failure to forward it without calling replyTo, or returning an error, results in the request being lost and the caller waiting for a response until timeout.
func (*HiveModuleBase) SetNotificationSink ¶
func (m *HiveModuleBase) SetNotificationSink(consumer msg.NotificationHandler)
Set the handler that will receive notifications emitted by this module
func (*HiveModuleBase) SetRequestSink ¶
func (m *HiveModuleBase) SetRequestSink(sink msg.RequestHandler)
SetRequestSink sets the producer that will handle requests for this consumer and register this module as the receive of notifications from the module.
producer is the sink that will handle requests and send notifications
func (*HiveModuleBase) SetTimeout ¶
func (m *HiveModuleBase) SetTimeout(rpcTimeout time.Duration)
// SetTimeout changes the timeout when waiting for result.
func (*HiveModuleBase) Start ¶
func (co *HiveModuleBase) Start() error
Start the consumer module .. owning struct must implement this
func (*HiveModuleBase) Stop ¶
func (co *HiveModuleBase) Stop()
Stop the consumer module .. owning struct must implement this
type IHiveModule ¶
type IHiveModule interface {
// HandleRequest - invoked by consumer to this producer.
// [producer] processes or forwards a request downstream to other producers.
//
// When the request is for this module then the module processes the request and
// invokes replyTo with the response. ReplyTo is invoked asynchronously before
// or after returning.
//
// When the request is not for this producer then it is forwarded:
//
// 1. By default modules forward unhandled requests to their request sink.
// Flow: consumer -> module -[rsink]-> producer
//
// 2. If the module is a transport client: the request is transported to the server,
// and the server passes it to the producer that is registered as its sink.
// Flow: consumer -[rsink]-> tp-client -> tp-server -[rsink]-> producer
//
// 3. If the module is a transport server or server connection then the request is
// transported to the remote client. The client passes it to its registered sink.
// This sink should be a producer that can handle the request.
// (In this case the consumer is a process running on the server)
// Flow: consumer -[rsink]-> tp-server -> tp-client -[rsink]-> producer
//
// Note this is the use-case where a device uses connection reversal to connect
// to a server, like a hub or gateway, to serve IoT data. The gateway acts
// as a consumer to the producer connected to the client.
//
//
// A middleware module can intercept the response by forwarding the request downstream
// while providing its own handler as the replyTo. This handler then forwards the response
// to the original replyTo endpoint.
//
// This returns an error if the provided replyTo will not be able to receive a response.
HandleRequest(request *msg.RequestMessage, replyTo msg.ResponseHandler) error
// Handle the notification received from a producer.
// The default behavior is to forward it upstream to the handler set with SetNotificationSink.
HandleNotification(notif *msg.NotificationMessage)
// SetAppRequestHook sets the handler that receives unhandled requests that pass through
// this module.
// The handler decides if it can handle the request and should forward the request if it
// cannot be handled.
SetAppRequestHook(hook msg.RequestHandler)
// Set the consumer of notifications emitted by this module (acting as a producer)
// Intended to create a chain of notifications from producer to consumer.
//
// This can be invoked before or after Start()
SetNotificationSink(consumer msg.NotificationHandler)
// SetRequestSink sets the handler of requests emitted by this module.
//
// This can be invoked before or after Start() to allow for live rewiring of the
// module chain.
SetRequestSink(sink msg.RequestHandler)
// Start readies the module for use.
// Intended for modulues to initialize resources
Start() error
// Stop halts module operation and releases resources.
// Intended for modulues to free resources
Stop()
}
The HiveOT module interface Anything that accepts requests can be a module, including clients and servers. This interface is the most basic module interface.
Directories
¶
| Path | Synopsis |
|---|---|
|
package authn with admin service messaging definitions
|
package authn with admin service messaging definitions |
|
pkg
Package authnclient with administration facing methods
|
Package authnclient with administration facing methods |
|
Package bucketstore is set of modules for data storage.
|
Package bucketstore is set of modules for data storage. |
|
cmd
command
|
|
|
internal/service
package service with the bucket store module code
|
package service with the bucket store module code |
|
internal/stores/kvbtree
Package kvbtree
|
Package kvbtree |
|
test
Package certs with managing certificates for testing
|
Package certs with managing certificates for testing |
|
internal/msgserver
Package internal with service methods
|
Package internal with service methods |
|
internal
Package historyserver with methods for storage, iteration and querying of thing values
|
Package historyserver with methods for storage, iteration and querying of thing values |
|
package transport with http server and TLSClient apis
|
package transport with http server and TLSClient apis |
|
clients
Package clients containing all clients.
|
Package clients containing all clients. |
|
discovery/internal/client
Package discodiscoclientvery with client for DNS-SD service discovery
|
Package discodiscoclientvery with client for DNS-SD service discovery |
|
discovery/internal/server
Package internal to publish Hub services for discovery
|
Package internal to publish Hub services for discovery |
|
httptransport/internal/client
Package internal with a TLS client helper supporting certificate, JWT or Basic authentication
|
Package internal with a TLS client helper supporting certificate, JWT or Basic authentication |