Class: RJR::NodeCallback

Inherits:
Object show all
Defined in:
lib/rjr/node.rb

Overview

Node callback interface, used to invoke json-rpc methods against a remote node via node connection previously established

After a node sends a json-rpc request to another, the either node may send additional requests to each other via the connection already established until it is closed on either end

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ NodeCallback

NodeCallback initializer

Parameters:

  • args (Hash) (defaults to: {})

    the options to create the node callback with

Options Hash (args):

  • :node (node)

    node used to send messages

  • :connection (connection)

    connection to be used in channel selection



261
262
263
264
# File 'lib/rjr/node.rb', line 261

def initialize(args = {})
  @node        = args[:node]
  @connection  = args[:connection]
end

Instance Method Details

#notify(callback_method, *data) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
# File 'lib/rjr/node.rb', line 266

def notify(callback_method, *data)
  # XXX return if node type does not support
  # pesistent conntections (throw err instead?)
  return if @node.class::RJR_NODE_TYPE == :web

  msg = NotificationMessage.new :method => callback_method,
                                :args => data, :headers => @node.message_headers

  # TODO surround w/ begin/rescue block incase of socket errors / raise RJR::ConnectionError
  @node.send_msg msg.to_s, @connection
end