diff options
Diffstat (limited to 'plugins/memory/plugin.go')
-rw-r--r-- | plugins/memory/plugin.go | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/plugins/memory/plugin.go b/plugins/memory/plugin.go index 650f0b4b..6151ebf0 100644 --- a/plugins/memory/plugin.go +++ b/plugins/memory/plugin.go @@ -1,18 +1,43 @@ package memory import ( + "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/pkg/pubsub" + "github.com/spiral/roadrunner/v2/plugins/config" + "github.com/spiral/roadrunner/v2/plugins/kv" "github.com/spiral/roadrunner/v2/plugins/logger" ) const PluginName string = "memory" type Plugin struct { - log logger.Logger + // heap is user map for the key-value pairs + stop chan struct{} + + log logger.Logger + cfgPlugin config.Configurer + drivers uint } -func (p *Plugin) Init(log logger.Logger) error { +func (p *Plugin) Init(log logger.Logger, cfg config.Configurer) error { + p.log = log p.log = log + p.cfgPlugin = cfg + p.stop = make(chan struct{}, 1) + return nil +} + +func (p *Plugin) Serve() chan error { + return make(chan error, 1) +} + +func (p *Plugin) Stop() error { + if p.drivers > 0 { + for i := uint(0); i < p.drivers; i++ { + // send close signal to every driver + p.stop <- struct{}{} + } + } return nil } @@ -20,6 +45,19 @@ func (p *Plugin) PSProvide(key string) (pubsub.PubSub, error) { return NewPubSubDriver(p.log, key) } +func (p *Plugin) KVProvide(key string) (kv.Storage, error) { + const op = errors.Op("inmemory_plugin_provide") + st, err := NewInMemoryDriver(p.log, key, p.cfgPlugin, p.stop) + if err != nil { + return nil, errors.E(op, err) + } + + // save driver number to release resources after Stop + p.drivers++ + + return st, nil +} + func (p *Plugin) Name() string { return PluginName } |