Class: ZMQMachine::Socket::Rep

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/zm/sockets/rep.rb

Instance Attribute Summary

Attributes included from Base

#kind, #poll_options, #raw_socket

Instance Method Summary collapse

Methods included from Base

#attach, #bind, #connect, create, #identity, #identity=, #inspect, #resume_read, #resume_write, #send_message, #send_message_string, #send_messages

Constructor Details

#initialize(context, handler) ⇒ Rep

Returns a new instance of Rep.



44
45
46
47
48
49
# File 'lib/zm/sockets/rep.rb', line 44

def initialize context, handler
  @poll_options = ZMQ::POLLIN
  @kind = :reply

  super
end

Instance Method Details

#on_attach(handler) ⇒ Object

Attach a handler to the REP socket.

A REP socket must alternate between recv.send (i.e. it cannot receive twice in a row without an intervening send). This socket expects its handler to implement at least the #on_readable method. This method will be called whenever a request arrives.

For error handling purposes, the handler must also implement #on_readable_error.

Raises:

  • (ArgumentError)


62
63
64
65
66
# File 'lib/zm/sockets/rep.rb', line 62

def on_attach handler
  raise ArgumentError, "Handler must implement an #on_readable method" unless handler.respond_to? :on_readable
  raise ArgumentError, "Handler must implement an #on_readable_error method" unless handler.respond_to? :on_readable_error
  super
end