59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
cda "git.loafle.net/commons/di-go/annotation"
|
|
cdr "git.loafle.net/commons/di-go/registry"
|
|
crp "git.loafle.net/commons/rpc-go/protocol"
|
|
|
|
// For annotation
|
|
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
|
)
|
|
|
|
var ProbeServiceType = reflect.TypeOf((*ProbeService)(nil))
|
|
|
|
func init() {
|
|
cdr.RegisterType(ProbeServiceType)
|
|
}
|
|
|
|
type ProbeService struct {
|
|
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
|
|
|
RPCWriteChan chan []byte `annotation:"@Resource(name='CONTAINER_RPC_WRITE_CHAN')"`
|
|
ClientCodec crp.ClientCodec `annotation:"@Resource(name='CONTAINER_RPC_CLIENT_CODEC')"`
|
|
}
|
|
|
|
func (s *ProbeService) InitService() error {
|
|
return nil
|
|
}
|
|
|
|
func (s *ProbeService) StartService() error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *ProbeService) StopService() {
|
|
|
|
}
|
|
|
|
func (s *ProbeService) DestroyService() {
|
|
|
|
}
|
|
|
|
func (s *ProbeService) Send(method string, params ...interface{}) error {
|
|
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
|
|
}
|