2020-07-13 05:25:48 +00:00
|
|
|
package bbgo
|
|
|
|
|
2020-07-16 07:36:02 +00:00
|
|
|
type Notifier interface {
|
2020-10-27 12:13:10 +00:00
|
|
|
NotifyTo(channel, format string, args ...interface{})
|
|
|
|
Notify(format string, args ...interface{})
|
2020-07-16 07:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type NullNotifier struct{}
|
|
|
|
|
2020-10-27 12:13:10 +00:00
|
|
|
func (n *NullNotifier) NotifyTo(channel, format string, args ...interface{}) {}
|
2020-10-22 02:47:54 +00:00
|
|
|
|
2020-10-27 12:13:10 +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)
|
|
|
|
}
|
|
|
|
|
2020-10-27 12:13:10 +00:00
|
|
|
func (m *Notifiability) Notify(format string, args ...interface{}) {
|
2020-10-22 02:54:03 +00:00
|
|
|
for _, n := range m.notifiers {
|
2020-10-27 12:13:10 +00:00
|
|
|
n.Notify(format, args...)
|
2020-10-22 06:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 12:13:10 +00:00
|
|
|
func (m *Notifiability) NotifyTo(channel, format string, args ...interface{}) {
|
2020-10-22 06:45:05 +00:00
|
|
|
for _, n := range m.notifiers {
|
2020-10-27 12:13:10 +00:00
|
|
|
n.NotifyTo(channel, format, args...)
|
2020-10-22 02:54:03 +00:00
|
|
|
}
|
|
|
|
}
|