This commit is contained in:
crusader 2018-04-19 22:01:11 +09:00
parent 665b0bbd56
commit f76a10dcd1
3 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package container package container
const ( const (
CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS" CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS"
CONTAINER_RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC"
CONTAINER_RPC_WRITE_CHAN = "CONTAINER_RPC_WRITE_CHAN"
) )

View File

@ -5,6 +5,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"
// For annotation // For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation" _ "git.loafle.net/overflow/commons-go/core/annotation"
@ -18,6 +19,9 @@ 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<- []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"`
} }
func (s *ProbeService) InitService() error { func (s *ProbeService) InitService() error {
@ -38,6 +42,12 @@ 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
}
s.RPCWriteChan <- buf
return nil return nil
} }

View File

@ -19,7 +19,8 @@ type RPCServlet interface {
type RPCServlets struct { type RPCServlets struct {
cssn.Servlets cssn.Servlets
RPCInvoker crr.RPCInvoker RPCInvoker crr.RPCInvoker
RPCWriteChan <-chan []byte
} }
func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, conn net.Conn) error { func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, conn net.Conn) error {
@ -72,6 +73,8 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx,
} }
writeChan <- replyBuff writeChan <- replyBuff
case buf := <-s.RPCWriteChan:
writeChan <- buf
case <-stopChan: case <-stopChan:
return return
} }