Class: LaunchDarkly::EventDispatcher

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of EventDispatcher.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/ldclient-rb/events.rb', line 218

def initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender)
  @sdk_key = sdk_key
  @config = config
  @diagnostic_accumulator = config.diagnostic_opt_out? ? nil : diagnostic_accumulator
  @event_sender = event_sender

  @context_keys = 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 = NonBlockingThreadPool.new(MAX_FLUSH_WORKERS)

  if !@diagnostic_accumulator.nil?
    diagnostic_event_workers = NonBlockingThreadPool.new(1)
    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) }
end