Class: LaunchDarkly::FileDataSourceImpl

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

Defined Under Namespace

Classes: FileDataSourcePoller

Instance Method Summary collapse

Constructor Details

#initialize(feature_store, logger, options = {}) ⇒ FileDataSourceImpl

Returns a new instance of FileDataSourceImpl.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/ldclient-rb/file_data_source.rb', line 120

def initialize(feature_store, logger, options={})
  @feature_store = feature_store
  @logger = logger
  @paths = options[:paths] || []
  if @paths.is_a? String
    @paths = [ @paths ]
  end
  @auto_update = options[:auto_update]
  if @auto_update && LaunchDarkly.have_listen? && !options[: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 = options[:poll_interval] || 1
  @initialized = Concurrent::AtomicBoolean.new(false)
  @ready = Concurrent::Event.new
end

Instance Method Details

#initialized?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/ldclient-rb/file_data_source.rb', line 142

def initialized?
  @initialized.value
end

#startObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/ldclient-rb/file_data_source.rb', line 146

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

#stopObject



164
165
166
# File 'lib/ldclient-rb/file_data_source.rb', line 164

def stop
  @listener.stop if !@listener.nil?
end