Class: ZMQMachine::Socket::XReq

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

Overview

class Req

Instance Attribute Summary

Attributes included from Base

#kind, #poll_options, #raw_socket

Instance Method Summary collapse

Methods included from EnvelopeHelp

#resume_read, #send_messages

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) ⇒ XReq

Returns a new instance of XReq.



81
82
83
84
85
86
# File 'lib/zm/sockets/req.rb', line 81

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

  super
end

Instance Method Details

#on_attach(handler) ⇒ Object

Attach a handler to the XREQ socket.

A XREQ 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 REP/XREP 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.

Raises:

  • (ArgumentError)


103
104
105
106
107
108
109
# File 'lib/zm/sockets/req.rb', line 103

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_writable method" unless handler.respond_to? :on_writable
  raise ArgumentError, "Handler must implement an #on_writable_error method" unless handler.respond_to? :on_writable_error
  super
end