class RedPack::Server
Public Class Methods
new(redis, name, transcoder, dispatcher)
click to toggle source
# File lib/redpack-ruby/servers.rb, line 4 def initialize(redis, name, transcoder, dispatcher) @queue_name = RedPack::Consts::queue_name(name) @redis = redis @transcoder = transcoder @dispatcher = dispatcher end
Public Instance Methods
listen(timeout=0)
click to toggle source
# File lib/redpack-ruby/servers.rb, line 11 def listen(timeout=0) a = @redis.blpop(@queue_name, timeout) unless a.nil? then unpacked = @transcoder.unpack(a[1]) response_queue_name = unpacked['return'] data = unpacked['data'] case data[0] when RedPack::Consts::REQUEST then process_REQUEST(response_queue_name, data[1], data[2], data[3]) when RedPack::Consts::NOTIFY then process_NOTIFY(data[1], data[2]) when RedPack::Consts::RESPONSE then raise Exception.new('plz dont do that...') else raise Exception.new("unknown code -- #{data[0]}") end end end
process_NOTIFY(method, params)
click to toggle source
# File lib/redpack-ruby/servers.rb, line 35 def process_NOTIFY(method, params) ctx = RedPack::RequestContext.new(nil, nil, RedPack::Consts::NOTIFY) @dispatcher.dispatch(ctx, method, params) end
process_REQUEST(response_queue_name, msg_id, method, params)
click to toggle source
# File lib/redpack-ruby/servers.rb, line 30 def process_REQUEST(response_queue_name, msg_id, method, params) ctx = RedPack::RequestContext.new(response_queue_name, msg_id, RedPack::Consts::REQUEST) @dispatcher.dispatch(ctx, method, params) end