Class: Fwd::Output

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fwd/output.rb

Constant Summary collapse

RESCUABLE =
[
  Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EPIPE,
  Errno::ENETUNREACH, Errno::ENETDOWN, Errno::EINVAL, Errno::ETIMEDOUT,
  IOError, EOFError
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ Output

Constructor

Parameters:



15
16
17
18
19
20
21
# File 'lib/fwd/output.rb', line 15

def initialize(core)
  backends = Array(core.opts[:forward]).compact.map do |s|
    Fwd::Backend.new(s)
  end
  @core = core
  @pool = Fwd::Pool.new(backends)
end

Instance Attribute Details

#coreObject (readonly)

Returns the value of attribute core.



11
12
13
# File 'lib/fwd/output.rb', line 11

def core
  @core
end

#poolObject (readonly)

Returns the value of attribute pool.



11
12
13
# File 'lib/fwd/output.rb', line 11

def pool
  @pool
end

Instance Method Details

#forward!Object

Callback



24
25
26
27
28
29
30
31
# File 'lib/fwd/output.rb', line 24

def forward!
  Dir[root.join("#{prefix}.*.closed")].each do |file|
    reserve(file) do |data|
      logger.debug { "Flushing #{File.basename(file)}, #{data.size.fdiv(1024).round} kB" }
      write(data)
    end
  end
end

#write(data) ⇒ Object

Parameters:

  • binary (String)

    data



34
35
36
37
38
# File 'lib/fwd/output.rb', line 34

def write(data)
  pool.any? do |backend|
    forward(backend, data)
  end
end