ing
This commit is contained in:
parent
21b4085bcc
commit
7ec23e0ba2
|
@ -5,3 +5,8 @@ const (
|
||||||
CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC"
|
CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC"
|
||||||
CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN"
|
CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RPCNotification struct {
|
||||||
|
Method string
|
||||||
|
Params []interface{}
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
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"
|
||||||
crp "git.loafle.net/commons/rpc-go/protocol"
|
"git.loafle.net/overflow/container-go"
|
||||||
|
|
||||||
// For annotation
|
// For annotation
|
||||||
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
||||||
|
@ -21,8 +21,7 @@ func init() {
|
||||||
type ProbeService struct {
|
type ProbeService struct {
|
||||||
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
||||||
|
|
||||||
RPCClientCodec crp.ClientCodec `annotation:"@Resource(name='CONTAINER_RPC_CLIENT_CODEC')"`
|
RPCWriteChan chan<- *container.RPCNotification `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"`
|
||||||
RPCWriteChan chan<- []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ProbeService) InitService() error {
|
func (s *ProbeService) InitService() error {
|
||||||
|
@ -43,13 +42,8 @@ func (s *ProbeService) DestroyService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ProbeService) Send(method string, params ...interface{}) error {
|
func (s *ProbeService) Send(method string, params ...interface{}) error {
|
||||||
buf, err := s.RPCClientCodec.NewRequest(method, params, nil)
|
|
||||||
if nil != err {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case s.RPCWriteChan <- buf:
|
case s.RPCWriteChan <- &container.RPCNotification{Method: method, Params: params}:
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cannot write to rpcWriteChan")
|
return fmt.Errorf("cannot write to rpcWriteChan")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
|
|
||||||
"git.loafle.net/commons/logging-go"
|
"git.loafle.net/commons/logging-go"
|
||||||
crp "git.loafle.net/commons/rpc-go/protocol"
|
crp "git.loafle.net/commons/rpc-go/protocol"
|
||||||
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
|
||||||
crr "git.loafle.net/commons/rpc-go/registry"
|
crr "git.loafle.net/commons/rpc-go/registry"
|
||||||
"git.loafle.net/commons/server-go"
|
"git.loafle.net/commons/server-go"
|
||||||
css "git.loafle.net/commons/server-go/socket"
|
css "git.loafle.net/commons/server-go/socket"
|
||||||
cssn "git.loafle.net/commons/server-go/socket/net"
|
cssn "git.loafle.net/commons/server-go/socket/net"
|
||||||
|
"git.loafle.net/overflow/container-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RPCServlet interface {
|
type RPCServlet interface {
|
||||||
|
@ -19,8 +19,9 @@ type RPCServlet interface {
|
||||||
type RPCServlets struct {
|
type RPCServlets struct {
|
||||||
cssn.Servlets
|
cssn.Servlets
|
||||||
|
|
||||||
|
RPCServerCodec crp.ServerCodec
|
||||||
RPCInvoker crr.RPCInvoker
|
RPCInvoker crr.RPCInvoker
|
||||||
RPCWriteChan <-chan []byte
|
RPCWriteChan <-chan *container.RPCNotification
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, conn net.Conn) error {
|
func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, conn net.Conn) error {
|
||||||
|
@ -49,7 +50,7 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx,
|
||||||
replyBuff []byte
|
replyBuff []byte
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
sc := crpj.NewServerCodec()
|
|
||||||
go s.handleRPCWrite(stopChan, writeChan)
|
go s.handleRPCWrite(stopChan, writeChan)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -59,7 +60,7 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// grpc exec method call
|
// grpc exec method call
|
||||||
src, err = sc.NewRequest(msg)
|
src, err = s.RPCServerCodec.NewRequest(msg)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.Logger().Error(err)
|
logging.Logger().Error(err)
|
||||||
break
|
break
|
||||||
|
@ -81,13 +82,22 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RPCServlets) handleRPCWrite(stopChan <-chan struct{}, writeChan chan<- []byte) {
|
func (s *RPCServlets) handleRPCWrite(stopChan <-chan struct{}, writeChan chan<- []byte) {
|
||||||
|
var (
|
||||||
|
buf []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case buf, ok := <-s.RPCWriteChan:
|
case noti, ok := <-s.RPCWriteChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf, err = s.RPCServerCodec.NewNotification(noti.Method, noti.Params)
|
||||||
|
if nil != err {
|
||||||
|
logging.Logger().Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
writeChan <- buf
|
writeChan <- buf
|
||||||
case <-stopChan:
|
case <-stopChan:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user