Class: LaunchDarkly::Impl::Integrations::FileDataSourceImpl
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Integrations::FileDataSourceImpl
- Defined in:
- lib/ldclient-rb/impl/integrations/file_data_source.rb
Overview
Defined Under Namespace
Classes: FileDataSourcePoller
Constant Summary collapse
- @@have_listen =
To avoid pulling in 'listen' and its transitive dependencies for people who aren't using the file data source or who don't need auto-updating, we only enable auto-update if the 'listen' gem has been provided by the host app.
false
Instance Method Summary collapse
-
#initialize(data_store, data_source_update_sink, logger, options = {}) ⇒ FileDataSourceImpl
constructor
A new instance of FileDataSourceImpl.
- #initialized? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(data_store, data_source_update_sink, logger, options = {}) ⇒ FileDataSourceImpl
Returns a new instance of FileDataSourceImpl.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 30 def initialize(data_store, data_source_update_sink, logger, ={}) @data_store = data_source_update_sink || data_store @data_source_update_sink = data_source_update_sink @logger = logger @paths = [:paths] || [] if @paths.is_a? String @paths = [ @paths ] end @auto_update = [:auto_update] if @auto_update && @@have_listen && ![:force_polling] # force_polling is used only for tests # We have seen unreliable behavior in the 'listen' gem in JRuby 9.1 (https://github.com/guard/listen/issues/449). # Therefore, on that platform we'll fall back to file polling instead. if defined?(JRUBY_VERSION) && JRUBY_VERSION.start_with?("9.1.") @use_listen = false else @use_listen = true end end @poll_interval = [:poll_interval] || 1 @initialized = Concurrent::AtomicBoolean.new(false) @ready = Concurrent::Event.new end |
Instance Method Details
#initialized? ⇒ Boolean
53 54 55 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 53 def initialized? @initialized.value end |
#start ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 57 def start ready = Concurrent::Event.new # We will return immediately regardless of whether the file load succeeded or failed - # the difference can be detected by checking "initialized?" ready.set load_all if @auto_update # If we're going to watch files, then the start event will be set the first time we get # a successful load. @listener = start_listener end ready end |
#stop ⇒ Object
75 76 77 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 75 def stop @listener.stop unless @listener.nil? end |