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.



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

def initialize
  require 'thrift'
  $:.unshift File.join(File.dirname(__FILE__), 'thrift')
  require 'flume_types'
  require 'flume_constants'
  require 'thrift_flume_event_server'

  super
end

Instance Method Details

#configure(conf) ⇒ Object



50
51
52
# File 'lib/fluent/plugin/in_flume.rb', line 50

def configure(conf)
  super
end

#runObject



107
108
109
110
111
112
113
# File 'lib/fluent/plugin/in_flume.rb', line 107

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

#shutdownObject



102
103
104
105
# File 'lib/fluent/plugin/in_flume.rb', line 102

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

#startObject



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
97
98
99
100
# File 'lib/fluent/plugin/in_flume.rb', line 54

def start
  log.debug "listening flume on #{@bind}:#{@port}"

  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
  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