-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathcherry.go
68 lines (53 loc) · 1.46 KB
/
cherry.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cherry
import (
cfacade "github.com/cherry-game/cherry/facade"
ccluster "github.com/cherry-game/cherry/net/cluster"
cdiscovery "github.com/cherry-game/cherry/net/discovery"
)
type (
AppBuilder struct {
*Application
components []cfacade.IComponent
}
)
func Configure(profileFilePath, nodeId string, isFrontend bool, mode NodeMode) *AppBuilder {
appBuilder := &AppBuilder{
Application: NewApp(profileFilePath, nodeId, isFrontend, mode),
components: make([]cfacade.IComponent, 0),
}
return appBuilder
}
func ConfigureNode(node cfacade.INode, isFrontend bool, mode NodeMode) *AppBuilder {
appBuilder := &AppBuilder{
Application: NewAppNode(node, isFrontend, mode),
components: make([]cfacade.IComponent, 0),
}
return appBuilder
}
func (p *AppBuilder) Startup() {
app := p.Application
if app.NodeMode() == Cluster {
cluster := ccluster.New()
app.SetCluster(cluster)
app.Register(cluster)
discovery := cdiscovery.New()
app.SetDiscovery(discovery)
app.Register(discovery)
}
// Register custom components
app.Register(p.components...)
// startup
app.Startup()
}
func (p *AppBuilder) Register(component ...cfacade.IComponent) {
p.components = append(p.components, component...)
}
func (p *AppBuilder) AddActors(actors ...cfacade.IActorHandler) {
p.actorSystem.Add(actors...)
}
func (p *AppBuilder) NetParser() cfacade.INetParser {
return p.netParser
}
func (p *AppBuilder) SetNetParser(parser cfacade.INetParser) {
p.netParser = parser
}