overflow_discovery/server/server.go
crusader 3ebe20681f ing
2018-03-27 18:51:48 +09:00

51 lines
1.4 KiB
Go

package server
import (
"reflect"
cdr "git.loafle.net/commons_go/di/registry"
"git.loafle.net/commons_go/logging"
crr "git.loafle.net/commons_go/rpc/registry"
"git.loafle.net/commons_go/server"
ooca "git.loafle.net/overflow/overflow_commons_go/annotation"
"git.loafle.net/overflow/overflow_discovery/crawler"
oods "git.loafle.net/overflow/overflow_discovery/service"
oopc "git.loafle.net/overflow/overflow_probe_container"
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
)
func New(pidPath string) server.Server {
var (
services []interface{}
probeService *oopcService.ProbeService
err error
)
oods.InitService()
cdr.RegisterResource(oopc.PROBE_CONTAINER_CRAWLERS, crawler.GetCrawlers())
rpcRegistry := crr.NewRPCRegistry()
if services, err = cdr.GetInstancesByAnnotationName(ooca.ServiceTag); nil != err {
logging.Logger().Panic(err)
}
for _, s := range services {
rpcRegistry.RegisterService(s, "")
}
if _probeService, err := cdr.GetInstance(reflect.TypeOf((*oopcService.ProbeService)(nil))); nil != err {
logging.Logger().Panic(err)
} else {
probeService = _probeService.(*oopcService.ProbeService)
}
rpcSH := oopcs.NewRPCServletHandler(rpcRegistry)
socketHandler := newSocketHandler(rpcSH, probeService)
sh := newServerHandler(pidPath, socketHandler, services, oods.ServicesToStartAndStop)
s := oopcs.New(sh)
return s
}