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.



188
189
190
191
# File 'lib/fluent/plugin_helper/storage.rb', line 188

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

Instance Method Details

#autosaveObject



205
206
207
# File 'lib/fluent/plugin_helper/storage.rb', line 205

def autosave
  false
end

#delete(key) ⇒ Object



252
253
254
255
256
257
258
259
# File 'lib/fluent/plugin_helper/storage.rb', line 252

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

#fetch(key, defval) ⇒ Object



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

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

#get(key) ⇒ Object



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

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

#implementationObject



213
214
215
# File 'lib/fluent/plugin_helper/storage.rb', line 213

def implementation
  @storage
end

#loadObject



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

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

#persistentObject



201
202
203
# File 'lib/fluent/plugin_helper/storage.rb', line 201

def persistent
  true
end

#persistent_always?Boolean

Returns:

  • (Boolean)


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

def persistent_always?
  true
end

#put(key, value) ⇒ Object



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

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

#saveObject



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

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

#synchronized?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/fluent/plugin_helper/storage.rb', line 209

def synchronized?
  true
end

#update(key, &block) ⇒ Object



261
262
263
264
265
266
267
268
269
# File 'lib/fluent/plugin_helper/storage.rb', line 261

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