mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
1.支持动态服务发现功能
2.Service中支持对RPC结点连接或断开事件监听
This commit is contained in:
@@ -26,7 +26,7 @@ type IModule interface {
|
||||
GetService() IService
|
||||
GetModuleName() string
|
||||
GetEventProcessor()event.IEventProcessor
|
||||
NotifyEvent(ev *event.Event)
|
||||
NotifyEvent(ev event.IEvent)
|
||||
}
|
||||
|
||||
type IModuleTimer interface {
|
||||
@@ -213,7 +213,7 @@ func (m *Module) GetEventProcessor() event.IEventProcessor{
|
||||
return m.eventHandler.GetEventProcessor()
|
||||
}
|
||||
|
||||
func (m *Module) NotifyEvent(ev *event.Event){
|
||||
func (m *Module) NotifyEvent(ev event.IEvent){
|
||||
m.eventHandler.NotifyEvent(ev)
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ package service
|
||||
var mapServiceName map[string]IService
|
||||
var setupServiceList []IService
|
||||
|
||||
type RegRpcEventFunType func(serviceName string)
|
||||
var RegRpcEventFun RegRpcEventFunType
|
||||
|
||||
func init(){
|
||||
mapServiceName = map[string]IService{}
|
||||
setupServiceList = []IService{}
|
||||
|
||||
Reference in New Issue
Block a user