builtin.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2021-2023 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package io
  15. import (
  16. "github.com/lf-edge/ekuiper/internal/io/file"
  17. "github.com/lf-edge/ekuiper/internal/io/http"
  18. "github.com/lf-edge/ekuiper/internal/io/memory"
  19. "github.com/lf-edge/ekuiper/internal/io/mqtt"
  20. "github.com/lf-edge/ekuiper/internal/io/neuron"
  21. "github.com/lf-edge/ekuiper/internal/io/sink"
  22. plugin2 "github.com/lf-edge/ekuiper/internal/plugin"
  23. "github.com/lf-edge/ekuiper/pkg/api"
  24. )
  25. type (
  26. NewSourceFunc func() api.Source
  27. NewLookupSourceFunc func() api.LookupSource
  28. NewSinkFunc func() api.Sink
  29. )
  30. var (
  31. sources = map[string]NewSourceFunc{
  32. "mqtt": func() api.Source { return &mqtt.MQTTSource{} },
  33. "httppull": func() api.Source { return &http.PullSource{} },
  34. "httppush": func() api.Source { return &http.PushSource{} },
  35. "file": func() api.Source { return &file.FileSource{} },
  36. "memory": func() api.Source { return memory.GetSource() },
  37. "neuron": func() api.Source { return neuron.GetSource() },
  38. }
  39. sinks = map[string]NewSinkFunc{
  40. "log": sink.NewLogSink,
  41. "logToMemory": sink.NewLogSinkToMemory,
  42. "mqtt": func() api.Sink { return &mqtt.MQTTSink{} },
  43. "rest": func() api.Sink { return &http.RestSink{} },
  44. "nop": func() api.Sink { return &sink.NopSink{} },
  45. "memory": func() api.Sink { return memory.GetSink() },
  46. "neuron": func() api.Sink { return neuron.GetSink() },
  47. "file": func() api.Sink { return file.File() },
  48. }
  49. lookupSources = map[string]NewLookupSourceFunc{
  50. "memory": func() api.LookupSource { return memory.GetLookupSource() },
  51. }
  52. )
  53. type Manager struct{}
  54. func (m *Manager) Source(name string) (api.Source, error) {
  55. if s, ok := sources[name]; ok {
  56. return s(), nil
  57. }
  58. return nil, nil
  59. }
  60. func (m *Manager) SourcePluginInfo(name string) (plugin2.EXTENSION_TYPE, string, string) {
  61. if _, ok := sources[name]; ok {
  62. return plugin2.INTERNAL, "", ""
  63. } else {
  64. return plugin2.NONE_EXTENSION, "", ""
  65. }
  66. }
  67. func (m *Manager) LookupSource(name string) (api.LookupSource, error) {
  68. if s, ok := lookupSources[name]; ok {
  69. return s(), nil
  70. }
  71. return nil, nil
  72. }
  73. func (m *Manager) Sink(name string) (api.Sink, error) {
  74. if s, ok := sinks[name]; ok {
  75. return s(), nil
  76. }
  77. return nil, nil
  78. }
  79. func (m *Manager) SinkPluginInfo(name string) (plugin2.EXTENSION_TYPE, string, string) {
  80. if _, ok := sinks[name]; ok {
  81. return plugin2.INTERNAL, "", ""
  82. } else {
  83. return plugin2.NONE_EXTENSION, "", ""
  84. }
  85. }
  86. var m = &Manager{}
  87. func GetManager() *Manager {
  88. return m
  89. }