Class: Majordomo::Broker::Worker
- Inherits:
-
Object
- Object
- Majordomo::Broker::Worker
- Defined in:
- lib/majordomo/broker/worker.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#broker ⇒ Object
Returns the value of attribute broker.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#service ⇒ Object
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
- #delete(disconnect) ⇒ Object
-
#initialize(broker, identity, address) ⇒ Worker
constructor
A new instance of Worker.
- #send_message(command, message = []) ⇒ Object
Constructor Details
#initialize(broker, identity, address) ⇒ Worker
Returns a new instance of Worker.
6 7 8 9 10 |
# File 'lib/majordomo/broker/worker.rb', line 6 def initialize(broker, identity, address) @broker = broker @identity = identity @address = address end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
4 5 6 |
# File 'lib/majordomo/broker/worker.rb', line 4 def address @address end |
#broker ⇒ Object
Returns the value of attribute broker.
4 5 6 |
# File 'lib/majordomo/broker/worker.rb', line 4 def broker @broker end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
4 5 6 |
# File 'lib/majordomo/broker/worker.rb', line 4 def expires_at @expires_at end |
#identity ⇒ Object
Returns the value of attribute identity.
4 5 6 |
# File 'lib/majordomo/broker/worker.rb', line 4 def identity @identity end |
#service ⇒ Object
Returns the value of attribute service.
4 5 6 |
# File 'lib/majordomo/broker/worker.rb', line 4 def service @service end |
Class Method Details
.require(broker, address) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/majordomo/broker/worker.rb', line 12 def self.require(broker, address) identity = address.unpack('H*').first worker = broker.workers[identity] if worker == nil worker = self.new(broker, identity, address) broker.workers[identity] = worker end worker end |
Instance Method Details
#delete(disconnect) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/majordomo/broker/worker.rb', line 24 def delete(disconnect) if disconnect (DISCONNECT) end if service service.waiting.delete(self) service.workers -= 1 end broker.waiting.delete(self) broker.workers.delete(identity) end |
#send_message(command, message = []) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/majordomo/broker/worker.rb', line 37 def (command, = []) .unshift(command) .unshift(WORKER) .unshift(nil) .unshift(address) broker.socket.send_strings() end |