summaryrefslogtreecommitdiff
path: root/plugins/informer/plugin.go
blob: f8725ed7dbc63b58d9a43a408f6ffcaa7e128f87 (plain)
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
package informer

import (
	endure "github.com/spiral/endure/pkg/container"
	"github.com/spiral/roadrunner/v2/pkg/process"
)

const PluginName = "informer"

type Plugin struct {
	withWorkers map[string]Informer
	available   map[string]Availabler
}

func (p *Plugin) Init() error {
	p.available = make(map[string]Availabler)
	p.withWorkers = make(map[string]Informer)
	return nil
}

// Workers provides BaseProcess slice with workers for the requested plugin
func (p *Plugin) Workers(name string) []process.State {
	svc, ok := p.withWorkers[name]
	if !ok {
		return nil
	}

	return svc.Workers()
}

// Collects declares services to be collected.
func (p *Plugin) Collects() []interface{} {
	return []interface{}{
		p.CollectPlugins,
		p.CollectWorkers,
	}
}

// CollectPlugins collects all RR plugins
func (p *Plugin) CollectPlugins(name endure.Named, l Availabler) {
	p.available[name.Name()] = l
}

// CollectWorkers obtains plugins with workers inside.
func (p *Plugin) CollectWorkers(name endure.Named, r Informer) {
	p.withWorkers[name.Name()] = r
}

// Name of the service.
func (p *Plugin) Name() string {
	return PluginName
}

// RPC returns associated rpc service.
func (p *Plugin) RPC() interface{} {
	return &rpc{srv: p}
}