Documentation ¶
Index ¶
- Constants
- Variables
- func Equal(v1, v2 *Message) bool
- func StartRemote(controller *Controller, conn net.Conn, readTimeout time.Duration) (context.Context, context.CancelFunc)
- type BaseHandler
- func (s *BaseHandler) Dependencies() []string
- func (s *BaseHandler) HandleChannelEvent(event interface{}, controller *Controller) error
- func (s *BaseHandler) HandleMessage(message *Message, controller *Controller) error
- func (s *BaseHandler) HandleTimerEvent(tick time.Time, controller *Controller) error
- func (s *BaseHandler) Setup(controller *Controller) (Interrupts, error)
- func (s *BaseHandler) String() string
- func (s *BaseHandler) Teardown()
- func (s *BaseHandler) Topics() []types.CommandType
- type Controller
- func (c *Controller) Pub(command *types.Command, receiverID uuid.UUID)
- func (c *Controller) PubMessage(message *Message, topics ...string)
- func (c *Controller) Reply(request *Message, replyType types.CommandType, replyContent interface{})
- func (c *Controller) Start(ctx context.Context, handlers []Handler)
- func (c *Controller) Sub(topics ...string) chan interface{}
- func (c *Controller) SubOnce(topics ...string) chan interface{}
- func (c *Controller) Unsub(subscription chan interface{})
- type Handler
- type Interrupts
- type Message
- type Remote
- type StatusHolder
- type Timer
Constants ¶
const BufferSize = 10
BufferSize is the size of channel buffers
const MaxIdleTime = 2 * time.Minute
MaxIdleTime is the maximum time to wait before closing a connection for inactivity
Variables ¶
var LoopbackID = uuid.Nil
LoopbackID is the id internal only messages are sent to
Functions ¶
func StartRemote ¶ added in v1.7.0
func StartRemote(controller *Controller, conn net.Conn, readTimeout time.Duration) (context.Context, context.CancelFunc)
Start starts a new remote and returns a context and a cancel function to stop remote operations. The returned context can also be closed by an error or a timeout in the send/receive routine
Types ¶
type BaseHandler ¶ added in v1.5.0
type BaseHandler struct{}
func (*BaseHandler) Dependencies ¶ added in v1.5.0
func (s *BaseHandler) Dependencies() []string
func (*BaseHandler) HandleChannelEvent ¶ added in v1.6.0
func (s *BaseHandler) HandleChannelEvent(event interface{}, controller *Controller) error
func (*BaseHandler) HandleMessage ¶ added in v1.5.0
func (s *BaseHandler) HandleMessage(message *Message, controller *Controller) error
func (*BaseHandler) HandleTimerEvent ¶ added in v1.5.0
func (s *BaseHandler) HandleTimerEvent(tick time.Time, controller *Controller) error
func (*BaseHandler) Setup ¶ added in v1.5.0
func (s *BaseHandler) Setup(controller *Controller) (Interrupts, error)
func (*BaseHandler) String ¶ added in v1.5.0
func (s *BaseHandler) String() string
func (*BaseHandler) Teardown ¶ added in v1.5.0
func (s *BaseHandler) Teardown()
func (*BaseHandler) Topics ¶ added in v1.5.0
func (s *BaseHandler) Topics() []types.CommandType
type Controller ¶
func (*Controller) Pub ¶
func (c *Controller) Pub(command *types.Command, receiverID uuid.UUID)
Pub publishes a Message composed by the given Command
func (*Controller) PubMessage ¶
func (c *Controller) PubMessage(message *Message, topics ...string)
PubMessage publishes a Message
func (*Controller) Reply ¶
func (c *Controller) Reply(request *Message, replyType types.CommandType, replyContent interface{})
Reply sends back a reply message
func (*Controller) Start ¶
func (c *Controller) Start(ctx context.Context, handlers []Handler)
Start starts every registered handler
func (*Controller) Sub ¶
func (c *Controller) Sub(topics ...string) chan interface{}
Sub Subscribes to one or more message types
func (*Controller) SubOnce ¶
func (c *Controller) SubOnce(topics ...string) chan interface{}
SubOnce subscribes to the first event of one of the given topics, then it deletes the subscription
func (*Controller) Unsub ¶ added in v1.7.0
func (c *Controller) Unsub(subscription chan interface{})
type Handler ¶
type Handler interface { fmt.Stringer Dependencies() []string Topics() []types.CommandType Setup(controller *Controller) (Interrupts, error) HandleMessage(message *Message, controller *Controller) error HandleTimerEvent(tick time.Time, controller *Controller) error HandleChannelEvent(event interface{}, controller *Controller) error Teardown() }
Handler is the interface that handles network messages and optionally can return a reply
type Interrupts ¶ added in v1.6.0
type Interrupts struct { Timer Timer Event <-chan interface{} }
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
func NewMessage ¶
NewMessage creates a new message
func ParseMessage ¶
ParseMessage handles incoming data and creates a Message object
func (*Message) ReceiverUUID ¶
ReceiverUUID returns the receiver identity
func (*Message) SenderUUID ¶
SenderUUID returns the sender identity
type Remote ¶
type Remote struct {
// contains filtered or unexported fields
}
Remote represents a remote endpoint, data are sent via Controller.Pub() and received directly by the interested Handler
type StatusHolder ¶
type StatusHolder struct {
// contains filtered or unexported fields
}
StatusHolder is a struct that stores status of an handler that needs to trigger status changes when something happens
func NewStatusHolder ¶
func NewStatusHolder(moduleName string) *StatusHolder
NewStatusHolder creates a StatusHolder
func (*StatusHolder) Edit ¶
func (s *StatusHolder) Edit(controller *Controller, editFunction func(interface{}) (interface{}, bool))
Edit the current status via editFunction
func (*StatusHolder) Get ¶ added in v1.9.0
func (s *StatusHolder) Get() interface{}
func (*StatusHolder) Set ¶
func (s *StatusHolder) Set(status interface{}, controller *Controller)
Set stores the status and emits it if it is changed
type Timer ¶ added in v1.4.0
type Timer struct {
// contains filtered or unexported fields
}
func NewEmptyTimer ¶ added in v1.4.0
func NewEmptyTimer() Timer
NewEmptyTimer creates a timer that does never fire
func NewStartupActionTimer ¶ added in v1.6.0
func NewStartupActionTimer() Timer
NewStartupActionTimer creates a timer that fires only at start and then never triggers again