Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup node class / extract node_callback into seperate module
No functional changes. Adds complete spec suite testing all node and node_callback edge cases
- Loading branch information
Showing
11 changed files
with
646 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# RJR Node Callback | ||
# | ||
# Copyright (C) 2012-2014 Mohammed Morsi <mo@morsi.org> | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
module RJR | ||
|
||
# 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 | ||
class NodeCallback | ||
attr_reader :node | ||
attr_reader :connection | ||
|
||
# NodeCallback initializer | ||
# @param [Hash] args the options to create the node callback with | ||
# @option args [node] :node node used to send messages | ||
# @option args [connection] :connection connection to be used in | ||
# channel selection | ||
def initialize(args = {}) | ||
@node = args[:node] | ||
@connection = args[:connection] | ||
end | ||
|
||
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 | ||
end # class NodeCallback | ||
end # module RJR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,7 @@ class Web < RJR::Node | |
|
||
RJR_NODE_TYPE = :web | ||
PERSISTENT_NODE = false | ||
INDIRECT_NODE = false | ||
|
||
public | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.