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.
96 97 98 |
# File 'lib/fog/rackspace/queues.rb', line 96 def claims @claims end |
#messages ⇒ Object
Returns the value of attribute messages.
96 97 98 |
# File 'lib/fog/rackspace/queues.rb', line 96 def @messages end |
#metadata ⇒ Object
Returns the value of attribute metadata.
96 97 98 |
# File 'lib/fog/rackspace/queues.rb', line 96 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
96 97 98 |
# File 'lib/fog/rackspace/queues.rb', line 96 def name @name end |
Instance Method Details
#add_claim(ttl, grace) ⇒ Object
Create a new MockClaim.
157 158 159 160 161 |
# File 'lib/fog/rackspace/queues.rb', line 157 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.
145 146 147 148 149 150 151 |
# File 'lib/fog/rackspace/queues.rb', line 145 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.
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/fog/rackspace/queues.rb', line 173 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.
168 169 170 |
# File 'lib/fog/rackspace/queues.rb', line 168 def claim!(claim_id) claims[claim_id] or raise NotFound.new end |
#claimed ⇒ Integer
The number of messages currently held by a claim.
114 115 116 |
# File 'lib/fog/rackspace/queues.rb', line 114 def claimed @messages.count { |msg| msg.claimed? } end |
#free ⇒ Integer
The number of messages not held by any claim.
121 122 123 |
# File 'lib/fog/rackspace/queues.rb', line 121 def free @messages.count { |msg| ! msg.claimed? } end |
#newest ⇒ MockMessage|UndefinedObject
The most recently published message on this queue, or ‘nil`.
135 136 137 |
# File 'lib/fog/rackspace/queues.rb', line 135 def newest @messages.last end |
#oldest ⇒ MockMessage|UndefinedObject
The oldest published message on this queue, or ‘nil`.
128 129 130 |
# File 'lib/fog/rackspace/queues.rb', line 128 def oldest @messages.first end |
#total ⇒ Integer
The total number of messages currently on the queue.
107 108 109 |
# File 'lib/fog/rackspace/queues.rb', line 107 def total @messages.size end |