overflow_probes/service/CentralService.go

64 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() {
cdr.RegisterType(reflect.TypeOf((*CentralService)(nil)), &cda.ComponentAnnotation{})
}
2017-12-08 08:31:45 +00:00
type CentralService struct {
2017-12-08 12:01:38 +00:00
CentralClients map[string]oogwc.Client
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
}