This commit is contained in:
crusader 2018-03-26 11:58:39 +09:00
parent cc2c4e7d27
commit 8dd32aedb8
7 changed files with 76 additions and 12 deletions

View File

@ -1,2 +1,4 @@
package: git.loafle.net/overflow/overflow_probe_container_network
import: []
import:
- package: git.loafle.net/commons_go/di
- package: git.loafle.net/overflow/overflow_probe_container

View File

@ -1,18 +1,44 @@
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"
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
"git.loafle.net/overflow/overflow_probe_container_network/service"
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
oopcns "git.loafle.net/overflow/overflow_probe_container_network/service"
)
func New(pidPath string) server.Server {
var (
services []interface{}
probeService *oopcService.ProbeService
err error
)
oopcns.InitService()
rpcRegistry := crr.NewRPCRegistry()
service.RegisterRPC(rpcRegistry)
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)
socketHandler := newSocketHandler(rpcSH, probeService)
sh := newServerHandler(pidPath, socketHandler)
s := oopcs.New(sh)

View File

@ -5,11 +5,12 @@ import (
"git.loafle.net/commons_go/server"
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
)
func newSocketHandler(rpcSH oopcs.RPCServletHandler) SocketHandler {
func newSocketHandler(rpcSH oopcs.RPCServletHandler, probeService *oopcService.ProbeService) SocketHandler {
sh := &SocketHandlers{}
sh.SocketHandler = oopcs.NewSocketHandler(rpcSH)
sh.SocketHandler = oopcs.NewSocketHandler(rpcSH, probeService)
return sh
}

View File

@ -1,11 +1,21 @@
package service
import (
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
"git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*ConfigService)(nil)))
}
type ConfigService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
}
func (s *ConfigService) Add(crawlerName string, config *configM.Config) error {

View File

@ -1,8 +1,19 @@
package service
import "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
import (
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
"git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*DataService)(nil)))
}
type DataService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
}
func (s *DataService) Get(crawlerName string, sensorID string) (interface{}, error) {

View File

@ -1,6 +1,18 @@
package service
import (
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
)
func init() {
cdr.RegisterType(reflect.TypeOf((*StateService)(nil)))
}
type StateService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
}
func (s *StateService) State() (bool, error) {

View File

@ -1,11 +1,13 @@
package service
import (
crr "git.loafle.net/commons_go/rpc/registry"
oopcs "git.loafle.net/overflow/overflow_probe_container/service"
)
func RegisterRPC(rpcRegistry crr.RPCRegistry) {
rpcRegistry.RegisterService(&ConfigService{}, "")
rpcRegistry.RegisterService(&DataService{}, "")
rpcRegistry.RegisterService(&StateService{}, "")
func InitService() {
oopcs.InitService()
}
func DestroyService() {
oopcs.DestroyService()
}