mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
1.支持动态服务发现功能
2.Service中支持对RPC结点连接或断开事件监听
This commit is contained in:
@@ -23,6 +23,7 @@ type IService interface {
|
||||
GetName() string
|
||||
OnSetup(iService IService)
|
||||
OnInit() error
|
||||
OnStart()
|
||||
OnRelease()
|
||||
Wait()
|
||||
Start()
|
||||
@@ -42,6 +43,16 @@ type Service struct {
|
||||
startStatus bool
|
||||
eventProcessor event.IEventProcessor
|
||||
profiler *profiler.Profiler //性能分析器
|
||||
rpcEventLister rpc.IRpcListener
|
||||
}
|
||||
|
||||
type RpcEventData struct{
|
||||
IsConnect bool
|
||||
NodeId int
|
||||
}
|
||||
|
||||
func (rpcEventData *RpcEventData) GetEventType() event.EventType{
|
||||
return event.Sys_Event_Rpc_Event
|
||||
}
|
||||
|
||||
func (s *Service) OnSetup(iService IService){
|
||||
@@ -99,6 +110,7 @@ func (s *Service) Run() {
|
||||
log.Debug("Start running Service %s.", s.GetName())
|
||||
defer s.wg.Done()
|
||||
var bStop = false
|
||||
s.self.(IService).OnStart()
|
||||
for{
|
||||
rpcRequestChan := s.GetRpcRequestChan()
|
||||
rpcResponseCallBack := s.GetRpcResponseChan()
|
||||
@@ -211,4 +223,28 @@ func (s *Service) IsSingleCoroutine() bool {
|
||||
|
||||
func (s *Service) RegRawRpc(rpcMethodId uint32,rawRpcCB rpc.RawRpcCallBack){
|
||||
s.rpcHandler.RegRawRpc(rpcMethodId,rawRpcCB)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) OnStart(){
|
||||
}
|
||||
|
||||
func (s *Service) OnRpcEvent(ev event.IEvent){
|
||||
event := ev.(*RpcEventData)
|
||||
if event.IsConnect {
|
||||
s.rpcEventLister.OnRpcConnected(event.NodeId)
|
||||
}else{
|
||||
s.rpcEventLister.OnRpcDisconnect(event.NodeId)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) RegisterRpcListener (rpcEventLister rpc.IRpcListener) {
|
||||
s.rpcEventLister = rpcEventLister
|
||||
s.RegEventReceiverFunc(event.Sys_Event_Rpc_Event,s.GetEventHandler(),s.OnRpcEvent)
|
||||
RegRpcEventFun(s.GetName())
|
||||
}
|
||||
|
||||
func (s *Service) UnRegisterRpcListener (rpcLister rpc.IRpcListener) {
|
||||
s.UnRegEventReceiverFunc(event.Sys_Event_Rpc_Event,s.GetEventHandler())
|
||||
RegRpcEventFun(s.GetName())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user