forked from ergo-services/ergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
275 lines (229 loc) · 8.01 KB
/
default.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package ergo
import (
"github.com/sllt/ergo/etf"
"github.com/sllt/ergo/gen"
"github.com/sllt/ergo/node"
"time"
)
var (
DefaultNode node.Node
)
func init() {
DefaultNode, _ = StartNode("ergo@localhost", "ergo", node.Options{})
}
// Name returns node name
func Name() string {
return DefaultNode.Name()
}
// IsAlive returns true if node is still alive
func IsAlive() bool {
return DefaultNode.IsAlive()
}
// Uptime returns node uptime in seconds
func Uptime() int64 {
return DefaultNode.Uptime()
}
// ListEnv returns a map of configured Node environment variables.
func ListEnv() map[gen.EnvKey]interface{} {
return DefaultNode.ListEnv()
}
// SetEnv set node environment variable with given name. Use nil value to remove variable with given name. Ignores names with "ergo:" as a prefix.
func SetEnv(name gen.EnvKey, value interface{}) {
DefaultNode.SetEnv(name, value)
}
// Env returns value associated with given environment name.
func Env(name gen.EnvKey) interface{} {
return DefaultNode.Env(name)
}
func RegisterName(name string, pid etf.Pid) error {
return DefaultNode.RegisterName(name, pid)
}
func UnregisterName(name string) error {
return DefaultNode.UnregisterName(name)
}
func LoadedApplications() []gen.ApplicationInfo {
return DefaultNode.LoadedApplications()
}
func WhichApplications() []gen.ApplicationInfo {
return DefaultNode.WhichApplications()
}
func ApplicationInfo(name string) (gen.ApplicationInfo, error) {
return DefaultNode.ApplicationInfo(name)
}
func ApplicationLoad(app gen.ApplicationBehavior, args ...etf.Term) (string, error) {
return DefaultNode.ApplicationLoad(app, args...)
}
func ApplicationUnload(appName string) error {
return DefaultNode.ApplicationUnload(appName)
}
func ApplicationStart(appName string, args ...etf.Term) (gen.Process, error) {
return DefaultNode.ApplicationStart(appName, args...)
}
func ApplicationStartPermanent(appName string, args ...etf.Term) (gen.Process, error) {
return DefaultNode.ApplicationStartPermanent(appName, args...)
}
func ApplicationStartTransient(appName string, args ...etf.Term) (gen.Process, error) {
return DefaultNode.ApplicationStartTransient(appName, args...)
}
func ApplicationStop(appName string) error {
return DefaultNode.ApplicationStop(appName)
}
func ProvideRemoteSpawn(name string, object gen.ProcessBehavior) error {
return DefaultNode.ProvideRemoteSpawn(name, object)
}
func RevokeRemoteSpawn(name string) error {
return DefaultNode.RevokeRemoteSpawn(name)
}
// AddStaticRoute adds static route for the given name
func AddStaticRoute(node string, host string, port uint16, options node.RouteOptions) error {
return DefaultNode.AddStaticRoute(node, host, port, options)
}
// AddStaticRoutePort adds static route for the given node name which makes node skip resolving port process
func AddStaticRoutePort(node string, port uint16, options node.RouteOptions) error {
return DefaultNode.AddStaticRoutePort(node, port, options)
}
// AddStaticRouteOptions adds static route options for the given node name which does regular port resolving but applies static options
func AddStaticRouteOptions(node string, options node.RouteOptions) error {
return DefaultNode.AddStaticRouteOptions(node, options)
}
// Remove static route removes static route with given name
func RemoveStaticRoute(name string) bool {
return DefaultNode.RemoveStaticRoute(name)
}
// StaticRoutes returns list of routes added using AddStaticRoute
func StaticRoutes() []node.Route {
return DefaultNode.StaticRoutes()
}
// StaticRoute returns Route for the given name. Returns false if it doesn't exist.
func StaticRoute(name string) (node.Route, bool) {
return DefaultNode.StaticRoute(name)
}
func AddProxyRoute(proxy node.ProxyRoute) error {
return DefaultNode.AddProxyRoute(proxy)
}
func RemoveProxyRoute(name string) bool {
return DefaultNode.RemoveProxyRoute(name)
}
// ProxyRoutes returns list of proxy routes added using AddProxyRoute
func ProxyRoutes() []node.ProxyRoute {
return DefaultNode.ProxyRoutes()
}
// ProxyRoute returns proxy route added using AddProxyRoute
func ProxyRoute(name string) (node.ProxyRoute, bool) {
return DefaultNode.ProxyRoute(name)
}
// Resolve
func Resolve(node string) (node.Route, error) {
return DefaultNode.Resolve(node)
}
// ResolveProxy resolves proxy route. Checks for the proxy route added using AddProxyRoute.
// If it wasn't found makes request to the registrar.
func ResolveProxy(node string) (node.ProxyRoute, error) {
return DefaultNode.ResolveProxy(node)
}
// Returns Registrar interface
func Registrar() node.Registrar {
return DefaultNode.Registrar()
}
// Connect sets up a connection to node
func Connect(node string) error {
return DefaultNode.Connect(node)
}
// Disconnect close connection to the node
func Disconnect(node string) error {
return DefaultNode.Disconnect(node)
}
// Nodes returns the list of connected nodes
func Nodes() []string {
return DefaultNode.Nodes()
}
// NodesIndirect returns the list of nodes connected via proxies
func NodesIndirect() []string {
return DefaultNode.NodesIndirect()
}
// NetworkStats returns network statistics of the connection with the node. Returns error
// ErrUnknown if connection with given node is not established.
func NetworkStats(name string) (node.NetworkStats, error) {
return DefaultNode.NetworkStats(name)
}
func Links(process etf.Pid) []etf.Pid {
return DefaultNode.Links(process)
}
func Monitors(process etf.Pid) []etf.Pid {
return DefaultNode.Monitors(process)
}
func MonitorsByName(process etf.Pid) []gen.ProcessID {
return DefaultNode.MonitorsByName(process)
}
func MonitoredBy(process etf.Pid) []etf.Pid {
return DefaultNode.MonitoredBy(process)
}
func Stats() node.NodeStats {
return DefaultNode.Stats()
}
func Stop() {
DefaultNode.Stop()
}
func Wait() {
DefaultNode.Wait()
}
func WaitWithTimeout(d time.Duration) error {
return DefaultNode.WaitWithTimeout(d)
}
// Spawn spawns a new process
func Spawn(name string, opts gen.ProcessOptions, object gen.ProcessBehavior, args ...etf.Term) (gen.Process, error) {
return DefaultNode.Spawn(name, opts, object, args...)
}
// ProcessByName returns Process for the given name.
// Returns nil if it doesn't exist (not found) or terminated.
func ProcessByName(name string) gen.Process {
return DefaultNode.ProcessByName(name)
}
// ProcessByPid returns Process for the given Pid.
// Returns nil if it doesn't exist (not found) or terminated.
func ProcessByPid(pid etf.Pid) gen.Process {
return DefaultNode.ProcessByPid(pid)
}
// ProcessByAlias returns Process for the given alias.
// Returns nil if it doesn't exist (not found) or terminated
func ProcessByAlias(alias etf.Alias) gen.Process {
return DefaultNode.ProcessByAlias(alias)
}
// ProcessInfo returns the details about given Pid
func ProcessInfo(pid etf.Pid) (gen.ProcessInfo, error) {
return DefaultNode.ProcessInfo(pid)
}
// ProcessList returns the list of running processes
func ProcessList() []gen.Process {
return DefaultNode.ProcessList()
}
// MakeRef creates an unique reference within this node
func MakeRef() etf.Ref {
return DefaultNode.MakeRef()
}
// IsAlias checks whether the given alias is belongs to the alive process on this node.
// If the process died all aliases are cleaned up and this function returns
// false for the given alias. For alias from the remote node always returns false.
func IsAlias(alias etf.Alias) bool {
return DefaultNode.IsAlias(alias)
}
// IsMonitor returns true if the given references is a monitor
func IsMonitor(ref etf.Ref) bool {
return DefaultNode.IsMonitor(ref)
}
// RegisterBehavior
func RegisterBehavior(group, name string, behavior gen.ProcessBehavior, data interface{}) error {
return DefaultNode.RegisterBehavior(group, name, behavior, data)
}
// RegisteredBehavior
func RegisteredBehavior(group, name string) (gen.RegisteredBehavior, error) {
return DefaultNode.RegisteredBehavior(group, name)
}
// RegisteredBehaviorGroup
func RegisteredBehaviorGroup(group string) []gen.RegisteredBehavior {
return DefaultNode.RegisteredBehaviorGroup(group)
}
// UnregisterBehavior
func UnregisterBehavior(group, name string) error {
return DefaultNode.UnregisterBehavior(group, name)
}