overflow_probe_container_ne.../server/server.go

52 lines
1.5 KiB
Go
Raw Normal View History

2017-12-04 11:59:11 +00:00
package server
import (
2018-03-26 02:58:39 +00:00
"reflect"
cdr "git.loafle.net/commons_go/di/registry"
"git.loafle.net/commons_go/logging"
2017-12-04 11:59:11 +00:00
crr "git.loafle.net/commons_go/rpc/registry"
"git.loafle.net/commons_go/server"
2018-03-26 02:58:39 +00:00
ooca "git.loafle.net/overflow/overflow_commons_go/annotation"
2018-03-27 09:03:36 +00:00
oopc "git.loafle.net/overflow/overflow_probe_container"
2017-12-05 06:09:04 +00:00
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
2018-03-26 02:58:39 +00:00
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
2018-03-27 09:03:36 +00:00
"git.loafle.net/overflow/overflow_probe_container_network/crawler"
2018-03-26 02:58:39 +00:00
oopcns "git.loafle.net/overflow/overflow_probe_container_network/service"
2017-12-04 11:59:11 +00:00
)
2017-12-14 08:51:08 +00:00
func New(pidPath string) server.Server {
2018-03-26 02:58:39 +00:00
var (
services []interface{}
probeService *oopcService.ProbeService
err error
)
oopcns.InitService()
2018-03-27 09:03:36 +00:00
cdr.RegisterResource(oopc.PROBE_CONTAINER_CRAWLERS, crawler.GetCrawlers())
2017-12-04 11:59:11 +00:00
rpcRegistry := crr.NewRPCRegistry()
2018-03-26 02:58:39 +00:00
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)
}
2017-12-04 11:59:11 +00:00
2017-12-05 06:09:04 +00:00
rpcSH := oopcs.NewRPCServletHandler(rpcRegistry)
2018-03-26 02:58:39 +00:00
socketHandler := newSocketHandler(rpcSH, probeService)
2017-12-04 11:59:11 +00:00
2018-03-27 09:03:36 +00:00
sh := newServerHandler(pidPath, socketHandler, services, oopcns.ServicesToStartAndStop)
2017-12-05 06:09:04 +00:00
s := oopcs.New(sh)
2017-12-04 11:59:11 +00:00
return s
}