-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.go
38 lines (31 loc) · 974 Bytes
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package processor
import (
"context"
"git.golaxy.org/core/service"
"git.golaxy.org/core/util/generic"
"git.golaxy.org/core/util/types"
"git.golaxy.org/framework/plugins/dserv"
"git.golaxy.org/framework/plugins/log"
)
// NewServiceProcessor 创建分布式服务间的RPC处理器
func NewServiceProcessor() any {
return &_ServiceProcessor{}
}
// _ServiceProcessor 分布式服务间的RPC处理器
type _ServiceProcessor struct {
servCtx service.Context
dist dserv.IDistService
watcher dserv.IWatcher
}
// Init 初始化
func (p *_ServiceProcessor) Init(ctx service.Context) {
p.servCtx = ctx
p.dist = dserv.Using(ctx)
p.watcher = p.dist.WatchMsg(context.Background(), generic.MakeDelegateFunc2(p.handleMsg))
log.Debugf(p.servCtx, "rpc processor %q started", types.FullName(*p))
}
// Shut 结束
func (p *_ServiceProcessor) Shut(ctx service.Context) {
<-p.watcher.Terminate()
log.Debugf(p.servCtx, "rpc processor %q stopped", types.FullName(*p))
}