Class: LaunchDarkly::EventDispatcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/events.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender) ⇒ EventDispatcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EventDispatcher.



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/ldclient-rb/events.rb', line 255

def initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender)
  @sdk_key = sdk_key
  @config = config
  @diagnostic_accumulator = diagnostic_accumulator
  @event_sender = event_sender
  @sampler = LaunchDarkly::Impl::Sampler.new(Random.new)

  @context_keys = Impl::SimpleLRUCacheSet.new(config.context_keys_capacity)
  @formatter = EventOutputFormatter.new(config)
  @disabled = Concurrent::AtomicBoolean.new(false)
  @last_known_past_time = Concurrent::AtomicReference.new(0)
  @deduplicated_contexts = 0
  @events_in_last_batch = 0

  outbox = EventBuffer.new(config.capacity, config.logger)
  flush_workers = Impl::NonBlockingThreadPool.new(MAX_FLUSH_WORKERS, 'LD/EventDispatcher/FlushWorkers')

  if !@diagnostic_accumulator.nil?
    diagnostic_event_workers = Impl::NonBlockingThreadPool.new(1, 'LD/EventDispatcher/DiagnosticEventWorkers')
    init_event = @diagnostic_accumulator.create_init_event(config)
    send_diagnostic_event(init_event, diagnostic_event_workers)
  else
    diagnostic_event_workers = nil
  end

  Thread.new { main_loop(inbox, outbox, flush_workers, diagnostic_event_workers) }.name = "LD/EventDispatcher#main_loop"
end