Class: Fluent::FlumeInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_flume.rb

Defined Under Namespace

Classes: FluentFlumeHandler

Instance Method Summary collapse

Constructor Details

#initializeFlumeInput

Returns a new instance of FlumeInput.



39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/in_flume.rb', line 39

def initialize
  require 'thrift'
  require 'fluent/plugin/old_thrift/flume_types'
  $:.unshift File.join(File.dirname(__FILE__), 'old_thrift')
  require 'flume_constants'
  require 'thrift_flume_event_server'
  super
end

Instance Method Details

#runObject



103
104
105
106
107
108
109
# File 'lib/fluent/plugin/in_flume.rb', line 103

def run
  log.debug "starting server: #{@server}"
  @server.serve
rescue
  log.error "unexpected error", :error=>$!.to_s
  log.error_backtrace
end

#shutdownObject



98
99
100
101
# File 'lib/fluent/plugin/in_flume.rb', line 98

def shutdown
  @transport.close unless @transport.closed?
  #@thread.join
end

#startObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fluent/plugin/in_flume.rb', line 48

def start
  log.debug "listening flume on #{@bind}:#{@port}"
  log.warn "[in_flume] This plugin is obsoleted for Flume NG. You should consider to use flume-ng-fluentd-sink."

  handler = FluentFlumeHandler.new
  handler.tag_field = @tag_field
  handler.default_tag = @default_tag
  handler.add_prefix = @add_prefix
  handler.msg_format = @msg_format
  handler.log = log
  handler.router = router
  processor = ThriftFlumeEventServer::Processor.new handler

  @transport = Thrift::ServerSocket.new @bind, @port
  unless @is_framed
    transport_factory = Thrift::BufferedTransportFactory.new
  else
    raise ConfigError, "in_flume: unsupported is_framed '#{@is_framed}'"
  end

  unless ['text', 'json'].include? @msg_format
    raise 'Unknown format: msg_format=#{@msg_format}'
  end

  # 2011/09/29 Kazuki Ohta <[email protected]>
  # This section is a workaround to set strict_read and strict_write option.
  # Ruby-Thrift 0.7 set them both 'true' in default, but Flume protocol set
  # them both 'false'.
  protocol_factory = Thrift::BinaryProtocolFactory.new
  protocol_factory.instance_eval {|obj|
    def get_protocol(trans) # override
      return Thrift::BinaryProtocol.new(trans,
                                        strict_read=false,
                                        strict_write=false)
    end
  }

  case @server_type
  when 'simple'
    @server = Thrift::SimpleServer.new processor, @transport, transport_factory, protocol_factory
  when 'threaded'
    @server = Thrift::ThreadedServer.new processor, @transport, transport_factory, protocol_factory
  when 'thread_pool'
    @server = Thrift::ThreadPoolServer.new processor, @transport, transport_factory, protocol_factory
  else
    raise ConfigError, "in_flume: unsupported server_type '#{@server_type}'"
  end
  @thread = Thread.new(&method(:run))
end