Class: Fusuma::Plugin::Inputs::Input Abstract
- Defined in:
- lib/fusuma/plugin/inputs/input.rb
Overview
This class is abstract.
Subclass and override #io to implement
Inherite this base
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Class Method Summary collapse
-
.select(inputs) ⇒ Event
Wait multiple inputs until it becomes readable.
Instance Method Summary collapse
- #create_event(record: "dummy input") ⇒ Event
-
#initialize(*args) ⇒ Input
constructor
A new instance of Input.
- #io ⇒ IO
-
#read_from_io ⇒ String, Record
IO#readline is blocking method so input plugin must write line to pipe (include ‘n`) or, override read_from_io and implement your own read method.
Methods inherited from Base
#config_index, #config_param_types, #config_params, inherited, plugins, #shutdown
Constructor Details
#initialize(*args) ⇒ Input
Returns a new instance of Input.
12 13 14 15 |
# File 'lib/fusuma/plugin/inputs/input.rb', line 12 def initialize(*args) super @tag = self.class.name.split("Inputs::").last.underscore end |
Instance Attribute Details
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
17 18 19 |
# File 'lib/fusuma/plugin/inputs/input.rb', line 17 def tag @tag end |
Class Method Details
.select(inputs) ⇒ Event
Wait multiple inputs until it becomes readable
22 23 24 25 26 27 28 29 |
# File 'lib/fusuma/plugin/inputs/input.rb', line 22 def self.select(inputs) ios = IO.select(inputs.map(&:io)) io = ios&.first&.first input = inputs.find { |i| i.io == io } input.create_event(record: input.read_from_io) end |
Instance Method Details
#create_event(record: "dummy input") ⇒ Event
52 53 54 55 56 |
# File 'lib/fusuma/plugin/inputs/input.rb', line 52 def create_event(record: "dummy input") e = Events::Event.new(tag: tag, record: record) MultiLogger.debug(input_event: e) e end |
#io ⇒ IO
47 48 49 |
# File 'lib/fusuma/plugin/inputs/input.rb', line 47 def io raise NotImplementedError, "override #{self.class.name}##{__method__}" end |
#read_from_io ⇒ String, Record
IO#readline is blocking method so input plugin must write line to pipe (include ‘n`) or, override read_from_io and implement your own read method
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fusuma/plugin/inputs/input.rb', line 35 def read_from_io io.readline(chomp: true) rescue EOFError => e MultiLogger.error "#{self.class.name}: #{e}" MultiLogger.error "Shutdown fusuma process..." Process.kill("TERM", Process.pid) rescue => e MultiLogger.error "#{self.class.name}: #{e}" exit 1 end |