summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-14 18:18:58 +0300
committerGitHub <[email protected]>2021-06-14 18:18:58 +0300
commite30bc57f13023c15775925b7cc3b3fcbb9f2b55c (patch)
treed116452cf8d7a53d4dd3b431bdb76ee76f134ea1 /plugins
parentaeaf67900cbd9dff5bd7318eb4d79e302331e457 (diff)
parent63687937d0189359c48288e16afca8f56c3cda93 (diff)
#725 feat(plugin): make `in-memory` plugin general for the KV and WS
#725 feat(plugin): make `in-memory` plugin general for the KV and WS
Diffstat (limited to 'plugins')
-rw-r--r--plugins/kv/drivers/memory/plugin.go68
-rw-r--r--plugins/memory/config.go (renamed from plugins/kv/drivers/memory/config.go)0
-rw-r--r--plugins/memory/kv.go (renamed from plugins/kv/drivers/memory/driver.go)0
-rw-r--r--plugins/memory/plugin.go42
4 files changed, 40 insertions, 70 deletions
diff --git a/plugins/kv/drivers/memory/plugin.go b/plugins/kv/drivers/memory/plugin.go
deleted file mode 100644
index da81017e..00000000
--- a/plugins/kv/drivers/memory/plugin.go
+++ /dev/null
@@ -1,68 +0,0 @@
-package memory
-
-import (
- "github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/plugins/config"
- "github.com/spiral/roadrunner/v2/plugins/kv"
- "github.com/spiral/roadrunner/v2/plugins/logger"
-)
-
-// PluginName is user friendly name for the plugin
-const PluginName = "memory"
-
-type Plugin struct {
- // heap is user map for the key-value pairs
- stop chan struct{}
-
- log logger.Logger
- cfgPlugin config.Configurer
- drivers uint
-}
-
-func (s *Plugin) Init(cfg config.Configurer, log logger.Logger) error {
- const op = errors.Op("in_memory_plugin_init")
- if !cfg.Has(kv.PluginName) {
- return errors.E(op, errors.Disabled)
- }
-
- s.log = log
- s.cfgPlugin = cfg
- s.stop = make(chan struct{}, 1)
- return nil
-}
-
-func (s *Plugin) Serve() chan error {
- return make(chan error, 1)
-}
-
-func (s *Plugin) Stop() error {
- if s.drivers > 0 {
- for i := uint(0); i < s.drivers; i++ {
- // send close signal to every driver
- s.stop <- struct{}{}
- }
- }
- return nil
-}
-
-func (s *Plugin) KVProvide(key string) (kv.Storage, error) {
- const op = errors.Op("inmemory_plugin_provide")
- st, err := NewInMemoryDriver(s.log, key, s.cfgPlugin, s.stop)
- if err != nil {
- return nil, errors.E(op, err)
- }
-
- // save driver number to release resources after Stop
- s.drivers++
-
- return st, nil
-}
-
-// Name returns plugin user-friendly name
-func (s *Plugin) Name() string {
- return PluginName
-}
-
-// Available interface implementation
-func (s *Plugin) Available() {
-}
diff --git a/plugins/kv/drivers/memory/config.go b/plugins/memory/config.go
index e51d09c5..e51d09c5 100644
--- a/plugins/kv/drivers/memory/config.go
+++ b/plugins/memory/config.go
diff --git a/plugins/kv/drivers/memory/driver.go b/plugins/memory/kv.go
index 9b7d7259..9b7d7259 100644
--- a/plugins/kv/drivers/memory/driver.go
+++ b/plugins/memory/kv.go
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
}