Class: SplitIoClient::SplitFactory
- Inherits:
-
Object
- Object
- SplitIoClient::SplitFactory
- Includes:
- Cache::Fetchers, Cache::Repositories, Cache::Senders, Cache::Stores
- Defined in:
- lib/splitclient-rb/split_factory.rb
Constant Summary collapse
- ROOT_PROCESS_ID =
Process.pid
- SINGLETON_WARN =
'We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'
- LOCALHOST_API_KEY =
'localhost'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
Instance Method Summary collapse
-
#initialize(api_key, config_hash = {}) ⇒ SplitFactory
constructor
A new instance of SplitFactory.
- #register_factory ⇒ Object
- #start! ⇒ Object (also: #resume!)
- #stop! ⇒ Object
- #valid_mode ⇒ Object
Constructor Details
#initialize(api_key, config_hash = {}) ⇒ SplitFactory
Returns a new instance of SplitFactory.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/splitclient-rb/split_factory.rb', line 14 def initialize(api_key, config_hash = {}) at_exit do unless ENV['SPLITCLIENT_ENV'] == 'test' if (Process.pid == ROOT_PROCESS_ID) @config.logger.info('Split SDK shutdown started...') @client.destroy if @client stop! @config.logger.info('Split SDK shutdown complete') end end end @api_key = api_key @config = SplitConfig.new(config_hash.merge(localhost_mode: @api_key == LOCALHOST_API_KEY )) raise 'Invalid SDK mode' unless valid_mode build_telemetry_components @splits_repository = SplitsRepository.new(@config) @segments_repository = SegmentsRepository.new(@config) @impressions_repository = ImpressionsRepository.new(@config) @events_repository = EventsRepository.new(@config, @api_key, @runtime_producer) @sdk_blocker = SDKBlocker.new(@splits_repository, @segments_repository, @config) @impression_counter = SplitIoClient::Engine::Common::ImpressionCounter.new @impressions_manager = SplitIoClient::Engine::Common::ImpressionManager.new(@config, @impressions_repository, @impression_counter, @runtime_producer) @telemetry_api = SplitIoClient::Api::TelemetryApi.new(@config, @api_key, @runtime_producer) @telemetry_synchronizer = Telemetry::Synchronizer.new(@config, @telemetry_consumers, @init_producer, repositories, @telemetry_api) start! @client = SplitClient.new(@api_key, repositories, @sdk_blocker, @config, @impressions_manager, @evaluation_producer) @manager = SplitManager.new(@splits_repository, @sdk_blocker, @config) validate_api_key register_factory end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
12 13 14 |
# File 'lib/splitclient-rb/split_factory.rb', line 12 def adapter @adapter end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
12 13 14 |
# File 'lib/splitclient-rb/split_factory.rb', line 12 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/splitclient-rb/split_factory.rb', line 12 def config @config end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
12 13 14 |
# File 'lib/splitclient-rb/split_factory.rb', line 12 def manager @manager end |
Instance Method Details
#register_factory ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/splitclient-rb/split_factory.rb', line 76 def register_factory SplitIoClient.load_factory_registry number_of_factories = SplitIoClient.split_factory_registry.number_of_factories_for(@api_key) if(number_of_factories > 0) @config.logger.warn("Factory instantiation: You already have #{number_of_factories} factories with this API Key. #{SINGLETON_WARN}") elsif(SplitIoClient.split_factory_registry.other_factories) @config.logger.warn('Factory instantiation: You already have an instance of the Split factory.' \ " Make sure you definitely want this additional instance. #{SINGLETON_WARN}") end SplitIoClient.split_factory_registry.add(@api_key) end |
#start! ⇒ Object Also known as: resume!
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/splitclient-rb/split_factory.rb', line 53 def start! if @config.localhost_mode start_localhost_components else split_fetcher = SplitFetcher.new(@splits_repository, @api_key, config, @sdk_blocker, @runtime_producer) segment_fetcher = SegmentFetcher.new(@segments_repository, @api_key, config, @sdk_blocker, @runtime_producer) params = { split_fetcher: split_fetcher, segment_fetcher: segment_fetcher, imp_counter: @impression_counter, telemetry_runtime_producer: @runtime_producer, telemetry_synchronizer: @telemetry_synchronizer } synchronizer = SplitIoClient::Engine::Synchronizer.new(repositories, @api_key, @config, @sdk_blocker, params) SplitIoClient::Engine::SyncManager.new(repositories, @api_key, @config, synchronizer, @runtime_producer, @sdk_blocker, @telemetry_synchronizer).start end end |
#stop! ⇒ Object
72 73 74 |
# File 'lib/splitclient-rb/split_factory.rb', line 72 def stop! @config.threads.each { |_, t| t.exit } end |
#valid_mode ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/splitclient-rb/split_factory.rb', line 91 def valid_mode valid_startup_mode = false case @config.mode when :consumer if @config.cache_adapter.is_a? SplitIoClient::Cache::Adapters::RedisAdapter if !@config.localhost_mode valid_startup_mode = true else @config.logger.error('Localhost mode cannot be used with Redis. ' \ 'Use standalone mode and Memory adapter instead.') end else @config.logger.error('Consumer mode cannot be used with Memory adapter. ' \ 'Use Redis adapter instead.') end when :standalone if @config.cache_adapter.is_a? SplitIoClient::Cache::Adapters::MemoryAdapter valid_startup_mode = true else @config.logger.error('Standalone mode cannot be used with Redis adapter. ' \ 'Use Memory adapter instead.') end when :producer @config.logger.error('Producer mode is no longer supported. Use Split Synchronizer. ' \ 'See: https://github.com/splitio/split-synchronizer') else @config.logger.error('Invalid SDK mode selected. ' \ "Valid modes are 'standalone with memory adapter' and 'consumer with redis adapter'") end valid_startup_mode end |