Class: Fusuma::Plugin::Inputs::Input Abstract

Inherits:
Base
  • Object
show all
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

LibinputCommandInput, TimerInput

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(*args)
  @tag = self.class.name.split("Inputs::").last.underscore
end

Instance Attribute Details

#tagObject (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

Parameters:

Returns:

  • (Event)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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 }

  begin
    # NOTE: io.readline is blocking method
    # each input plugin must write line to pipe (include `\n`)
    line = io.readline(chomp: true)
  rescue EOFError => e
    MultiLogger.error "#{input.class.name}: #{e}"
    MultiLogger.error "Shutdown fusuma process..."
    Process.kill("TERM", Process.pid)
  rescue => e
    MultiLogger.error "#{input.class.name}: #{e}"
    exit 1
  end
  input.create_event(record: line)
end

Instance Method Details

#create_event(record: "dummy input") ⇒ Event

Returns:

  • (Event)


54
55
56
57
58
# File 'lib/fusuma/plugin/inputs/input.rb', line 54

def create_event(record: "dummy input")
  e = Events::Event.new(tag: tag, record: record)
  MultiLogger.debug(input_event: e)
  e
end

#ioIO

Returns:

  • (IO)

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/fusuma/plugin/inputs/input.rb', line 49

def io
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end

#pidInteger

Returns:

  • (Integer)

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/fusuma/plugin/inputs/input.rb', line 44

def pid
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end