probe/service/DataClientService.go

54 lines
1.0 KiB
Go
Raw Normal View History

2018-04-17 14:11:13 +00:00
package service
import (
"context"
"reflect"
cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry"
logging "git.loafle.net/commons/logging-go"
crc "git.loafle.net/commons/rpc-go/client"
_ "git.loafle.net/overflow/commons-go/core/annotation"
"git.loafle.net/overflow/probe/client/central"
)
var DataClientServiceType = reflect.TypeOf((*DataClientService)(nil))
func init() {
cdr.RegisterType(DataClientServiceType)
}
type DataClientService struct {
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
client *crc.Client
}
func (s *DataClientService) InitService() error {
client, err := central.NewData()
if nil != err {
return err
}
s.client = client
return nil
}
func (s *DataClientService) StartService() error {
if err := s.client.Start(); nil != err {
return err
}
return nil
}
func (s *DataClientService) StopService() {
if err := s.client.Stop(context.Background()); nil != err {
logging.Logger().Error(err)
}
}
func (s *DataClientService) DestroyService() {
s.client = nil
}