ing
This commit is contained in:
parent
8aa9dce840
commit
6ac6a2c21b
|
@ -3,20 +3,13 @@ package client
|
|||
import (
|
||||
"git.loafle.net/commons_go/rpc"
|
||||
"git.loafle.net/commons_go/rpc/client"
|
||||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
)
|
||||
|
||||
func NewClientHandler(addr string, codec protocol.ClientCodec, notifyRegistry rpc.Registry) ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.addr = addr
|
||||
ch.RPCRegistry = notifyRegistry
|
||||
ch.Codec = codec
|
||||
func New(addr string, registry rpc.Registry) client.Client {
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
type ClientHandlers struct {
|
||||
client.ClientHandlers
|
||||
|
||||
addr string
|
||||
ch := NewClientHandler(addr, registry)
|
||||
|
||||
c := client.New(ch)
|
||||
|
||||
return c
|
||||
}
|
||||
|
|
|
@ -1,2 +1,28 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"git.loafle.net/commons_go/rpc"
|
||||
"git.loafle.net/commons_go/rpc/client"
|
||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||
)
|
||||
|
||||
func NewClientHandler(addr string, registry rpc.Registry) ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.addr = addr
|
||||
ch.RPCRegistry = registry
|
||||
ch.Codec = json.NewClientCodec()
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
type ClientHandlers struct {
|
||||
client.ClientHandlers
|
||||
|
||||
addr string
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Connect() (net.Conn, error) {
|
||||
return net.Dial("unix", ch.addr)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"git.loafle.net/commons_go/rpc"
|
||||
crcwf "git.loafle.net/commons_go/rpc/connection/websocket/fasthttp"
|
||||
"git.loafle.net/commons_go/rpc/gateway"
|
||||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||
|
@ -19,19 +18,6 @@ func newGatewayRPCServletHandler() GatewayRPCServletHandler {
|
|||
|
||||
type GatewayRPCServletHandlers struct {
|
||||
gateway.ServletHandlers
|
||||
rpcIO crcwf.ServletHandlers
|
||||
}
|
||||
|
||||
func (sh *GatewayRPCServletHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
|
||||
return sh.rpcIO.ReadRequest(servletCTX, codec, conn)
|
||||
}
|
||||
|
||||
func (sh *GatewayRPCServletHandlers) WriteResponse(servletCTX rpc.ServletContext, conn interface{}, requestCodec protocol.ServerRequestCodec, result interface{}, err error) error {
|
||||
return sh.rpcIO.WriteResponse(servletCTX, conn, requestCodec, result, err)
|
||||
}
|
||||
|
||||
func (sh *GatewayRPCServletHandlers) WriteNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, args []interface{}) error {
|
||||
return sh.rpcIO.WriteNotification(servletCTX, conn, codec, method, args)
|
||||
}
|
||||
|
||||
func (sh *GatewayRPCServletHandlers) Invoke(servletCTX rpc.ServletContext, requestCodec protocol.RegistryCodec) (result interface{}, err error) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
cRPC "git.loafle.net/commons_go/rpc"
|
||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||
crsrwf "git.loafle.net/commons_go/rpc/server/rwc/websocket/fasthttp"
|
||||
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
||||
oogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
"git.loafle.net/overflow/overflow_gateway_websocket/rpc"
|
||||
|
@ -15,9 +16,11 @@ import (
|
|||
|
||||
func NewRPCGatewayServletHandler(gwRPCHandler rpc.GatewayRPCHandler) RPCGatewayServletHandler {
|
||||
gwRPCSH := newGatewayRPCServletHandler()
|
||||
rpcRWCSH := crsrwf.New()
|
||||
|
||||
sh := &RPCGatewayServletHandlers{
|
||||
gwRPCSH: gwRPCSH,
|
||||
rpcRWCSH: rpcRWCSH,
|
||||
gwRPCHandler: gwRPCHandler,
|
||||
}
|
||||
|
||||
|
@ -28,6 +31,7 @@ type RPCGatewayServletHandlers struct {
|
|||
servlet.ServletHandlers
|
||||
|
||||
gwRPCSH GatewayRPCServletHandler
|
||||
rpcRWCSH cRPC.ServletReadWriteCloseHandler
|
||||
gwRPCHandler rpc.GatewayRPCHandler
|
||||
}
|
||||
|
||||
|
@ -64,7 +68,7 @@ func (sh *RPCGatewayServletHandlers) OnConnect(soc cwf.Socket) {
|
|||
|
||||
func (sh *RPCGatewayServletHandlers) Handle(soc cwf.Socket, stopChan <-chan struct{}, doneChan chan<- error) {
|
||||
var err error
|
||||
rpcServlet := retainRPCServlet(sh.gwRPCSH)
|
||||
rpcServlet := retainRPCServlet(sh.gwRPCSH, sh.rpcRWCSH)
|
||||
|
||||
defer func() {
|
||||
releaseRPCServlet(rpcServlet)
|
||||
|
@ -106,10 +110,10 @@ func (sh *RPCGatewayServletHandlers) Validate() {
|
|||
|
||||
var rpcServletPool sync.Pool
|
||||
|
||||
func retainRPCServlet(sh GatewayRPCServletHandler) cRPC.Servlet {
|
||||
func retainRPCServlet(sh GatewayRPCServletHandler, rpcRWCSH cRPC.ServletReadWriteCloseHandler) cRPC.Servlet {
|
||||
v := rpcServletPool.Get()
|
||||
if v == nil {
|
||||
return cRPC.NewServlet(sh)
|
||||
return cRPC.NewServlet(sh, rpcRWCSH)
|
||||
}
|
||||
return v.(cRPC.Servlet)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user