overflow_gateway_probe/servlet/probe/subscriber_handlers.go
crusader ef1a27ab6c ing
2018-03-23 01:10:27 +09:00

41 lines
1.1 KiB
Go

package probe
import (
"git.loafle.net/commons_go/logging"
"git.loafle.net/commons_go/websocket_fasthttp/websocket"
oogws "git.loafle.net/overflow/overflow_gateway_websocket/servlet"
oogwsub "git.loafle.net/overflow/overflow_gateway_websocket/subscribe"
oos "git.loafle.net/overflow/overflow_subscriber"
)
func newSubscriberHandler(servletHandler oogws.ServletHandler) oogwsub.SubscriberHandler {
sh := &SubscriberHandlers{}
sh.ServletHandler = servletHandler
sh.Channel = cfg.Entry
return sh
}
type SubscriberHandlers struct {
oogwsub.SubscriberHandlers
}
func (sh *SubscriberHandlers) OnSubscribe(channel string, message oos.SubscribeMessage) {
switch message.TargetType {
case oos.PROBE:
for _, pid := range message.Targets {
if soc := sh.GetSocket(pid); nil != soc {
if err := soc.WriteMessageUseWriter(websocket.TextMessage, message.Message); nil != err {
logging.Logger().Errorf("OnSubscribe: write error %v", err)
}
}
}
default:
logging.Logger().Warnf("[PROBE] SubscriberHandler: Unknown TargetType %s", message.TargetType)
}
}
func (sh *SubscriberHandlers) Validate() {
sh.SubscriberHandlers.Validate()
}