Class: ZMQMachine::Socket::XRep
- Inherits:
-
Object
- Object
- ZMQMachine::Socket::XRep
- Includes:
- Base
- Defined in:
- lib/zm/sockets/xrep.rb
Instance Attribute Summary
Attributes included from Base
#kind, #poll_options, #raw_socket
Instance Method Summary collapse
-
#initialize(context, handler) ⇒ XRep
constructor
A new instance of XRep.
-
#on_attach(handler) ⇒ Object
Attach a handler to the XREP socket.
Methods included from Base
#attach, #bind, #connect, #identity, #identity=, #inspect, #resume_read, #resume_write, #send_message, #send_message_string, #send_messages
Constructor Details
#initialize(context, handler) ⇒ XRep
Returns a new instance of XRep.
44 45 46 47 48 49 50 |
# File 'lib/zm/sockets/xrep.rb', line 44 def initialize context, handler @poll_options = ZMQ::POLLIN | ZMQ::POLLOUT @kind = :xreply super @state = :ready end |
Instance Method Details
#on_attach(handler) ⇒ Object
Attach a handler to the XREP socket.
A XREP socket has no restrictions on the number of sends and recieves. Each send will silently prepend a message part to your outgoing data which the REQ/XREQ socket on the other end will use for matching up the transaction.
This socket expects its handler
to implement at least the #on_readable method. This method will be called whenever a reply arrives. The #on_writable method will be called continually until the socket HWM is breached.
For error handling purposes, the handler must also implement #on_readable_error.
67 68 69 70 71 72 73 |
# File 'lib/zm/sockets/xrep.rb', line 67 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 raise ArgumentError, "Handler must implement an #on_readable method" unless handler.respond_to? :on_writable raise ArgumentError, "Handler must implement an #on_readable_error method" unless handler.respond_to? :on_writable_error super end |