Class: Majordomo::Broker::Service
- Inherits:
-
Object
- Object
- Majordomo::Broker::Service
- Defined in:
- lib/majordomo/broker/service.rb
Instance Attribute Summary collapse
-
#blacklist ⇒ Object
Returns the value of attribute blacklist.
-
#broker ⇒ Object
Returns the value of attribute broker.
-
#name ⇒ Object
Returns the value of attribute name.
-
#requests ⇒ Object
Returns the value of attribute requests.
-
#waiting ⇒ Object
Returns the value of attribute waiting.
-
#workers ⇒ Object
Returns the value of attribute workers.
Class Method Summary collapse
Instance Method Summary collapse
- #command_enabled?(command) ⇒ Boolean
- #disable_command(command) ⇒ Object
- #dispatch ⇒ Object
- #enable_command(command) ⇒ Object
-
#initialize(broker, name) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(broker, name) ⇒ Service
Returns a new instance of Service.
8 9 10 11 12 13 14 15 |
# File 'lib/majordomo/broker/service.rb', line 8 def initialize(broker, name) @broker = broker @name = name @requests = [] @waiting = [] @workers = 0 @blacklist = ::Set.new end |
Instance Attribute Details
#blacklist ⇒ Object
Returns the value of attribute blacklist.
6 7 8 |
# File 'lib/majordomo/broker/service.rb', line 6 def blacklist @blacklist end |
#broker ⇒ Object
Returns the value of attribute broker.
6 7 8 |
# File 'lib/majordomo/broker/service.rb', line 6 def broker @broker end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/majordomo/broker/service.rb', line 6 def name @name end |
#requests ⇒ Object
Returns the value of attribute requests.
6 7 8 |
# File 'lib/majordomo/broker/service.rb', line 6 def requests @requests end |
#waiting ⇒ Object
Returns the value of attribute waiting.
6 7 8 |
# File 'lib/majordomo/broker/service.rb', line 6 def waiting @waiting end |
#workers ⇒ Object
Returns the value of attribute workers.
6 7 8 |
# File 'lib/majordomo/broker/service.rb', line 6 def workers @workers end |
Class Method Details
.require(broker, name) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/majordomo/broker/service.rb', line 17 def self.require(broker, name) service = broker.services[name] if service == nil service = self.new(broker, name) broker.services[name] = service end service end |
Instance Method Details
#command_enabled?(command) ⇒ Boolean
47 48 49 |
# File 'lib/majordomo/broker/service.rb', line 47 def command_enabled?(command) @blacklist.include?(command) end |
#disable_command(command) ⇒ Object
43 44 45 |
# File 'lib/majordomo/broker/service.rb', line 43 def disable_command(command) @blacklist.add(command) end |
#dispatch ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/majordomo/broker/service.rb', line 27 def dispatch broker.purge return if waiting.empty? while requests.any? worker = waiting.shift = requests.shift worker.(REQUEST, ) waiting << worker end end |
#enable_command(command) ⇒ Object
39 40 41 |
# File 'lib/majordomo/broker/service.rb', line 39 def enable_command(command) @blacklist.delete(command) end |