1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Allow plugins to have multiple handlers

Currently the plugins pkg allows a single handler. This assumption
breaks down if there are mutiple listeners to a plugin of a certain
Manifest such as NetworkDriver or IpamDriver when swarm-mode is enabled.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2016-10-14 22:40:28 -07:00
parent 88cae7412d
commit 5e9c78aeaf
4 changed files with 26 additions and 11 deletions

View file

@ -43,7 +43,7 @@ type plugins struct {
var (
storage = plugins{plugins: make(map[string]*Plugin)}
extpointHandlers = make(map[string]func(string, *Client))
extpointHandlers = make(map[string][]func(string, *Client))
)
// Manifest lists what a plugin implements.
@ -129,11 +129,13 @@ func (p *Plugin) activateWithLock() error {
p.Manifest = m
for _, iface := range m.Implements {
handler, handled := extpointHandlers[iface]
handlers, handled := extpointHandlers[iface]
if !handled {
continue
}
handler(p.name, p.client)
for _, handler := range handlers {
handler(p.name, p.client)
}
}
return nil
}
@ -226,7 +228,16 @@ func Get(name, imp string) (*Plugin, error) {
// Handle adds the specified function to the extpointHandlers.
func Handle(iface string, fn func(string, *Client)) {
extpointHandlers[iface] = fn
handlers, ok := extpointHandlers[iface]
if !ok {
handlers = []func(string, *Client){}
}
handlers = append(handlers, fn)
extpointHandlers[iface] = handlers
for _, p := range storage.plugins {
p.activated = false
}
}
// GetAll returns all the plugins for the specified implementation