container-go/service/ProbeService.go

59 lines
1.1 KiB
Go
Raw Normal View History

2018-05-02 10:59:45 +00:00
package service
import (
2018-05-03 06:14:22 +00:00
"fmt"
2018-05-02 10:59:45 +00:00
"reflect"
cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry"
2018-05-03 06:14:22 +00:00
crp "git.loafle.net/commons/rpc-go/protocol"
2018-05-02 10:59:45 +00:00
// For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation"
)
2018-05-02 11:14:46 +00:00
var ProbeServiceType = reflect.TypeOf((*ProbeService)(nil))
2018-05-02 10:59:45 +00:00
func init() {
2018-05-02 11:14:46 +00:00
cdr.RegisterType(ProbeServiceType)
2018-05-02 10:59:45 +00:00
}
2018-05-02 11:14:46 +00:00
type ProbeService struct {
2018-05-02 10:59:45 +00:00
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
2018-05-03 06:14:22 +00:00
RPCWriteChan chan []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"`
ClientCodec crp.ClientCodec `annotation:"@Resource(name='CONTAINER_RPC_CLIENT_CODEC')"`
2018-05-02 10:59:45 +00:00
}
2018-05-02 11:14:46 +00:00
func (s *ProbeService) InitService() error {
2018-05-02 10:59:45 +00:00
return nil
}
2018-05-02 11:14:46 +00:00
func (s *ProbeService) StartService() error {
2018-05-02 10:59:45 +00:00
return nil
}
2018-05-02 11:14:46 +00:00
func (s *ProbeService) StopService() {
2018-05-02 10:59:45 +00:00
}
2018-05-02 11:14:46 +00:00
func (s *ProbeService) DestroyService() {
2018-05-02 10:59:45 +00:00
}
2018-05-02 11:14:46 +00:00
func (s *ProbeService) Send(method string, params ...interface{}) error {
2018-05-03 06:14:22 +00:00
buff, err := s.ClientCodec.NewRequest(method, params, nil)
if nil != err {
return err
}
select {
case s.RPCWriteChan <- buff:
default:
return fmt.Errorf("Cannot send notification method[%s] params[%v]", method, params)
}
return nil
2018-05-02 10:59:45 +00:00
}