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
#connection_event_handlers, #dispatcher, #message_headers, #node_id
Class Method Summary collapse
-
.node_type_for(dst) ⇒ Object
Publically available helper, retrieve the rjr node type based on dst format.
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
#clear_event_handlers, em, #em, #halt, #indirect?, indirect?, #join, #node_type, #on, persistent?, #persistent?, tp, #tp
Constructor Details
#initialize(args = {}) ⇒ Easy
Easy Node initializer
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rjr/nodes/easy.rb', line 91 def initialize(args = {}) super(args) nodes = 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 |
Class Method Details
.node_type_for(dst) ⇒ Object
Publically available helper, retrieve the rjr node type based on dst format
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rjr/nodes/easy.rb', line 42 def self.node_type_for(dst) type = nil if dst.is_a?(String) if /tcp:\/\/.*/ =~ dst || /jsonrpc:\/\/.*/ =~ dst || /json-rpc:\/\/.*/ =~ dst type = RJR::Nodes::TCP elsif /ws:\/\/.*/ =~ dst type = RJR::Nodes::WS elsif /http:\/\/.*/ =~ dst type = RJR::Nodes::Web elsif /.*-queue$/ =~ dst type = RJR::Nodes::AMQP # else # TODO # type = RJR::Nodes::Local end end type 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
140 141 142 143 144 |
# File 'lib/rjr/nodes/easy.rb', line 140 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
127 128 129 |
# File 'lib/rjr/nodes/easy.rb', line 127 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
153 154 155 156 |
# File 'lib/rjr/nodes/easy.rb', line 153 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
120 121 122 |
# File 'lib/rjr/nodes/easy.rb', line 120 def send_msg(data, connection) # TODO end |
#stop_on(signal) ⇒ Object
Stop node on the specified signal
162 163 164 165 166 167 |
# File 'lib/rjr/nodes/easy.rb', line 162 def stop_on(signal) Signal.trap(signal) { @multi_node.stop } self end |