Class: FreeMessageQueue::SyncronizedQueue

Inherits:
LinkedQueue show all
Defined in:
lib/fmq/queues/syncronized.rb

Overview

The SyncronizedQueue implements a little wrapper around the LinkedQueue to make it thread safe

queue_manager = FreeMessageQueue::QueueManager.new(true) do
  setup_queue "/fmq_test/test1" do |q|
    q.max_messages = 1000000
    q.max_size = 10.kb
  end
end

Constant Summary

Constants inherited from BaseQueue

BaseQueue::INFINITE

Instance Attribute Summary

Attributes inherited from BaseQueue

#bytes, #manager, #max_messages, #max_size, #size

Instance Method Summary collapse

Methods inherited from LinkedQueue

#clear

Methods inherited from BaseQueue

#empty?

Constructor Details

#initialize(manager) ⇒ SyncronizedQueue

Returns a new instance of SyncronizedQueue.



34
35
36
37
# File 'lib/fmq/queues/syncronized.rb', line 34

def initialize(manager)
  super(manager)
  @semaphore = Mutex.new
end

Instance Method Details

#pollObject

Returns one item from the queue



40
41
42
43
44
# File 'lib/fmq/queues/syncronized.rb', line 40

def poll()
  @semaphore.synchronize {
    super
  }
end

#put(message) ⇒ Object

Puts one message to the queue



47
48
49
50
51
# File 'lib/fmq/queues/syncronized.rb', line 47

def put(message)
  @semaphore.synchronize {
    super(message)
  }
end