Class: Fluent::RoundRobinOutput

Inherits:
MultiOutput show all
Defined in:
lib/fluent/plugin/out_roundrobin.rb

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary collapse

Attributes inherited from Output

#router

Attributes included from PluginLoggerMixin

#log

Instance Method Summary collapse

Methods inherited from Output

#secondary_init

Methods included from PluginLoggerMixin

included

Methods included from PluginId

#plugin_id

Methods included from Configurable

#config, included, lookup_type, register_type

Constructor Details

#initializeRoundRobinOutput

Returns a new instance of RoundRobinOutput.



24
25
26
27
28
29
# File 'lib/fluent/plugin/out_roundrobin.rb', line 24

def initialize
  super

  @outputs = []
  @weights = []
end

Instance Attribute Details

#outputsObject (readonly)

Returns the value of attribute outputs.



31
32
33
# File 'lib/fluent/plugin/out_roundrobin.rb', line 31

def outputs
  @outputs
end

#rand_seedObject

Returns the value of attribute rand_seed.



32
33
34
# File 'lib/fluent/plugin/out_roundrobin.rb', line 32

def rand_seed
  @rand_seed
end

#weightsObject (readonly)

Returns the value of attribute weights.



31
32
33
# File 'lib/fluent/plugin/out_roundrobin.rb', line 31

def weights
  @weights
end

Instance Method Details

#configure(conf) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fluent/plugin/out_roundrobin.rb', line 34

def configure(conf)
  super

  conf.elements.select {|e|
    e.name == 'store'
  }.each {|e|
    type = e['@type'] || e['type']
    unless type
      raise ConfigError, "Missing 'type' parameter on <store> directive"
    end

    weight = e['weight']
    weight = weight ? weight.to_i : 1
    log.debug "adding store type=#{type.dump}, weight=#{weight}"

    output = Plugin.new_output(type)
    output.router = router
    output.configure(e)
    @outputs << output
    @weights << weight
  }
  @rr = -1  # starts from @output[0]
  @rand_seed = Random.new.seed
end

#emit(tag, es, chain) ⇒ Object



73
74
75
# File 'lib/fluent/plugin/out_roundrobin.rb', line 73

def emit(tag, es, chain)
  next_output.emit(tag, es, chain)
end

#shutdownObject



67
68
69
70
71
# File 'lib/fluent/plugin/out_roundrobin.rb', line 67

def shutdown
  @outputs.each {|o|
    o.shutdown
  }
end

#startObject



59
60
61
62
63
64
65
# File 'lib/fluent/plugin/out_roundrobin.rb', line 59

def start
  rebuild_weight_array

  @outputs.each {|o|
    o.start
  }
end