bbgo_origin/pkg/bbgo/notifier.go

48 lines
1.3 KiB
Go
Raw Normal View History

2020-07-13 05:25:48 +00:00
package bbgo
2020-07-16 07:36:02 +00:00
type Notifier interface {
NotifyTo(channel, format string, args ...interface{})
Notify(format string, args ...interface{})
2020-07-16 07:36:02 +00:00
}
type NullNotifier struct{}
func (n *NullNotifier) NotifyTo(channel, format string, args ...interface{}) {}
2020-10-22 02:47:54 +00:00
func (n *NullNotifier) Notify(format string, args ...interface{}) {}
2020-10-22 02:54:03 +00:00
type Notifiability struct {
2020-10-27 01:24:59 +00:00
notifiers []Notifier
2020-10-27 01:38:29 +00:00
SessionChannelRouter *PatternChannelRouter
SymbolChannelRouter *PatternChannelRouter
ObjectChannelRouter *ObjectChannelRouter
2020-10-27 01:24:59 +00:00
}
func (m *Notifiability) RouteSymbol(symbol string) (channel string, ok bool) {
2020-10-27 01:38:29 +00:00
return m.SymbolChannelRouter.Route(symbol)
2020-10-27 01:24:59 +00:00
}
func (m *Notifiability) RouteSession(session string) (channel string, ok bool) {
2020-10-27 01:38:29 +00:00
return m.SessionChannelRouter.Route(session)
2020-10-27 01:24:59 +00:00
}
func (m *Notifiability) RouteObject(obj interface{}) (channel string, ok bool) {
2020-10-27 01:38:29 +00:00
return m.ObjectChannelRouter.Route(obj)
2020-10-22 02:54:03 +00:00
}
func (m *Notifiability) AddNotifier(notifier Notifier) {
m.notifiers = append(m.notifiers, notifier)
}
func (m *Notifiability) Notify(format string, args ...interface{}) {
2020-10-22 02:54:03 +00:00
for _, n := range m.notifiers {
n.Notify(format, args...)
2020-10-22 06:45:05 +00:00
}
}
func (m *Notifiability) NotifyTo(channel, format string, args ...interface{}) {
2020-10-22 06:45:05 +00:00
for _, n := range m.notifiers {
n.NotifyTo(channel, format, args...)
2020-10-22 02:54:03 +00:00
}
}