Skip to content
Merged
25 changes: 8 additions & 17 deletions lib/ldclient-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@
module LaunchDarkly
end

require "ldclient-rb/version"
require "ldclient-rb/interfaces"
require "ldclient-rb/util"
require "ldclient-rb/flags_state"
require "ldclient-rb/migrations"
require "ldclient-rb/ldclient"
require "ldclient-rb/cache_store"
require "ldclient-rb/expiring_cache"
require "ldclient-rb/memoized_value"
require "ldclient-rb/in_memory_store"
# Public APIs - these define the main interfaces users interact with
require "ldclient-rb/config"
require "ldclient-rb/context"
require "ldclient-rb/reference"
require "ldclient-rb/stream"
require "ldclient-rb/polling"
require "ldclient-rb/simple_lru_cache"
require "ldclient-rb/non_blocking_thread_pool"
require "ldclient-rb/events"
require "ldclient-rb/requestor"
require "ldclient-rb/flags_state"
require "ldclient-rb/integrations"
require "ldclient-rb/interfaces"
require "ldclient-rb/ldclient"
require "ldclient-rb/migrations"
require "ldclient-rb/reference"
require "ldclient-rb/util"
require "ldclient-rb/version"
45 changes: 0 additions & 45 deletions lib/ldclient-rb/cache_store.rb

This file was deleted.

7 changes: 4 additions & 3 deletions lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "logger"
require "ldclient-rb/impl/cache_store"

module LaunchDarkly
#
Expand Down Expand Up @@ -96,7 +97,7 @@ def initialize(opts = {})
# Custom data source implementations should integrate with this sink if
# they want to provide support for data source status listeners.
#
# @private
# @api private
#
attr_accessor :data_source_update_sink

Expand All @@ -108,7 +109,7 @@ def initialize(opts = {})
# property is not supported; it is temporarily being exposed to maintain
# backwards compatibility while the SDK structure is updated.
#
# @private
# @api private
#
attr_accessor :instance_id

Expand Down Expand Up @@ -477,7 +478,7 @@ def self.default_events_uri
# @return [Object] the Rails cache if in Rails, or a simple in-memory implementation otherwise
#
def self.default_cache_store
defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : Impl::ThreadSafeMemoryStore.new
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LDContext
attr_reader :error

#
# @private
# @api private
# @param key [String, nil]
# @param fully_qualified_key [String, nil]
# @param kind [String, nil]
Expand Down
40 changes: 21 additions & 19 deletions lib/ldclient-rb/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "ldclient-rb/impl/event_sender"
require "ldclient-rb/impl/event_summarizer"
require "ldclient-rb/impl/event_types"
require "ldclient-rb/impl/non_blocking_thread_pool"
require "ldclient-rb/impl/simple_lru_cache"
require "ldclient-rb/impl/util"

require "concurrent"
Expand Down Expand Up @@ -70,24 +72,24 @@ def stop
MAX_FLUSH_WORKERS = 5
private_constant :MAX_FLUSH_WORKERS

# @private
# @api private
class NullEventProcessor
include EventProcessorMethods
end

# @private
# @api private
class FlushMessage
end

# @private
# @api private
class FlushContextsMessage
end

# @private
# @api private
class DiagnosticEventMessage
end

# @private
# @api private
class SynchronousMessage
def initialize
@reply = Concurrent::Semaphore.new(0)
Expand All @@ -102,15 +104,15 @@ def wait_for_completion
end
end

# @private
# @api private
class TestSyncMessage < SynchronousMessage
end

# @private
# @api private
class StopMessage < SynchronousMessage
end

# @private
# @api private
class EventProcessor
include EventProcessorMethods

Expand Down Expand Up @@ -141,7 +143,7 @@ def initialize(sdk_key, config, client = nil, diagnostic_accumulator = nil, test
@inbox_full = Concurrent::AtomicBoolean.new(false)

event_sender = (test_properties || {})[:event_sender] ||
Impl::EventSender.new(sdk_key, config, client || Util.new_http_client(config.events_uri, config))
Impl::EventSender.new(sdk_key, config, client || Impl::Util.new_http_client(config.events_uri, config))

@timestamp_fn = (test_properties || {})[:timestamp_fn] || proc { Impl::Util.current_time_millis }
@omit_anonymous_contexts = config.omit_anonymous_contexts
Expand Down Expand Up @@ -226,7 +228,7 @@ def wait_until_inactive
end
end

# @private
# @api private
class EventDispatcher
def initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender)
@sdk_key = sdk_key
Expand All @@ -235,18 +237,18 @@ def initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender)
@event_sender = event_sender
@sampler = LaunchDarkly::Impl::Sampler.new(Random.new)

@context_keys = SimpleLRUCacheSet.new(config.context_keys_capacity)
@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 = NonBlockingThreadPool.new(MAX_FLUSH_WORKERS, 'LD/EventDispatcher/FlushWorkers')
flush_workers = Impl::NonBlockingThreadPool.new(MAX_FLUSH_WORKERS, 'LD/EventDispatcher/FlushWorkers')

if !@diagnostic_accumulator.nil?
diagnostic_event_workers = NonBlockingThreadPool.new(1, 'LD/EventDispatcher/DiagnosticEventWorkers')
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
Expand Down Expand Up @@ -281,7 +283,7 @@ def main_loop(inbox, outbox, flush_workers, diagnostic_event_workers)
dispatch_event(message, outbox)
end
rescue => e
Util.log_exception(@config.logger, "Unexpected error in event processor", e)
Impl::Util.log_exception(@config.logger, "Unexpected error in event processor", e)
end
end
end
Expand Down Expand Up @@ -383,7 +385,7 @@ def trigger_flush(outbox, flush_workers)
@last_known_past_time.value = (result.time_from_server.to_f * 1000).to_i
end
rescue => e
Util.log_exception(@config.logger, "Unexpected error in event processor", e)
Impl::Util.log_exception(@config.logger, "Unexpected error in event processor", e)
end
end
outbox.clear if success # Reset our internal state, these events now belong to the flush worker
Expand All @@ -408,16 +410,16 @@ def send_diagnostic_event(event, diagnostic_event_workers)
begin
@event_sender.send_event_data(event.to_json, "diagnostic event", true)
rescue => e
Util.log_exception(@config.logger, "Unexpected error in event processor", e)
Impl::Util.log_exception(@config.logger, "Unexpected error in event processor", e)
end
end
end
end

# @private
# @api private
FlushPayload = Struct.new(:events, :summary)

# @private
# @api private
class EventBuffer
def initialize(capacity, logger)
@capacity = capacity
Expand Down Expand Up @@ -461,7 +463,7 @@ def clear
end
end

# @private
# @api private
class EventOutputFormatter
FEATURE_KIND = 'feature'
IDENTIFY_KIND = 'identify'
Expand Down
77 changes: 0 additions & 77 deletions lib/ldclient-rb/expiring_cache.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/ldclient-rb/flags_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(valid)
end

# Used internally to build the state map.
# @private
# @api private
def add_flag(flag_state, with_reasons, details_only_if_tracked)
key = flag_state[:key]
@flag_values[key] = flag_state[:value]
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module LaunchDarkly
# and subject to change.
#
# @since 5.5.0
# @private
# @api private
#
module Impl
# code is in ldclient-rb/impl/
Expand Down
8 changes: 4 additions & 4 deletions lib/ldclient-rb/impl/big_segments.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "ldclient-rb/config"
require "ldclient-rb/expiring_cache"
require "ldclient-rb/impl/expiring_cache"
require "ldclient-rb/impl/repeating_task"
require "ldclient-rb/impl/util"
require "ldclient-rb/interfaces"
require "ldclient-rb/util"

require "digest"

Expand Down Expand Up @@ -45,7 +45,7 @@ def get_context_membership(context_key)
membership = EMPTY_MEMBERSHIP if membership.nil?
@cache[context_key] = membership
rescue => e
LaunchDarkly::Util.log_exception(@logger, "Big Segment store membership query returned error", e)
Impl::Util.log_exception(@logger, "Big Segment store membership query returned error", e)
return BigSegmentMembershipResult.new(nil, BigSegmentsStatus::STORE_ERROR)
end
end
Expand All @@ -67,7 +67,7 @@ def poll_store_and_update_status
metadata = @store.get_metadata
new_status = Interfaces::BigSegmentStoreStatus.new(true, !metadata || stale?(metadata.last_up_to_date))
rescue => e
LaunchDarkly::Util.log_exception(@logger, "Big Segment store status query returned error", e)
Impl::Util.log_exception(@logger, "Big Segment store status query returned error", e)
end
end
@last_status = new_status
Expand Down
Loading