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



244
245
246
247
# File 'lib/rjr/node.rb', line 244

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

Instance Method Details

#notify(callback_method, *data) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/rjr/node.rb', line 249

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