Class: EventMachine::Protocols::Zmq2::Router

Inherits:
PreRouter
  • Object
show all
Includes:
QueuePerPeer
Defined in:
lib/em/protocols/zmq2/router.rb

Overview

ZMQ socket which acts like Router. It counts first message string as peer identity when sending message and prepends socket identity to message on receiving.

Direct Known Subclasses

Rep

Instance Method Summary collapse

Methods included from QueuePerPeer

#initialize, #peer_free, #register_peer, #unregister_peer

Methods inherited from PreRouter

#receive_message, #receive_message_and_peer

Instance Method Details

#send_message(message) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/em/protocols/zmq2/router.rb', line 42

def send_message(message)
  peer_identity = message.first
  unless (queue = @queues[peer_identity])
    if generated_identity?(peer_identity)
      return false
    else
      queue = @queues[peer_identity] = []
    end
  end
  peer = choose_peer(peer_identity)
  if peer && (queue.empty? || flush_queue(queue, peer)) &&
     !peer.error? && peer.not_too_busy?
    peer.send_strings(message[1..-1])
    true
  else
    push_to_queue(queue, message)
  end
end