Class: InnerClient
- Inherits:
-
ClientCallback
- Object
- Closeable
- ClientCallback
- InnerClient
- Defined in:
- lib/ff/ruby/server/sdk/api/inner_client.rb
Constant Summary
Constants inherited from ClientCallback
Instance Method Summary collapse
- #bool_variation(identifier, target, default_value) ⇒ Object
- #close ⇒ Object
-
#initialize(api_key = nil, config = nil, connector = nil) ⇒ InnerClient
constructor
A new instance of InnerClient.
- #is_closing ⇒ Object
- #json_variation(identifier, target, default_value) ⇒ Object
- #number_variation(identifier, target, default_value) ⇒ Object
- #off ⇒ Object
- #on_auth_failed ⇒ Object
- #on_auth_success ⇒ Object
- #on_metrics_processor_ready ⇒ Object
- #on_poller_error(e) ⇒ Object
- #on_poller_iteration(poller) ⇒ Object
- #on_poller_ready(poller) ⇒ Object
- #on_processor_ready(processor) ⇒ Object
- #on_unauthorized ⇒ Object
- #on_update_processor_ready ⇒ Object
- #string_variation(identifier, target, default_value) ⇒ Object
- #update(message, manual) ⇒ Object
- #wait_for_initialization(timeout: nil) ⇒ Object
Methods inherited from ClientCallback
Constructor Details
#initialize(api_key = nil, config = nil, connector = nil) ⇒ InnerClient
Returns a new instance of InnerClient.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 19 def initialize(api_key = nil, config = nil, connector = nil) if api_key == nil || api_key == "" SdkCodes::raise_missing_sdk_key config.logger end if config == nil @config = ConfigBuilder.new.build else unless config.kind_of?(Config) raise "The 'config' parameter must be of '" + Config.to_s + "' data type" end @config = config end @config.logger.debug "Ruby SDK version: " + Ff::Ruby::Server::Sdk::VERSION if connector == nil @connector = HarnessConnector.new(api_key, config = @config, = self) else unless connector.kind_of?(Connector) raise "The 'connector' parameter must be of '" + Connector.to_s + "' data type" end @connector = connector end @closing = false @failure = false @initialized = false @poller_ready = false @stream_ready = false @metrics_ready = false @my_mutex = Mutex.new @repository_callback = InnerClientRepositoryCallback.new(@config.logger) setup end |
Instance Method Details
#bool_variation(identifier, target, default_value) ⇒ Object
68 69 70 71 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 68 def bool_variation(identifier, target, default_value) @evaluator.bool_variation(identifier, target, default_value, @evaluator_callback) end |
#close ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 114 def close @config.logger.info "Closing the client: " + self.to_s @closing = true off @auth_service.close @repository.close @poll_processor.close @update_processor.close @metrics_processor.close @connector.close end |
#is_closing ⇒ Object
130 131 132 133 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 130 def is_closing @closing end |
#json_variation(identifier, target, default_value) ⇒ Object
83 84 85 86 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 83 def json_variation(identifier, target, default_value) @evaluator.json_variation(identifier, target, default_value, @evaluator_callback) end |
#number_variation(identifier, target, default_value) ⇒ Object
78 79 80 81 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 78 def number_variation(identifier, target, default_value) @evaluator.number_variation(identifier, target, default_value, @evaluator_callback) end |
#off ⇒ Object
135 136 137 138 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 135 def off # TODO: Implement - Reactivity support end |
#on_auth_failed ⇒ Object
109 110 111 112 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 109 def on_auth_failed SdkCodes::warn_auth_failed_srv_defaults @config.logger @initialized = true end |
#on_auth_success ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 88 def on_auth_success SdkCodes::info_sdk_auth_ok @config.logger if @closing return end @poll_processor.start if @config.stream_enabled @update_processor.start end if @config.analytics_enabled @metrics_processor.start end end |
#on_metrics_processor_ready ⇒ Object
192 193 194 195 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 192 def on_metrics_processor_ready on_processor_ready(@metrics_processor) end |
#on_poller_error(e) ⇒ Object
167 168 169 170 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 167 def on_poller_error(e) @config.logger.error "Poller error: " + e.to_s end |
#on_poller_iteration(poller) ⇒ Object
172 173 174 175 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 172 def on_poller_iteration(poller) @config.logger.debug "Poller iterated" + poller.to_s end |
#on_poller_ready(poller) ⇒ Object
162 163 164 165 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 162 def on_poller_ready(poller) on_processor_ready(poller) end |
#on_processor_ready(processor) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 197 def on_processor_ready(processor) if @closing return end if processor == @poll_processor @poller_ready = true @config.logger.debug "PollingProcessor ready" end if processor == @update_processor @stream_ready = true @config.logger.debug "Updater ready" end if processor == @metrics_processor @metrics_ready = true @config.logger.debug "Metrics ready" end if (@config.stream_enabled && !@stream_ready) || (@config.analytics_enabled && !@metrics_ready) || !@poller_ready return end SdkCodes.info_sdk_init_ok @config.logger @initialized = true end |
#on_unauthorized ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 140 def if @closing return end @poll_processor.stop if @config.stream_enabled @update_processor.stop end if @config.analytics_enabled @metrics_processor.stop end @auth_service.start_async end |
#on_update_processor_ready ⇒ Object
187 188 189 190 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 187 def on_update_processor_ready on_processor_ready(@update_processor) end |
#string_variation(identifier, target, default_value) ⇒ Object
73 74 75 76 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 73 def string_variation(identifier, target, default_value) @evaluator.string_variation(identifier, target, default_value, @evaluator_callback) end |
#update(message, manual) ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 177 def update(, manual) if @config.stream_enabled && manual @config.logger.warn "You run the update method manually with the stream enabled. Please turn off the stream in this case." end @update_processor.update() end |
#wait_for_initialization(timeout: nil) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/ff/ruby/server/sdk/api/inner_client.rb', line 234 def wait_for_initialization(timeout: nil) synchronize do SdkCodes::info_sdk_waiting_to_initialize(@config.logger, timeout) start_time = Time.now until @initialized # Check if a timeout is specified and has been exceeded if timeout && (Time.now - start_time) > (timeout / 1000.0) @config.logger.warn "The SDK has timed out waiting to initialize with supplied timeout #{timeout} ms" handle_initialization_failure end sleep(1) end if @failure raise "Initialization failed" end @config.logger.debug "Waiting for initialization has completed" end end |