Class: Fog::Rackspace::Queues::Mock::MockQueue
- Inherits:
-
Object
- Object
- Fog::Rackspace::Queues::Mock::MockQueue
- Defined in:
- lib/fog/rackspace/queues.rb
Overview
An in-memory Queue implementation.
Instance Attribute Summary collapse
-
#claims ⇒ Object
Returns the value of attribute claims.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#add_claim(ttl, grace) ⇒ Object
Create a new MockClaim.
-
#add_message(client_id, data, ttl) ⇒ MockMessage
Append a new message to the queue.
-
#ageoff ⇒ Object
Remove any messages or claims whose ttls have expired.
-
#claim!(claim_id) ⇒ MockClaim
Access an existing MockClaim by id.
-
#claimed ⇒ Integer
The number of messages currently held by a claim.
-
#free ⇒ Integer
The number of messages not held by any claim.
-
#initialize(name) ⇒ MockQueue
constructor
A new instance of MockQueue.
-
#newest ⇒ MockMessage|UndefinedObject
The most recently published message on this queue, or ‘nil`.
-
#oldest ⇒ MockMessage|UndefinedObject
The oldest published message on this queue, or ‘nil`.
-
#total ⇒ Integer
The total number of messages currently on the queue.
Constructor Details
Instance Attribute Details
#claims ⇒ Object
Returns the value of attribute claims.
103 104 105 |
# File 'lib/fog/rackspace/queues.rb', line 103 def claims @claims end |
#messages ⇒ Object
Returns the value of attribute messages.
103 104 105 |
# File 'lib/fog/rackspace/queues.rb', line 103 def @messages end |
#metadata ⇒ Object
Returns the value of attribute metadata.
103 104 105 |
# File 'lib/fog/rackspace/queues.rb', line 103 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
103 104 105 |
# File 'lib/fog/rackspace/queues.rb', line 103 def name @name end |
Instance Method Details
#add_claim(ttl, grace) ⇒ Object
Create a new MockClaim.
164 165 166 167 168 |
# File 'lib/fog/rackspace/queues.rb', line 164 def add_claim(ttl, grace) claim = MockClaim.new(self, ttl, grace) claims[claim.id] = claim claim end |
#add_message(client_id, data, ttl) ⇒ MockMessage
Append a new message to the queue.
152 153 154 155 156 157 158 |
# File 'lib/fog/rackspace/queues.rb', line 152 def (client_id, data, ttl) id = @id_counter.to_s(16) @id_counter += 1 = MockMessage.new(id, self, client_id, data, ttl) @messages << end |
#ageoff ⇒ Object
Remove any messages or claims whose ttls have expired.
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/fog/rackspace/queues.rb', line 180 def ageoff .reject! { |m| m.expired? } claims.keys.dup.each do |id| claim = claims[id] if claim.expired? || claim..empty? claim..each { |m| m.claim = nil } claims.delete(id) end end end |
#claim!(claim_id) ⇒ MockClaim
Access an existing MockClaim by id.
175 176 177 |
# File 'lib/fog/rackspace/queues.rb', line 175 def claim!(claim_id) claims[claim_id] or raise NotFound.new end |
#claimed ⇒ Integer
The number of messages currently held by a claim.
121 122 123 |
# File 'lib/fog/rackspace/queues.rb', line 121 def claimed @messages.count { |msg| msg.claimed? } end |
#free ⇒ Integer
The number of messages not held by any claim.
128 129 130 |
# File 'lib/fog/rackspace/queues.rb', line 128 def free @messages.count { |msg| ! msg.claimed? } end |
#newest ⇒ MockMessage|UndefinedObject
The most recently published message on this queue, or ‘nil`.
142 143 144 |
# File 'lib/fog/rackspace/queues.rb', line 142 def newest @messages.last end |
#oldest ⇒ MockMessage|UndefinedObject
The oldest published message on this queue, or ‘nil`.
135 136 137 |
# File 'lib/fog/rackspace/queues.rb', line 135 def oldest @messages.first end |
#total ⇒ Integer
The total number of messages currently on the queue.
114 115 116 |
# File 'lib/fog/rackspace/queues.rb', line 114 def total @messages.size end |