Class: OsCtld::Devices::ChangeSet
- Inherits:
-
Object
- Object
- OsCtld::Devices::ChangeSet
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/osctld/devices/change_set.rb
Overview
Track changed devices manager to reconfigure them just once
Instance Method Summary collapse
-
#add(pool, manager, sort_key) ⇒ Object
Add manager to the changeset.
-
#close(pool) ⇒ Object
Close the changeset, applying all changes.
-
#initialize ⇒ ChangeSet
constructor
A new instance of ChangeSet.
-
#open(pool) ⇒ Object
Open new changeset on pool.
- #sync ⇒ Object protected
Constructor Details
#initialize ⇒ ChangeSet
Returns a new instance of ChangeSet.
14 15 16 17 |
# File 'lib/osctld/devices/change_set.rb', line 14 def initialize @mutex = Mutex.new @pools = {} end |
Instance Method Details
#add(pool, manager, sort_key) ⇒ Object
Add manager to the changeset
31 32 33 34 35 |
# File 'lib/osctld/devices/change_set.rb', line 31 def add(pool, manager, sort_key) sync do @pools[pool.name][sort_key] = manager end end |
#close(pool) ⇒ Object
Close the changeset, applying all changes
39 40 41 42 43 44 45 46 47 |
# File 'lib/osctld/devices/change_set.rb', line 39 def close(pool) changes = sync { @pools.delete(pool.name) } changes.sort do |a, b| a[0] <=> b[0] end.each do |_, manager| manager.apply end end |
#open(pool) ⇒ Object
Open new changeset on pool
21 22 23 24 25 |
# File 'lib/osctld/devices/change_set.rb', line 21 def open(pool) sync do @pools[pool.name] = {} end end |
#sync ⇒ Object (protected)
51 52 53 |
# File 'lib/osctld/devices/change_set.rb', line 51 def sync(&) @mutex.synchronize(&) end |