This commit is contained in:
crusader 2018-03-16 16:46:31 +09:00
parent f5e37136e0
commit c78d3b60ea
6 changed files with 60 additions and 9 deletions

View File

@ -0,0 +1,22 @@
package annotation
// @Service()
// inherit @Component
import (
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdia "git.loafle.net/commons_go/di/injection/annotation"
)
const (
ServiceTag = "@overFlow:Service"
)
func init() {
cda.RegisterAnnotation(ServiceTag, reflect.TypeOf((*Service)(nil)))
}
type Service struct {
cdia.Component
}

View File

@ -7,3 +7,4 @@ import:
- package: git.loafle.net/commons_go/server - package: git.loafle.net/commons_go/server
- package: git.loafle.net/commons_go/rpc - package: git.loafle.net/commons_go/rpc
- package: gopkg.in/natefinch/npipe.v2 - package: gopkg.in/natefinch/npipe.v2
- package: git.loafle.net/commons_go/di

View File

@ -1,15 +1,24 @@
package server package server
import ( import (
cdr "git.loafle.net/commons_go/di/registry"
crr "git.loafle.net/commons_go/rpc/registry" crr "git.loafle.net/commons_go/rpc/registry"
"git.loafle.net/commons_go/server" "git.loafle.net/commons_go/server"
"git.loafle.net/overflow/overflow_discovery/service" oodca "git.loafle.net/overflow/overflow_discovery/commons/annotation"
oods "git.loafle.net/overflow/overflow_discovery/service"
oopcs "git.loafle.net/overflow/overflow_probe_container/server" oopcs "git.loafle.net/overflow/overflow_probe_container/server"
) )
func New(pidPath string) server.Server { func New(pidPath string) server.Server {
oods.InitService()
rpcRegistry := crr.NewRPCRegistry() rpcRegistry := crr.NewRPCRegistry()
service.RegisterRPC(rpcRegistry)
services := cdr.GetInstancesByAnnotationName(oodca.ServiceTag)
for _, s := range services {
rpcRegistry.RegisterService(s, "")
}
rpcSH := oopcs.NewRPCServletHandler(rpcRegistry) rpcSH := oopcs.NewRPCServletHandler(rpcRegistry)
socketHandler := newSocketHandler(rpcSH) socketHandler := newSocketHandler(rpcSH)

View File

@ -1,6 +1,18 @@
package service 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((*ContainerService)(nil)))
}
type ContainerService struct { type ContainerService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
} }
func (cs *ContainerService) State() (bool, error) { func (cs *ContainerService) State() (bool, error) {

View File

@ -1,11 +1,20 @@
package service package service
import ( import (
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model" discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
"git.loafle.net/overflow/overflow_discovery/discovery" "git.loafle.net/overflow/overflow_discovery/discovery"
) )
func init() {
cdr.RegisterType(reflect.TypeOf((*DiscoveryService)(nil)))
}
type DiscoveryService struct { type DiscoveryService struct {
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
} }
func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error { func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error {

View File

@ -1,10 +1,8 @@
package service package service
import ( func InitService() {
crr "git.loafle.net/commons_go/rpc/registry" }
)
func DestroyService() {
func RegisterRPC(rpcRegistry crr.RPCRegistry) {
rpcRegistry.RegisterService(&ContainerService{}, "")
rpcRegistry.RegisterService(&DiscoveryService{}, "")
} }