Class: RJR::NodeCallback

Inherits:
Object show all
Defined in:
lib/rjr/node_callback.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 Attribute Summary collapse

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



25
26
27
28
# File 'lib/rjr/node_callback.rb', line 25

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

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



18
19
20
# File 'lib/rjr/node_callback.rb', line 18

def connection
  @connection
end

#nodeObject (readonly)

Returns the value of attribute node.



17
18
19
# File 'lib/rjr/node_callback.rb', line 17

def node
  @node
end

Instance Method Details

#notify(callback_method, *data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rjr/node_callback.rb', line 30

def notify(callback_method, *data)
  # TODO throw error here ?
  return unless node.persistent?

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

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