Class: LogStash::Util::WrappedSynchronousQueue::ReadBatch

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/util/wrapped_synchronous_queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(queue, size, wait) ⇒ ReadBatch

Returns a new instance of ReadBatch.



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 188

def initialize(queue, size, wait)
  @queue = queue
  @size = size
  @wait = wait

  @originals = Hash.new

  # TODO: disabled for https://github.com/elastic/logstash/issues/6055 - will have to properly refactor
  # @cancelled = Hash.new

  @generated = Hash.new
  @iterating_temp = Hash.new
  @iterating = false # Atomic Boolean maybe? Although batches are not shared across threads
  @acked_batch = nil
end

Instance Method Details

#cancel(event) ⇒ Object



225
226
227
228
229
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 225

def cancel(event)
  # TODO: disabled for https://github.com/elastic/logstash/issues/6055 - will have to properly refactor
  raise("cancel is unsupported")
  # @cancelled[event] = true
end

#cancelled_sizeObject



259
260
261
262
263
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 259

def cancelled_size
# TODO: disabled for https://github.com/elastic/logstash/issues/6055 = will have to properly refactor
raise("cancelled_size is unsupported ")
  # @cancelled.size
end

#each(&blk) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 231

def each(&blk)
  # take care not to cause @originals or @generated to change during iteration
  @iterating = true

  # below the checks for @cancelled.include?(e) have been replaced by e.cancelled?
  # TODO: for https://github.com/elastic/logstash/issues/6055 = will have to properly refactor
  @originals.each do |e, _|
    blk.call(e) unless e.cancelled?
  end
  @generated.each do |e, _|
    blk.call(e) unless e.cancelled?
  end
  @iterating = false
  update_generated
end

#filtered_sizeObject



255
256
257
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 255

def filtered_size
  @originals.size + @generated.size
end

#merge(event) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 213

def merge(event)
  return if event.nil? || @originals.key?(event)
  # take care not to cause @generated to change during iteration
  # @iterating_temp is merged after the iteration
  if iterating?
    @iterating_temp[event] = true
  else
    # the periodic flush could generate events outside of an each iteration
    @generated[event] = true
  end
end

#read_nextObject



204
205
206
207
208
209
210
211
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 204

def read_next
  @size.times do |t|
    event = @queue.poll(@wait)
    return if event.nil? # queue poll timed out

    @originals[event] = true
  end
end

#sizeObject



247
248
249
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 247

def size
  filtered_size
end

#starting_sizeObject



251
252
253
# File 'lib/logstash/util/wrapped_synchronous_queue.rb', line 251

def starting_size
  @originals.size
end