ing
This commit is contained in:
parent
8aa9dce840
commit
6ac6a2c21b
|
@ -3,20 +3,13 @@ package client
|
||||||
import (
|
import (
|
||||||
"git.loafle.net/commons_go/rpc"
|
"git.loafle.net/commons_go/rpc"
|
||||||
"git.loafle.net/commons_go/rpc/client"
|
"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 {
|
func New(addr string, registry rpc.Registry) client.Client {
|
||||||
ch := &ClientHandlers{}
|
|
||||||
ch.addr = addr
|
|
||||||
ch.RPCRegistry = notifyRegistry
|
|
||||||
ch.Codec = codec
|
|
||||||
|
|
||||||
return ch
|
ch := NewClientHandler(addr, registry)
|
||||||
}
|
|
||||||
|
c := client.New(ch)
|
||||||
type ClientHandlers struct {
|
|
||||||
client.ClientHandlers
|
return c
|
||||||
|
|
||||||
addr string
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,28 @@
|
||||||
package client
|
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/logging"
|
||||||
"git.loafle.net/commons_go/rpc"
|
"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/gateway"
|
||||||
"git.loafle.net/commons_go/rpc/protocol"
|
"git.loafle.net/commons_go/rpc/protocol"
|
||||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||||
|
@ -19,19 +18,6 @@ func newGatewayRPCServletHandler() GatewayRPCServletHandler {
|
||||||
|
|
||||||
type GatewayRPCServletHandlers struct {
|
type GatewayRPCServletHandlers struct {
|
||||||
gateway.ServletHandlers
|
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) {
|
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"
|
cRPC "git.loafle.net/commons_go/rpc"
|
||||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
"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"
|
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
||||||
oogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
oogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||||
"git.loafle.net/overflow/overflow_gateway_websocket/rpc"
|
"git.loafle.net/overflow/overflow_gateway_websocket/rpc"
|
||||||
|
@ -15,9 +16,11 @@ import (
|
||||||
|
|
||||||
func NewRPCGatewayServletHandler(gwRPCHandler rpc.GatewayRPCHandler) RPCGatewayServletHandler {
|
func NewRPCGatewayServletHandler(gwRPCHandler rpc.GatewayRPCHandler) RPCGatewayServletHandler {
|
||||||
gwRPCSH := newGatewayRPCServletHandler()
|
gwRPCSH := newGatewayRPCServletHandler()
|
||||||
|
rpcRWCSH := crsrwf.New()
|
||||||
|
|
||||||
sh := &RPCGatewayServletHandlers{
|
sh := &RPCGatewayServletHandlers{
|
||||||
gwRPCSH: gwRPCSH,
|
gwRPCSH: gwRPCSH,
|
||||||
|
rpcRWCSH: rpcRWCSH,
|
||||||
gwRPCHandler: gwRPCHandler,
|
gwRPCHandler: gwRPCHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +31,7 @@ type RPCGatewayServletHandlers struct {
|
||||||
servlet.ServletHandlers
|
servlet.ServletHandlers
|
||||||
|
|
||||||
gwRPCSH GatewayRPCServletHandler
|
gwRPCSH GatewayRPCServletHandler
|
||||||
|
rpcRWCSH cRPC.ServletReadWriteCloseHandler
|
||||||
gwRPCHandler rpc.GatewayRPCHandler
|
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) {
|
func (sh *RPCGatewayServletHandlers) Handle(soc cwf.Socket, stopChan <-chan struct{}, doneChan chan<- error) {
|
||||||
var err error
|
var err error
|
||||||
rpcServlet := retainRPCServlet(sh.gwRPCSH)
|
rpcServlet := retainRPCServlet(sh.gwRPCSH, sh.rpcRWCSH)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
releaseRPCServlet(rpcServlet)
|
releaseRPCServlet(rpcServlet)
|
||||||
|
@ -106,10 +110,10 @@ func (sh *RPCGatewayServletHandlers) Validate() {
|
||||||
|
|
||||||
var rpcServletPool sync.Pool
|
var rpcServletPool sync.Pool
|
||||||
|
|
||||||
func retainRPCServlet(sh GatewayRPCServletHandler) cRPC.Servlet {
|
func retainRPCServlet(sh GatewayRPCServletHandler, rpcRWCSH cRPC.ServletReadWriteCloseHandler) cRPC.Servlet {
|
||||||
v := rpcServletPool.Get()
|
v := rpcServletPool.Get()
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return cRPC.NewServlet(sh)
|
return cRPC.NewServlet(sh, rpcRWCSH)
|
||||||
}
|
}
|
||||||
return v.(cRPC.Servlet)
|
return v.(cRPC.Servlet)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user