Class: Fluent::PluginHelper::Storage::PersistentWrapper
- Inherits:
-
Object
- Object
- Fluent::PluginHelper::Storage::PersistentWrapper
- Extended by:
- Forwardable
- Defined in:
- lib/fluent/plugin_helper/storage.rb
Instance Method Summary collapse
- #autosave ⇒ Object
- #delete(key) ⇒ Object
- #fetch(key, defval) ⇒ Object
- #get(key) ⇒ Object
- #implementation ⇒ Object
-
#initialize(storage) ⇒ PersistentWrapper
constructor
A new instance of PersistentWrapper.
- #load ⇒ Object
- #persistent ⇒ Object
- #persistent_always? ⇒ Boolean
- #put(key, value) ⇒ Object
- #save ⇒ Object
- #synchronized? ⇒ Boolean
- #update(key, &block) ⇒ Object
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
#autosave ⇒ Object
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 |
#implementation ⇒ Object
213 214 215 |
# File 'lib/fluent/plugin_helper/storage.rb', line 213 def implementation @storage end |
#load ⇒ Object
217 218 219 220 221 |
# File 'lib/fluent/plugin_helper/storage.rb', line 217 def load @monitor.synchronize do @storage.load end end |
#persistent ⇒ Object
201 202 203 |
# File 'lib/fluent/plugin_helper/storage.rb', line 201 def persistent true end |
#persistent_always? ⇒ 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 |
#save ⇒ Object
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
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 |