diff --git a/client/client.go b/client/client.go deleted file mode 100644 index c598817..0000000 --- a/client/client.go +++ /dev/null @@ -1,15 +0,0 @@ -package client - -import ( - crc "git.loafle.net/commons_go/rpc/client" - crcrs "git.loafle.net/commons_go/rpc/client/rwc/socket" - csc "git.loafle.net/commons_go/server/client" -) - -func New(clientHandler ClientHandler, socketBuilder csc.SocketBuilder) crc.Client { - cRWCHandler := crcrs.New(socketBuilder) - - c := crc.New(clientHandler, cRWCHandler) - - return c -} diff --git a/client/client_handler.go b/client/client_handler.go deleted file mode 100644 index 7e0ce21..0000000 --- a/client/client_handler.go +++ /dev/null @@ -1,7 +0,0 @@ -package client - -import "git.loafle.net/commons_go/rpc/client" - -type ClientHandler interface { - client.ClientHandler -} diff --git a/client/client_handlers.go b/client/client_handlers.go deleted file mode 100644 index 769379d..0000000 --- a/client/client_handlers.go +++ /dev/null @@ -1,19 +0,0 @@ -package client - -import ( - crc "git.loafle.net/commons_go/rpc/client" - "git.loafle.net/commons_go/rpc/protocol/json" - crr "git.loafle.net/commons_go/rpc/registry" -) - -func NewClientHandler(rpcInvoker crr.RPCInvoker) ClientHandler { - ch := &ClientHandlers{} - ch.RPCInvoker = rpcInvoker - ch.Codec = json.NewClientCodec() - - return ch -} - -type ClientHandlers struct { - crc.ClientHandlers -} diff --git a/client/socket_builders.go b/client/socket_builders.go deleted file mode 100644 index d6292e8..0000000 --- a/client/socket_builders.go +++ /dev/null @@ -1,17 +0,0 @@ -package client - -import ( - csc "git.loafle.net/commons_go/server/client" -) - -func NewSocketBuilder(address string) csc.SocketBuilder { - return newSocketBuilder(address) -} - -type SocketBuilders struct { - csc.SocketBuilders -} - -func (sb *SocketBuilders) SocketHandler() csc.SocketHandler { - return NewSocketHandler() -} diff --git a/client/socket_builders_unix.go b/client/socket_builders_unix.go deleted file mode 100644 index 0923953..0000000 --- a/client/socket_builders_unix.go +++ /dev/null @@ -1,13 +0,0 @@ -package client - -import ( - csc "git.loafle.net/commons_go/server/client" -) - -func newSocketBuilder(address string) csc.SocketBuilder { - sb := &SocketBuilders{} - sb.Network = "unix" - sb.Address = address - - return sb -} diff --git a/client/socket_builders_windows.go b/client/socket_builders_windows.go deleted file mode 100644 index c8c8dd5..0000000 --- a/client/socket_builders_windows.go +++ /dev/null @@ -1,23 +0,0 @@ -package client - -import ( - "net" - - csc "git.loafle.net/commons_go/server/client" - "gopkg.in/natefinch/npipe.v2" -) - -func newSocketBuilder(address string) csc.SocketBuilder { - sb := &SocketBuilders{} - sb.Network = "pipe" - sb.Address = address - - return sb -} - -func (sb *SocketBuilders) Dial(network, address string) (net.Conn, error) { - if 0 == sb.HandshakeTimeout { - return npipe.Dial(`\\.\pipe\` + address) - } - return npipe.DialTimeout(`\\.\pipe\`+address, sb.HandshakeTimeout) -} diff --git a/client/socket_handlers.go b/client/socket_handlers.go deleted file mode 100644 index c287ace..0000000 --- a/client/socket_handlers.go +++ /dev/null @@ -1,28 +0,0 @@ -package client - -import ( - "log" - "net" - - csc "git.loafle.net/commons_go/server/client" -) - -type SocketHandlers struct { - csc.SocketHandlers -} - -func (sh *SocketHandlers) OnConnect(socketContext csc.SocketContext, conn net.Conn) { - log.Printf("OnConnect res: %v \n", conn) -} - -func (sh *SocketHandlers) OnDisconnect(soc csc.Socket) { - log.Printf("OnDisconnect \n") -} - -func (sh *SocketHandlers) Validate() { - sh.SocketHandlers.Validate() -} - -func NewSocketHandler() csc.SocketHandler { - return &SocketHandlers{} -} diff --git a/server/rpc_servlet_handler.go b/server/rpc_servlet_handler.go deleted file mode 100644 index 5b4944a..0000000 --- a/server/rpc_servlet_handler.go +++ /dev/null @@ -1,9 +0,0 @@ -package server - -import ( - "git.loafle.net/commons_go/rpc/server" -) - -type RPCServletHandler interface { - server.ServletHandler -} diff --git a/server/rpc_servlet_handlers.go b/server/rpc_servlet_handlers.go deleted file mode 100644 index 429abaf..0000000 --- a/server/rpc_servlet_handlers.go +++ /dev/null @@ -1,22 +0,0 @@ -package server - -import ( - crr "git.loafle.net/commons_go/rpc/registry" - "git.loafle.net/commons_go/rpc/server" -) - -func newRPCServletHandler(rpcInvoker crr.RPCInvoker) server.ServletHandler { - sh := &RPCServletHandlers{} - sh.RPCInvoker = rpcInvoker - - return sh -} - -type RPCServletHandlers struct { - server.ServletHandlers -} - -func (sh *RPCServletHandlers) Validate() { - sh.ServletHandlers.Validate() - -} diff --git a/server/server.go b/server/server.go index c89825d..feeecad 100644 --- a/server/server.go +++ b/server/server.go @@ -1,24 +1,21 @@ package server import ( - crpj "git.loafle.net/commons_go/rpc/protocol/json" crr "git.loafle.net/commons_go/rpc/registry" "git.loafle.net/commons_go/server" - "git.loafle.net/overflow/overflow_discovery/service" + oopcs "git.loafle.net/overflow/overflow_probe_container/server" ) func New(addr string) server.Server { rpcRegistry := crr.NewRPCRegistry() service.RegisterRPC(rpcRegistry) - rpcSH := newRPCServletHandler(rpcRegistry) - rpcSH.RegisterCodec(crpj.Name, crpj.NewServerCodec()) - + rpcSH := oopcs.NewRPCServletHandler(rpcRegistry) socketHandler := newSocketHandler(rpcSH) sh := newServerHandler(addr, socketHandler) - s := server.New(sh) + s := oopcs.New(sh) return s } diff --git a/server/server_handler.go b/server/server_handler.go index cf02713..c9a4c37 100644 --- a/server/server_handler.go +++ b/server/server_handler.go @@ -1,7 +1,9 @@ package server -import "git.loafle.net/commons_go/server" +import ( + oopcs "git.loafle.net/overflow/overflow_probe_container/server" +) type ServerHandler interface { - server.ServerHandler + oopcs.ServerHandler } diff --git a/server/server_handlers.go b/server/server_handlers.go index 59314a3..b1ae753 100644 --- a/server/server_handlers.go +++ b/server/server_handlers.go @@ -1,32 +1,24 @@ package server import ( - "fmt" - - "git.loafle.net/commons_go/logging" - "git.loafle.net/overflow/overflow_discovery/discovery" - "git.loafle.net/commons_go/server" + "git.loafle.net/overflow/overflow_discovery/discovery" + oopcs "git.loafle.net/overflow/overflow_probe_container/server" ) func newServerHandler(addr string, socketHandler SocketHandler) ServerHandler { - sh := &ServerHandlers{ - addr: addr, - } + sh := &ServerHandlers{} + sh.ServerHandler = oopcs.NewServerHandler(addr, "Discovery Containter", socketHandler) - sh.Name = "Discovery" - sh.SocketHandler = socketHandler return sh } type ServerHandlers struct { - server.ServerHandlers - - addr string + oopcs.ServerHandler } func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error { - if err := sh.ServerHandlers.Init(serverCTX); nil != err { + if err := sh.ServerHandler.Init(serverCTX); nil != err { return err } @@ -34,7 +26,7 @@ func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error { } func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) { - sh.ServerHandlers.OnStart(serverCTX) + sh.ServerHandler.OnStart(serverCTX) discovery.DiscoveryInit() } @@ -43,14 +35,10 @@ func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) { discovery.DiscoveryDestroy() - sh.ServerHandlers.OnStop(serverCTX) + sh.ServerHandler.OnStop(serverCTX) } func (sh *ServerHandlers) Validate() { - sh.ServerHandlers.Validate() - - if "" == sh.addr { - logging.Logger().Panic(fmt.Sprintf("Server: Address of server must be specified")) - } + sh.ServerHandler.Validate() } diff --git a/server/server_handlers_unix.go b/server/server_handlers_unix.go deleted file mode 100644 index 4aad065..0000000 --- a/server/server_handlers_unix.go +++ /dev/null @@ -1,17 +0,0 @@ -package server - -import ( - "net" - "os" - - "git.loafle.net/commons_go/server" -) - -func (sh *ServerHandlers) Listen(serverCTX server.ServerContext) (net.Listener, error) { - os.Remove(sh.addr) - l, err := net.ListenUnix("unix", &net.UnixAddr{Name: sh.addr, Net: "unix"}) - if nil == err { - os.Chmod(sh.addr, 0777) - } - return l, err -} diff --git a/server/server_handlers_windows.go b/server/server_handlers_windows.go deleted file mode 100644 index 4c51a3e..0000000 --- a/server/server_handlers_windows.go +++ /dev/null @@ -1,16 +0,0 @@ -package server - -import ( - "net" - - "git.loafle.net/commons_go/server" - "gopkg.in/natefinch/npipe.v2" -) - -func (sh *ServerHandlers) Listen(serverCTX server.ServerContext) (net.Listener, error) { - ln, err := npipe.Listen(`\\.\pipe\` + sh.addr) - if err != nil { - // handle error - } - return ln, err -} diff --git a/server/socket_handler.go b/server/socket_handler.go index ed3b15e..6d19f66 100644 --- a/server/socket_handler.go +++ b/server/socket_handler.go @@ -1,9 +1,9 @@ package server import ( - "git.loafle.net/commons_go/server" + oopcs "git.loafle.net/overflow/overflow_probe_container/server" ) type SocketHandler interface { - server.SocketHandler + oopcs.SocketHandler } diff --git a/server/socket_handlers.go b/server/socket_handlers.go index 4f89851..029b816 100644 --- a/server/socket_handlers.go +++ b/server/socket_handlers.go @@ -2,36 +2,27 @@ package server import ( "net" - "sync" cRPC "git.loafle.net/commons_go/rpc" - crsrs "git.loafle.net/commons_go/rpc/server/rwc/socket" - - "git.loafle.net/commons_go/rpc/protocol/json" "git.loafle.net/commons_go/server" "git.loafle.net/overflow/overflow_discovery/discovery" + oopc "git.loafle.net/overflow/overflow_probe_container" + oopcs "git.loafle.net/overflow/overflow_probe_container/server" ) -func newSocketHandler(rpcSH RPCServletHandler) SocketHandler { - rpcRWCSH := crsrs.New() - - sh := &SocketHandlers{ - rpcSH: rpcSH, - rpcRWCSH: rpcRWCSH, - } +func newSocketHandler(rpcSH oopcs.RPCServletHandler) SocketHandler { + sh := &SocketHandlers{} + sh.SocketHandler = oopcs.NewSocketHandler(rpcSH) return sh } type SocketHandlers struct { - server.SocketHandlers - - rpcRWCSH cRPC.ServletReadWriteCloseHandler - rpcSH RPCServletHandler + oopcs.SocketHandler } func (sh *SocketHandlers) Init(serverCTX server.ServerContext) error { - if err := sh.SocketHandlers.Init(serverCTX); nil != err { + if err := sh.SocketHandler.Init(serverCTX); nil != err { return err } @@ -43,61 +34,22 @@ func (sh *SocketHandlers) Handshake(socketCTX server.SocketContext, conn net.Con } func (sh *SocketHandlers) OnConnect(soc server.Socket) { - sh.SocketHandlers.OnConnect(soc) + sh.SocketHandler.OnConnect(soc) - soc.Context().SetAttribute(cRPC.ContentTypeKey, json.Name) - -} - -func (sh *SocketHandlers) Handle(soc server.Socket, stopChan <-chan struct{}, doneChan chan<- error) { - var err error - rpcServlet := retainRPCServlet(sh.rpcSH, sh.rpcRWCSH) - discovery.RPCServlet = rpcServlet - - defer func() { - releaseRPCServlet(rpcServlet) - doneChan <- err - }() - - rpcDoneChan := make(chan error, 1) - - if err = rpcServlet.Start(soc.Context(), soc, rpcDoneChan); nil != err { - return - } - - select { - case err = <-rpcDoneChan: - case <-stopChan: - rpcServlet.Stop() - <-rpcDoneChan - } + discovery.RPCServlet = soc.Context().GetAttribute(oopc.RPCServletKey).(cRPC.Servlet) } func (sh *SocketHandlers) OnDisconnect(soc server.Socket) { + discovery.RPCServlet = nil - sh.SocketHandlers.OnDisconnect(soc) + sh.SocketHandler.OnDisconnect(soc) } func (sh *SocketHandlers) Destroy() { - sh.SocketHandlers.Destroy() + sh.SocketHandler.Destroy() } func (sh *SocketHandlers) Validate() { } - -var rpcServletPool sync.Pool - -func retainRPCServlet(sh RPCServletHandler, rpcRWCSH cRPC.ServletReadWriteCloseHandler) cRPC.Servlet { - v := rpcServletPool.Get() - if v == nil { - return cRPC.NewServlet(sh, rpcRWCSH) - } - return v.(cRPC.Servlet) -} - -func releaseRPCServlet(s cRPC.Servlet) { - - rpcServletPool.Put(s) -}