overflow_probes/service/CentralService.go

66 lines
1.5 KiB
Go
Raw Normal View History

2017-12-08 08:31:45 +00:00
package service
import (
2017-12-08 12:01:38 +00:00
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
2017-12-08 08:31:45 +00:00
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
)
2017-12-08 12:01:38 +00:00
func init() {
2018-03-15 13:52:23 +00:00
cdr.RegisterType(reflect.TypeOf((*CentralService)(nil)))
2017-12-08 12:01:38 +00:00
}
2017-12-08 08:31:45 +00:00
type CentralService struct {
2018-03-15 13:52:23 +00:00
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
2017-12-08 15:59:00 +00:00
CentralClients map[string]oogwc.Client `annotation:"@Resource()"`
2017-12-08 08:31:45 +00:00
}
func (cs *CentralService) PutClient(entryPath string, c oogwc.Client) {
2017-12-08 12:01:38 +00:00
cs.CentralClients[entryPath] = c
2017-12-08 08:31:45 +00:00
}
func (cs *CentralService) Call(entryPath string, result interface{}, method string, params ...interface{}) error {
c := cs.GetClient(entryPath)
return c.Call(result, method, params...)
}
func (cs *CentralService) Send(entryPath string, method string, params ...interface{}) error {
c := cs.GetClient(entryPath)
return c.Send(method, params...)
}
func (cs *CentralService) GetClient(entryPath string) oogwc.Client {
2017-12-08 12:01:38 +00:00
return cs.CentralClients[entryPath]
2017-12-08 08:31:45 +00:00
}
func (cs *CentralService) CheckClient(entryPath string) bool {
2017-12-08 12:01:38 +00:00
c, ok := cs.CentralClients[entryPath]
2017-12-08 08:31:45 +00:00
if !ok || nil == c {
return false
}
return true
}
func (cs *CentralService) Connect(entryPath string) error {
// var c oogwc.Client
// switch entryPath {
// case oocmp.HTTPEntry_Probe:
// c = oopccp.NewClient()
// case oocmp.HTTPEntry_Data:
// c = oopccd.NewClient()
// case oocmp.HTTPEntry_File:
// c = oopccf.NewClient()
// default:
// return fmt.Errorf("Gateway entry[%s] is not exist", entryPath)
// }
// cs.clients[entryPath] = c
return nil
}