overflow_discovery/server/server_handlers.go
crusader 7e2813ad35 ing
2017-12-05 11:52:14 +09:00

63 lines
1.2 KiB
Go

package server
import (
"fmt"
"net"
"git.loafle.net/commons_go/logging"
"git.loafle.net/overflow/overflow_discovery/discovery"
"git.loafle.net/commons_go/server"
)
func newServerHandler(addr string, socketHandler SocketHandler) ServerHandler {
sh := &ServerHandlers{
addr: addr,
}
sh.Name = "Discovery"
sh.SocketHandler = socketHandler
return sh
}
type ServerHandlers struct {
server.ServerHandlers
addr string
}
func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
if err := sh.ServerHandlers.Init(serverCTX); nil != err {
return err
}
return nil
}
func (sh *ServerHandlers) Listen(serverCTX server.ServerContext) (net.Listener, error) {
return net.Listen("tcp", "localhost:50006")
}
func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) {
sh.ServerHandlers.OnStart(serverCTX)
discovery.DiscoveryInit()
}
func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
discovery.DiscoveryDestroy()
sh.ServerHandlers.OnStop(serverCTX)
}
func (sh *ServerHandlers) Validate() {
sh.ServerHandlers.Validate()
if "" == sh.addr {
logging.Logger().Panic(fmt.Sprintf("Server: Address of server must be specified"))
}
}