Class: LogStash::Util::WrappedAckedQueue::ReadBatch

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

Instance Method Summary collapse

Constructor Details

#initialize(queue, size, wait) ⇒ ReadBatch

Returns a new instance of ReadBatch.



215
216
217
218
219
220
221
222
223
224
225
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 215

def initialize(queue, size, 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
  take_originals_from_queue(queue, size, wait) # this sets a reference to @acked_batch
end

Instance Method Details

#cancel(event) ⇒ Object



246
247
248
249
250
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 246

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



280
281
282
283
284
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 280

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

#closeObject



227
228
229
230
231
232
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 227

def close
  # this will ack the whole batch, regardless of whether some
  # events were cancelled or failed
  return if @acked_batch.nil?
  @acked_batch.close
end

#each(&blk) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 252

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

  # 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
  @iterating = true
  @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



276
277
278
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 276

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

#flush_signal_received?Boolean

Returns:

  • (Boolean)


290
291
292
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 290

def flush_signal_received?
  false
end

#merge(event) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 234

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

#shutdown_signal_received?Boolean

Returns:

  • (Boolean)


286
287
288
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 286

def shutdown_signal_received?
  false
end

#sizeObject



268
269
270
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 268

def size
  filtered_size
end

#starting_sizeObject



272
273
274
# File 'lib/logstash/util/wrapped_acked_queue.rb', line 272

def starting_size
  @originals.size
end