-
Notifications
You must be signed in to change notification settings - Fork 1
/
startstop.go
52 lines (43 loc) · 1.98 KB
/
startstop.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
package apis
import "fmt"
// The StartStopPlugin interface defines the interface for all plugins of the "run" command.
// They uses a channel to send new status updates which are shown by the "run" command.
type StartStopPlugin interface {
// Must return the name of the plugin. This name will also be used for single commands.
fmt.Stringer
// Start the command and sets the channel used to show status and monitoring messages.
// Returns a string that indicates the box name which is also present in the monitoring messages.
Start(chan *MonitoringMessage) (boxName string, err error)
// Stops the plugin for graceful shutdown.
Stop() error
// IsSingleRunnable determs if this plugin can be started using the "run <plugin>" command.
IsSingleRunnable() bool
}
// StartStopPluginRegistry is the registry which collects all StartStopPlugins and provides easy access to them.
type StartStopPluginRegistry interface {
// AddPlugin adds a single plugin to the registry.
AddPlugin(plugin StartStopPlugin)
// AddPlugins adds the given list of plugins to the registry.
AddPlugins(plugins ...StartStopPlugin)
// ListPlugins returns a list of all currently registered plugins in the registry.
ListPlugins() []StartStopPlugin
// FindPlugin tries to find and return a plugin with the given name. Otherwise it would return an error.
FindPlugin(name string) (StartStopPlugin, error)
}
// The message type for notifying the run cli command about new status and monitoring messages from the plugin.
type MonitoringMessage struct {
Box string
Message string
}
// CloneMonitoringMessage creates a copy of the given MonitoringMessage.
func CloneMonitoringMessage(message *MonitoringMessage) MonitoringMessage {
return MonitoringMessage{
Box: message.Box,
Message: message.Message,
}
}
// The terminating message. If this message will be send, the run command will shutdown all other start stop plugins and ends.
var TerminatingMessage = &MonitoringMessage{
Box: "terminating",
Message: "terminating",
}