-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
container.go
80 lines (69 loc) · 2.18 KB
/
container.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
package endure
import (
"context"
"github.com/roadrunner-server/endure/v2/dep"
)
const (
// InitMethodName is the function fn for the reflection
InitMethodName = "Init"
// ServeMethodName is the function fn for the Serve
ServeMethodName = "Serve"
// StopMethodName is the function fn for the reflection to Stop the service
StopMethodName = "Stop"
)
// Result is the information which endure sends to the user
type Result struct {
Error error
VertexID string
}
type result struct {
// error channel from vertex
errCh chan error
// error from the channel
err error
// unique vertex id
vertexID string
}
type (
// Service interface can be implemented by the plugin to use Start-Stop functionality
Service interface {
// Serve starts the plugin
Serve() chan error
// Stop stops the plugin
Stop(context.Context) error
}
// Named -> Name of the service
Named interface {
// Name return user-friendly name of the plugin
Name() string
}
// Container - Internal container interface
Container interface {
// Serve used to Start the plugin in topological order
Serve() (<-chan *Result, error)
// Stop stops the plugins in rev-topological order
Stop() error
// Register registers one plugin in container
Register(service any) error
// Plugins method is responsible for returning an all registered plugins
Plugins() string
// RegisterAll register set of comma separated plugins in container
RegisterAll(service ...any) error
// Init initializes all plugins (calling Init function), calculate vertices, invoke Collects and Provided functions if exist
Init() error
}
// Provider declares the ability to provide service edges of declared types.
Provider interface {
// Provides function return set of functions which provided dependencies to other plugins
Provides() []*dep.Out
}
// Weighted is optional to implement, but when implemented the return value added during the topological sort
Weighted interface {
Weight() uint
}
// Collector declares the ability to accept the plugins which match the provided method signature.
Collector interface {
// Collects search for the plugins which implements given interfaces in the args
Collects() []*dep.In
}
)