This commit is contained in:
crusader 2018-03-27 17:56:39 +09:00
parent df00b0f0e7
commit 657796d456

View File

@ -6,21 +6,26 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"strconv" "strconv"
"git.loafle.net/commons_go/logging" "git.loafle.net/commons_go/logging"
"git.loafle.net/commons_go/server" "git.loafle.net/commons_go/server"
oocu "git.loafle.net/overflow/overflow_commons_go/util"
) )
func NewServerHandler(pidPath string, serverName string, socketHandler SocketHandler) ServerHandler { func NewServerHandler(pidPath string, serverName string, socketHandler SocketHandler, services []interface{}, servicesToStartAndStop []reflect.Type) ServerHandler {
pidPathABS, err := filepath.Abs(pidPath) pidPathABS, err := filepath.Abs(pidPath)
if nil != err { if nil != err {
logging.Logger().Panicf("Container: pid file path[%s] is not valid %v", pidPath, err) logging.Logger().Panicf("Container: pid file path[%s] is not valid %v", pidPath, err)
} }
sh := &ServerHandlers{ sh := &ServerHandlers{
pidPath: pidPath, pidPath: pidPath,
pidPathABS: pidPathABS, pidPathABS: pidPathABS,
services: services,
servicesToStartAndStop: servicesToStartAndStop,
} }
sh.Name = serverName sh.Name = serverName
@ -34,6 +39,9 @@ type ServerHandlers struct {
pidPath string pidPath string
pidPathABS string pidPathABS string
port int port int
services []interface{}
servicesToStartAndStop []reflect.Type
} }
func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error { func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
@ -41,6 +49,10 @@ func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
return err return err
} }
if err := oocu.ExecuteStarters(sh.services, sh.servicesToStartAndStop, false); nil != err {
return err
}
return nil return nil
} }
@ -81,6 +93,9 @@ func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
} }
func (sh *ServerHandlers) Destroy(serverCTX server.ServerContext) { func (sh *ServerHandlers) Destroy(serverCTX server.ServerContext) {
if err := oocu.ExecuteStoppers(sh.services, sh.servicesToStartAndStop, true); nil != err {
logging.Logger().Error(err)
}
sh.ServerHandlers.Destroy(serverCTX) sh.ServerHandlers.Destroy(serverCTX)
} }