Class: RJR::Nodes::Easy
Overview
Easy node definition.
Clients should specify the transports that they would like to use and their relevant config upon instantating this call. After which invocations and notifications will be routed via the correct transport depending on the format of the destination.
All nodes managed locally will share the same dispatcher so that json-rpc methods only need to be registered once, with the multi-node itself.
Instance Attribute Summary
Attributes inherited from RJR::Node
#dispatcher, #message_headers, #node_id
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Easy
constructor
Easy Node initializer.
-
#invoke(dst, rpc_method, *args) ⇒ Object
Instructs node to send rpc request, and wait for and return response.
-
#listen ⇒ Object
Instruct Nodes to start listening for and dispatching rpc requests.
-
#notify(dst, rpc_method, *args) ⇒ Object
Instructs node to send rpc notification (immadiately returns / no response is generated).
-
#send_msg(data, connection) ⇒ Object
Send data using specified connection.
-
#stop_on(signal) ⇒ Object
Stop node on the specified signal.
Methods inherited from RJR::Node
em, #halt, #join, #node_type, #on, tp
Constructor Details
#initialize(args = {}) ⇒ Easy
Easy Node initializer
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rjr/nodes/easy.rb', line 79 def initialize(args = {}) super(args) nodes = [] args.keys.each { |n| node = case n when :amqp then RJR::Nodes::AMQP.new args[:amqp].merge(args) when :ws then RJR::Nodes::WS.new args[:ws].merge(args) when :tcp then RJR::Nodes::TCP.new args[:tcp].merge(args) when :web then RJR::Nodes::Web.new args[:web].merge(args) end if node nodes << node end } @multi_node = RJR::Nodes::Multi.new :nodes => nodes @dispatcher = @multi_node.dispatcher end |
Instance Method Details
#invoke(dst, rpc_method, *args) ⇒ Object
Instructs node to send rpc request, and wait for and return response.
Implementation of RJR::Node#invoke
128 129 130 131 132 |
# File 'lib/rjr/nodes/easy.rb', line 128 def invoke(dst, rpc_method, *args) n = get_node(dst) # TODO raise exception if n.nil? n.invoke dst, rpc_method, *args end |
#listen ⇒ Object
Instruct Nodes to start listening for and dispatching rpc requests
Implementation of RJR::Node#listen
115 116 117 |
# File 'lib/rjr/nodes/easy.rb', line 115 def listen @multi_node.listen end |
#notify(dst, rpc_method, *args) ⇒ Object
Instructs node to send rpc notification (immadiately returns / no response is generated)
Implementation of RJR::Node#notify
141 142 143 144 |
# File 'lib/rjr/nodes/easy.rb', line 141 def notify(dst, rpc_method, *args) n = get_node(dst) n.notify dst, rpc_method, *args end |
#send_msg(data, connection) ⇒ Object
Send data using specified connection
Implementation of RJR::Node#send_msg
108 109 110 |
# File 'lib/rjr/nodes/easy.rb', line 108 def send_msg(data, connection) # TODO end |
#stop_on(signal) ⇒ Object
Stop node on the specified signal
150 151 152 153 154 155 |
# File 'lib/rjr/nodes/easy.rb', line 150 def stop_on(signal) Signal.trap(signal) { @multi_node.stop } self end |