Class: Majordomo::Broker::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/majordomo/broker/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#blacklistObject

Returns the value of attribute blacklist.



6
7
8
# File 'lib/majordomo/broker/service.rb', line 6

def blacklist
  @blacklist
end

#brokerObject

Returns the value of attribute broker.



6
7
8
# File 'lib/majordomo/broker/service.rb', line 6

def broker
  @broker
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/majordomo/broker/service.rb', line 6

def name
  @name
end

#requestsObject

Returns the value of attribute requests.



6
7
8
# File 'lib/majordomo/broker/service.rb', line 6

def requests
  @requests
end

#waitingObject

Returns the value of attribute waiting.



6
7
8
# File 'lib/majordomo/broker/service.rb', line 6

def waiting
  @waiting
end

#workersObject

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

Returns:

  • (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

#dispatchObject



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
    message = requests.shift
    worker.send_message(REQUEST, message)
    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