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
2. add events
   stream[tag].add(time, record)

Instance Method Summary collapse

Methods inherited from EventStream

#to_msgpack_stream

Constructor Details

#initializeMultiEventStream

Returns a new instance of MultiEventStream.



100
101
102
103
# File 'lib/fluent/event.rb', line 100

def initialize
  @time_array = []
  @record_array = []
end

Instance Method Details

#add(time, record) ⇒ Object



113
114
115
116
# File 'lib/fluent/event.rb', line 113

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

#dupObject



105
106
107
108
109
110
111
# File 'lib/fluent/event.rb', line 105

def dup
  es = MultiEventStream.new
  @time_array.zip(@record_array).each { |time, record|
    es.add(time, record.dup)
  }
  es
end

#each(&block) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/fluent/event.rb', line 126

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)


122
123
124
# File 'lib/fluent/event.rb', line 122

def empty?
  @time_array.empty?
end

#repeatable?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/fluent/event.rb', line 118

def repeatable?
  true
end