From e4955d0250fffab6f2b973565800a8563d608835 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 3 May 2018 15:14:22 +0900 Subject: [PATCH] ing --- client/client.go | 33 +------------------ constants.go | 10 ++---- ...{ProbeClientService.go => ProbeService.go} | 19 +++++++++-- 3 files changed, 20 insertions(+), 42 deletions(-) rename service/{ProbeClientService.go => ProbeService.go} (59%) diff --git a/client/client.go b/client/client.go index 99f1463..ec1fc2e 100644 --- a/client/client.go +++ b/client/client.go @@ -4,45 +4,14 @@ import ( "fmt" "net/url" "path" - "reflect" "git.loafle.net/commons/logging-go" - crc "git.loafle.net/commons/rpc-go/client" - crpj "git.loafle.net/commons/rpc-go/protocol/json" csswc "git.loafle.net/commons/server-go/socket/web/client" occc "git.loafle.net/overflow/commons-go/config/container" occp "git.loafle.net/overflow/commons-go/config/probe" ) -func New(containerType occp.ContainerType, services []interface{}, orderedServices []reflect.Type, portNumber int) (*crc.Client, error) { - connector, err := newConnector(containerType.String(), portNumber) - if nil != err { - return nil, err - } - - codec := crpj.NewClientCodec() - - var rpcRegistry crr.RPCRegistry - if nil != services && 0 < len(services) { - rpcRegistry = crr.NewRPCRegistry() - rpcRegistry.RegisterServices(services...) - } - - ch := &ClientHandlers{ - Services: services, - OrderedServices: orderedServices, - } - ch.Name = containerType.String() - ch.Connector = connector - ch.RPCCodec = codec - ch.RPCInvoker = rpcRegistry - - return nil, &crc.Client{ - ClientHandler: ch, - } -} - -func newConnector(containerType occp.ContainerType, portNumber int) (*csswc.Connectors, error) { +func NewConnector(containerType occp.ContainerType, portNumber int) (*csswc.Connectors, error) { u := url.URL{ Scheme: "ws", Host: fmt.Sprintf("127.0.0.1:%d", port), diff --git a/constants.go b/constants.go index 481f697..01e8ee1 100644 --- a/constants.go +++ b/constants.go @@ -1,11 +1,7 @@ package container const ( - CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS" - CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN" + CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS" + CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN" + CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC" ) - -type RPCNotification struct { - Method string - Params []interface{} -} diff --git a/service/ProbeClientService.go b/service/ProbeService.go similarity index 59% rename from service/ProbeClientService.go rename to service/ProbeService.go index d1708d7..1cce807 100644 --- a/service/ProbeClientService.go +++ b/service/ProbeService.go @@ -1,11 +1,12 @@ package service import ( + "fmt" "reflect" cda "git.loafle.net/commons/di-go/annotation" cdr "git.loafle.net/commons/di-go/registry" - crc "git.loafle.net/commons/rpc-go/client" + crp "git.loafle.net/commons/rpc-go/protocol" // For annotation _ "git.loafle.net/overflow/commons-go/core/annotation" @@ -20,7 +21,8 @@ func init() { type ProbeService struct { cda.TypeAnnotation `annotation:"@overflow:RPCService()"` - Client *crc.Client `annotation:"@Resource(name='CONTAINER_CLIENT')"` + RPCWriteChan chan []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"` + ClientCodec crp.ClientCodec `annotation:"@Resource(name='CONTAINER_RPC_CLIENT_CODEC')"` } func (s *ProbeService) InitService() error { @@ -41,5 +43,16 @@ func (s *ProbeService) DestroyService() { } func (s *ProbeService) Send(method string, params ...interface{}) error { - return s.Client.Send(method, params...) + buff, err := s.ClientCodec.NewRequest(method, params, nil) + if nil != err { + return err + } + + select { + case s.RPCWriteChan <- buff: + default: + return fmt.Errorf("Cannot send notification method[%s] params[%v]", method, params) + } + + return nil }