Class: FreeMessageQueue::LinkedQueue
- Defined in:
- lib/fmq/queues/linked.rb
Overview
DO NOT USE THIS QUEUE DIRECTLY IN THE QUEUE MANAGER it is not thread safe. This Queue implements a FIFO based store in system memory.
Direct Known Subclasses
Constant Summary
Constants inherited from BaseQueue
Instance Attribute Summary
Attributes inherited from BaseQueue
#bytes, #manager, #max_messages, #max_size, #size
Instance Method Summary collapse
-
#clear ⇒ Object
Remove all items from the queue.
-
#initialize(manager) ⇒ LinkedQueue
constructor
A new instance of LinkedQueue.
-
#poll ⇒ Object
Return an message from the queue or nil if the queue is empty.
-
#put(message) ⇒ Object
Put an item to the queue.
Methods inherited from BaseQueue
Constructor Details
#initialize(manager) ⇒ LinkedQueue
Returns a new instance of LinkedQueue.
26 27 28 29 |
# File 'lib/fmq/queues/linked.rb', line 26 def initialize(manager) super(manager) @last_message = @first_message = nil end |
Instance Method Details
#clear ⇒ Object
Remove all items from the queue
32 33 34 |
# File 'lib/fmq/queues/linked.rb', line 32 def clear while self.poll; end end |
#poll ⇒ Object
Return an message from the queue or nil if the queue is empty
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fmq/queues/linked.rb', line 55 def poll() unless empty? # remove allways the first item = @first_message # took it off @first_message = .next @last_message = nil if @first_message.nil? .next = nil # unlink the message () # update stats else return nil end end |
#put(message) ⇒ Object
Put an item to the queue
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fmq/queues/linked.rb', line 37 def put() return false if .nil? () # update stats and check constraints # insert at end of list if @first_message == nil # first and last item are same if there is no item to the queue @first_message = @last_message = else # append the message to the end of the queue @last_message = @last_message.next = end return true end |