Class: Fluent::MultiEventStream

Inherits:
EventStream show all
Defined in:
lib/fluent/event.rb

Overview

EventStream from entries: numbers of pairs of time and record.

This class can handle many events more efficiently than ArrayEventStream because this class generate less objects than ArrayEventStream.

Use this class as below, in loop of data-enumeration:

1. initialize blank stream:
   streams[tag] ||= MultiEventStream.new
2. add events
   stream[tag].add(time, record)

Instance Method Summary collapse

Methods inherited from EventStream

#==, #to_compressed_msgpack_stream, #to_msgpack_stream, #to_msgpack_stream_forced_integer

Methods included from Plugin::Compressable

#compress, #decompress

Methods included from Fluent::MessagePackFactory::Mixin

#msgpack_factory, #msgpack_packer, #msgpack_unpacker

Constructor Details

#initialize(time_array = [], record_array = []) ⇒ MultiEventStream

Returns a new instance of MultiEventStream.



159
160
161
162
# File 'lib/fluent/event.rb', line 159

def initialize(time_array = [], record_array = [])
  @time_array = time_array
  @record_array = record_array
end

Instance Method Details

#add(time, record) ⇒ Object



172
173
174
175
# File 'lib/fluent/event.rb', line 172

def add(time, record)
  @time_array << time
  @record_array << record
end

#dupObject



164
165
166
# File 'lib/fluent/event.rb', line 164

def dup
  MultiEventStream.new(@time_array.dup, @record_array.map(&:dup))
end

#each(&block) ⇒ Object



189
190
191
192
193
194
195
196
# File 'lib/fluent/event.rb', line 189

def each(&block)
  time_array = @time_array
  record_array = @record_array
  for i in 0..time_array.length-1
    block.call(time_array[i], record_array[i])
  end
  nil
end

#empty?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/fluent/event.rb', line 181

def empty?
  @time_array.empty?
end

#repeatable?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/fluent/event.rb', line 177

def repeatable?
  true
end

#sizeObject



168
169
170
# File 'lib/fluent/event.rb', line 168

def size
  @time_array.size
end

#slice(index, num) ⇒ Object



185
186
187
# File 'lib/fluent/event.rb', line 185

def slice(index, num)
  MultiEventStream.new(@time_array.slice(index, num), @record_array.slice(index, num))
end