Class: UnifiedQueues::Multi
- Inherits:
-
Object
- Object
- UnifiedQueues::Multi
- Defined in:
- lib/unified-queues/multi.rb,
lib/unified-queues/multi/driver.rb,
lib/unified-queues/multi/driver/em-jack.rb,
lib/unified-queues/multi/driver/unified-queues.rb
Overview
Universal multi queue interface.
Defined Under Namespace
Classes: Driver
Constant Summary collapse
- DRIVERS =
Contains assignment of classnames to drivers.
Hash[ :"UnifiedQueues::Single" => "unified-queues.rb", :"EMJack::Connection" => "em-jack.rb" ]
Instance Attribute Summary collapse
-
#driver ⇒ UnifiedQueues::Multi::Driver
Contains driver for specific class instance.
Instance Method Summary collapse
-
#assign_driver(cls, args, block) ⇒ UnifiedQueues::Multi::Driver
Assigns driver to interface according to given class name.
-
#close(&block) ⇒ Object
(also: #close!)
Closes the session.
-
#initialize(cls, *args, &block) ⇒ Multi
constructor
Constructor.
-
#list(&block) ⇒ Array
Lists names of all available queues.
-
#list_subscribed(&block) ⇒ Array
Lists all subscribed queues.
-
#list_used(&block) ⇒ Array
Lists all used queues.
-
#pop(blocking = false, &block) ⇒ Object|nil
Pops value from the queue.
-
#push(value, key = value, &block) ⇒ Object
Pushes value to the currently used queue.
-
#subscribe(name, &block) ⇒ Object
Subscribes to the queue.
-
#subscribed(&block) ⇒ Queue
Currently subscribed queue.
-
#unsubscribe(name, &block) ⇒ Object
Unsubscribes from the queue.
-
#use(name, &block) ⇒ Object
Sets queue with given name as used.
-
#used(&block) ⇒ Queue
Currently used queue.
Constructor Details
#initialize(cls, *args, &block) ⇒ Multi
Constructor.
45 46 47 48 49 50 51 |
# File 'lib/unified-queues/multi.rb', line 45 def initialize(cls, *args, &block) if cls.kind_of? UnifiedQueues::Multi::Driver @driver = cls else self.assign_driver(cls, args, block) end end |
Instance Attribute Details
#driver ⇒ UnifiedQueues::Multi::Driver
Contains driver for specific class instance.
34 35 36 |
# File 'lib/unified-queues/multi.rb', line 34 def driver @driver end |
Instance Method Details
#assign_driver(cls, args, block) ⇒ UnifiedQueues::Multi::Driver
Assigns driver to interface according to given class name.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/unified-queues/multi.rb', line 62 def assign_driver(cls, args, block) _cls = cls if not _cls.kind_of? Class _cls = cls.class end driver = nil name = nil self.class::DRIVERS.each_pair do |_name, _driver| begin _module = Module::get_module(_name.to_s) rescue NameError next end if _cls <= _module driver = _driver name = _name break end end ### require "unified-queues/multi/driver/" << driver path = name.to_s.split("::") classname = path.shift << 'Driver::' << path.join('::') _module = Module::get_module("UnifiedQueues::Multi::Driver::" << classname) args = [cls] + args @driver = _module::new(*args, &block) return @driver end |
#close(&block) ⇒ Object Also known as: close!
Closes the session.
202 203 204 |
# File 'lib/unified-queues/multi.rb', line 202 def close(&block) @driver.close(&block) end |
#list(&block) ⇒ Array
Lists names of all available queues.
176 177 178 |
# File 'lib/unified-queues/multi.rb', line 176 def list(&block) @driver.list(&block) end |
#list_subscribed(&block) ⇒ Array
Lists all subscribed queues.
194 195 196 |
# File 'lib/unified-queues/multi.rb', line 194 def list_subscribed(&block) @driver.list_subscribed(&block) end |
#list_used(&block) ⇒ Array
Lists all used queues.
185 186 187 |
# File 'lib/unified-queues/multi.rb', line 185 def list_used(&block) @driver.list_used(&block) end |
#pop(blocking = false, &block) ⇒ Object|nil
Pops value from the queue. In contrast to default Queue library, blocks or returns nil
if empty.
117 118 119 |
# File 'lib/unified-queues/multi.rb', line 117 def pop(blocking = false, &block) @driver.pop(blocking, &block) end |
#push(value, key = value, &block) ⇒ Object
Pushes value to the currently used queue.
105 106 107 |
# File 'lib/unified-queues/multi.rb', line 105 def push(value, key = value, &block) @driver.push(value, key, &block) end |
#subscribe(name, &block) ⇒ Object
Subscribes to the queue. So marks it as target for #pop. Note, than only single queue usally can be subscribed at one time.
140 141 142 |
# File 'lib/unified-queues/multi.rb', line 140 def subscribe(name, &block) @driver.subscribe(name, &block) end |
#subscribed(&block) ⇒ Queue
Currently subscribed queue.
167 168 169 |
# File 'lib/unified-queues/multi.rb', line 167 def subscribed(&block) @driver.subscribed(&block) end |
#unsubscribe(name, &block) ⇒ Object
Unsubscribes from the queue.
149 150 151 |
# File 'lib/unified-queues/multi.rb', line 149 def unsubscribe(name, &block) @driver.unsubscribe(name, &block) end |
#use(name, &block) ⇒ Object
Sets queue with given name as used. So marks it as target for #push.
128 129 130 |
# File 'lib/unified-queues/multi.rb', line 128 def use(name, &block) @driver.use(name, &block) end |
#used(&block) ⇒ Queue
Currently used queue.
158 159 160 |
# File 'lib/unified-queues/multi.rb', line 158 def used(&block) @driver.used(&block) end |