Class: Fluent::PluginHelper::Storage::PersistentWrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fluent/plugin_helper/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(storage) ⇒ PersistentWrapper

Returns a new instance of PersistentWrapper.



198
199
200
201
# File 'lib/fluent/plugin_helper/storage.rb', line 198

def initialize(storage)
  @storage = storage
  @monitor = Monitor.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



207
208
209
# File 'lib/fluent/plugin_helper/storage.rb', line 207

def method_missing(name, *args)
  @monitor.synchronize{ @storage.__send__(name, *args) }
end

Instance Method Details

#autosaveObject



219
220
221
# File 'lib/fluent/plugin_helper/storage.rb', line 219

def autosave
  false
end

#delete(key) ⇒ Object



266
267
268
269
270
271
272
273
# File 'lib/fluent/plugin_helper/storage.rb', line 266

def delete(key)
  @monitor.synchronize do
    @storage.load
    val = @storage.delete(key)
    @storage.save
    val
  end
end

#fetch(key, defval) ⇒ Object



250
251
252
253
254
255
# File 'lib/fluent/plugin_helper/storage.rb', line 250

def fetch(key, defval)
  @monitor.synchronize do
    @storage.load
    @storage.fetch(key, defval)
  end
end

#get(key) ⇒ Object



243
244
245
246
247
248
# File 'lib/fluent/plugin_helper/storage.rb', line 243

def get(key)
  @monitor.synchronize do
    @storage.load
    @storage.get(key)
  end
end

#implementationObject



227
228
229
# File 'lib/fluent/plugin_helper/storage.rb', line 227

def implementation
  @storage
end

#loadObject



231
232
233
234
235
# File 'lib/fluent/plugin_helper/storage.rb', line 231

def load
  @monitor.synchronize do
    @storage.load
  end
end

#persistentObject



215
216
217
# File 'lib/fluent/plugin_helper/storage.rb', line 215

def persistent
  true
end

#persistent_always?Boolean

Returns:

  • (Boolean)


211
212
213
# File 'lib/fluent/plugin_helper/storage.rb', line 211

def persistent_always?
  true
end

#put(key, value) ⇒ Object



257
258
259
260
261
262
263
264
# File 'lib/fluent/plugin_helper/storage.rb', line 257

def put(key, value)
  @monitor.synchronize do
    @storage.load
    @storage.put(key, value)
    @storage.save
    value
  end
end

#saveObject



237
238
239
240
241
# File 'lib/fluent/plugin_helper/storage.rb', line 237

def save
  @monitor.synchronize do
    @storage.save
  end
end

#synchronized?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/fluent/plugin_helper/storage.rb', line 223

def synchronized?
  true
end

#update(key, &block) ⇒ Object



275
276
277
278
279
280
281
282
283
# File 'lib/fluent/plugin_helper/storage.rb', line 275

def update(key, &block)
  @monitor.synchronize do
    @storage.load
    v = block.call(@storage.get(key))
    @storage.put(key, v)
    @storage.save
    v
  end
end