ing
This commit is contained in:
parent
f330a9f4f5
commit
e4955d0250
|
@ -4,45 +4,14 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"git.loafle.net/commons/logging-go"
|
"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"
|
csswc "git.loafle.net/commons/server-go/socket/web/client"
|
||||||
occc "git.loafle.net/overflow/commons-go/config/container"
|
occc "git.loafle.net/overflow/commons-go/config/container"
|
||||||
occp "git.loafle.net/overflow/commons-go/config/probe"
|
occp "git.loafle.net/overflow/commons-go/config/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(containerType occp.ContainerType, services []interface{}, orderedServices []reflect.Type, portNumber int) (*crc.Client, error) {
|
func NewConnector(containerType occp.ContainerType, portNumber int) (*csswc.Connectors, 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) {
|
|
||||||
u := url.URL{
|
u := url.URL{
|
||||||
Scheme: "ws",
|
Scheme: "ws",
|
||||||
Host: fmt.Sprintf("127.0.0.1:%d", port),
|
Host: fmt.Sprintf("127.0.0.1:%d", port),
|
||||||
|
|
|
@ -3,9 +3,5 @@ package container
|
||||||
const (
|
const (
|
||||||
CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS"
|
CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS"
|
||||||
CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN"
|
CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN"
|
||||||
|
CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RPCNotification struct {
|
|
||||||
Method string
|
|
||||||
Params []interface{}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
cda "git.loafle.net/commons/di-go/annotation"
|
cda "git.loafle.net/commons/di-go/annotation"
|
||||||
cdr "git.loafle.net/commons/di-go/registry"
|
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
|
// For annotation
|
||||||
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
||||||
|
@ -20,7 +21,8 @@ func init() {
|
||||||
type ProbeService struct {
|
type ProbeService struct {
|
||||||
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
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 {
|
func (s *ProbeService) InitService() error {
|
||||||
|
@ -41,5 +43,16 @@ func (s *ProbeService) DestroyService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ProbeService) Send(method string, params ...interface{}) error {
|
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
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user