From ba3bcf053749543a1643421d7fa5f680a49ee1a8 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Fri, 15 May 2015 04:07:59 -0700 Subject: [PATCH] Allow to call back when a plugin is loaded. Signed-off-by: Madhu Venugopal --- pkg/plugins/client.go | 2 +- pkg/plugins/plugins.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/plugins/client.go b/pkg/plugins/client.go index f89253dad0..ab429f0689 100644 --- a/pkg/plugins/client.go +++ b/pkg/plugins/client.go @@ -15,7 +15,7 @@ import ( const ( versionMimetype = "appplication/vnd.docker.plugins.v1+json" - defaultTimeOut = 120 + defaultTimeOut = 30 ) func NewClient(addr string) *Client { diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go index af2111e758..47519486bd 100644 --- a/pkg/plugins/plugins.go +++ b/pkg/plugins/plugins.go @@ -16,7 +16,10 @@ type plugins struct { plugins map[string]*Plugin } -var storage = plugins{plugins: make(map[string]*Plugin)} +var ( + storage = plugins{plugins: make(map[string]*Plugin)} + extpointHandlers = make(map[string]func(string, *Client)) +) type Manifest struct { Implements []string @@ -39,6 +42,13 @@ func (p *Plugin) activate() error { logrus.Debugf("%s's manifest: %v", p.Name, m) p.Manifest = m + for _, iface := range m.Implements { + handler, handled := extpointHandlers[iface] + if !handled { + continue + } + handler(p.Name, p.Client) + } return nil } @@ -84,3 +94,7 @@ func Get(name, imp string) (*Plugin, error) { } return nil, ErrNotImplements } + +func Handle(iface string, fn func(string, *Client)) { + extpointHandlers[iface] = fn +}