Class: Rcom::Response
- Inherits:
-
Object
- Object
- Rcom::Response
- Defined in:
- lib/rcom/rpc.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(params) ⇒ Response
constructor
A new instance of Response.
- #send_method(method, args) ⇒ Object
- #serve ⇒ Object
Constructor Details
#initialize(params) ⇒ Response
Returns a new instance of Response.
31 32 33 34 35 |
# File 'lib/rcom/rpc.rb', line 31 def initialize(params) @node = params[:node] @channel = params[:channel] @server = params[:server] end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
29 30 31 |
# File 'lib/rcom/rpc.rb', line 29 def channel @channel end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
29 30 31 |
# File 'lib/rcom/rpc.rb', line 29 def node @node end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
29 30 31 |
# File 'lib/rcom/rpc.rb', line 29 def server @server end |
Instance Method Details
#send_method(method, args) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/rcom/rpc.rb', line 60 def send_method(method, args) begin server.send(method, args) rescue return nil end end |
#serve ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rcom/rpc.rb', line 37 def serve begin loop do ch, request = node.brpop(channel) = MessagePack.unpack( request, symbolize_keys: true ) response = send_method( [:method], [:args] ) node.rpush([:id], response.to_msgpack) end rescue sleep 1 retry rescue Interrupt => _ end end |