Class: AceMQ::AMQP::Patterns::KeyedLocks Private
- Inherits:
-
Object
- Object
- AceMQ::AMQP::Patterns::KeyedLocks
- Defined in:
- lib/acemq/amqp/patterns/ordered.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
One lock per key, and no lock for a key nothing is using.
Counted rather than left in place, because the natural key here is a per-order or per-customer identifier: keeping a mutex for every key ever seen means keeping one for every order this process ever handled.
Instance Method Summary collapse
- #holding(key) ⇒ Object private
-
#initialize ⇒ KeyedLocks
constructor
private
A new instance of KeyedLocks.
-
#size ⇒ Object
private
How many keys are currently locked, for a test that wants to know the map is not growing.
Constructor Details
#initialize ⇒ KeyedLocks
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of KeyedLocks.
115 116 117 118 119 |
# File 'lib/acemq/amqp/patterns/ordered.rb', line 115 def initialize @lock = Mutex.new @held = {} @users = Hash.new(0) end |
Instance Method Details
#holding(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
121 122 123 124 125 126 127 128 |
# File 'lib/acemq/amqp/patterns/ordered.rb', line 121 def holding(key, &) mutex = claim(key) begin mutex.synchronize(&) ensure release(key) end end |
#size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
How many keys are currently locked, for a test that wants to know the map is not growing.
132 |
# File 'lib/acemq/amqp/patterns/ordered.rb', line 132 def size = @lock.synchronize { @held.size } |