2018-04-17 14:11:13 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
cda "git.loafle.net/commons/di-go/annotation"
|
|
|
|
cdr "git.loafle.net/commons/di-go/registry"
|
|
|
|
|
|
|
|
// For annotation
|
|
|
|
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
|
|
|
"git.loafle.net/overflow/probe/client/central"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ProbeClientServiceType = reflect.TypeOf((*ProbeClientService)(nil))
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cdr.RegisterType(ProbeClientServiceType)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProbeClientService struct {
|
2018-04-18 14:56:13 +00:00
|
|
|
RPCClientService
|
|
|
|
|
2018-04-17 14:11:13 +00:00
|
|
|
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
|
|
|
|
2018-04-19 15:03:58 +00:00
|
|
|
DiscoveryService *DiscoveryService `annotation:"@Inject()"`
|
2018-04-17 14:11:13 +00:00
|
|
|
|
|
|
|
EncryptionKey string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProbeClientService) InitService() error {
|
2018-04-18 14:56:13 +00:00
|
|
|
if err := s.RPCClientService.InitService(); nil != err {
|
2018-04-17 14:11:13 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProbeClientService) StartService() error {
|
2018-04-18 14:56:13 +00:00
|
|
|
if err := s.RPCClientService.StartService(); nil != err {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-04-19 15:03:58 +00:00
|
|
|
client, err := central.NewProbe(s.HandleEncryptionKey, s.DiscoveryService)
|
2018-04-18 14:56:13 +00:00
|
|
|
if nil != err {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
s.client = client
|
|
|
|
|
2018-04-17 14:11:13 +00:00
|
|
|
if err := s.client.Start(); nil != err {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProbeClientService) StopService() {
|
2018-04-18 14:56:13 +00:00
|
|
|
s.RPCClientService.StopService()
|
2018-04-17 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProbeClientService) DestroyService() {
|
2018-04-18 14:56:13 +00:00
|
|
|
s.RPCClientService.DestroyService()
|
2018-04-17 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProbeClientService) HandleEncryptionKey(encryptionKey string) {
|
|
|
|
s.EncryptionKey = encryptionKey
|
|
|
|
}
|