Class: RedisRPC::Server
- Inherits:
-
Object
- Object
- RedisRPC::Server
- Defined in:
- lib/redisrpc.rb
Instance Method Summary collapse
- #flush_queue! ⇒ Object
-
#initialize(redis_server, message_queue, local_object) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(redis_server, message_queue, local_object) ⇒ Server
Returns a new instance of Server.
96 97 98 99 100 |
# File 'lib/redisrpc.rb', line 96 def initialize(redis_server, , local_object) @redis_server = redis_server @message_queue = @local_object = local_object end |
Instance Method Details
#flush_queue! ⇒ Object
131 132 133 |
# File 'lib/redisrpc.rb', line 131 def flush_queue! @redis_server.del @message_queue end |
#run ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/redisrpc.rb', line 102 def run loop do , = @redis_server.blpop @message_queue, 0 if $DEBUG fail 'assertion failed' if != @message_queue $stderr.puts 'RPC Request: ' + end rpc_request = MultiJson.load response_queue = rpc_request['response_queue'] function_call = FunctionCall.new(rpc_request['function_call']) begin return_value = @local_object.send( function_call.method, *function_call.args ) rpc_response = {'return_value' => return_value} rescue => err rpc_response = {'exception' => err} end = MultiJson.dump rpc_response if $DEBUG $stderr.puts 'RPC Response: ' + end @redis_server.rpush response_queue, end end |
#run! ⇒ Object
126 127 128 129 |
# File 'lib/redisrpc.rb', line 126 def run! flush_queue! run end |