Module: MessagePack::Rpc::Client
- Defined in:
- lib/msgpack/rpc/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(meth, *args, &blk) ⇒ Object
- #cancel(id) ⇒ Object
- #notify(meth, *args) ⇒ Object
- #on(name, &blk) ⇒ Object
- #receive_dgram(data) ⇒ Object
- #receive_stream(data) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/msgpack/rpc/client.rb', line 17 def included(klass) m = Module.new { klass.instance_variable_set(:@msgpack_options, {}) def (opts = :none) if opts.nil? || opts.kind_of?(Hash) @msgpack_options = opts end return (@msgpack_options = opts) end def new_unpacker return MessagePack::Unpacker.new(@msgpack_options || {}) end } klass.extend(m) end |
Instance Method Details
#call(meth, *args, &blk) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/msgpack/rpc/client.rb', line 70 def call(meth, *args, &blk) raise ArgumentError.new("handler is not spcified") if not blk id = new_id session_map[id] = blk send_data([0, id, meth, args].to_msgpack) return id end |
#cancel(id) ⇒ Object
85 86 87 |
# File 'lib/msgpack/rpc/client.rb', line 85 def cancel(id) session_map.delete(id) end |
#notify(meth, *args) ⇒ Object
81 82 83 |
# File 'lib/msgpack/rpc/client.rb', line 81 def notify(meth, *args) send_data([2, meth, args].to_msgpack) end |
#on(name, &blk) ⇒ Object
148 149 150 151 |
# File 'lib/msgpack/rpc/client.rb', line 148 def on(name, &blk) raise ArgumentError.new("handler is not spcified") if not blk notify_handler[name] = blk end |
#receive_dgram(data) ⇒ Object
131 132 133 |
# File 'lib/msgpack/rpc/client.rb', line 131 def receive_dgram(data) eval_response(MessagePack.unpack(data, self.class.)) end |
#receive_stream(data) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/msgpack/rpc/client.rb', line 135 def receive_stream(data) begin unpacker.feed_each(data) {|resp| eval_response(resp)} rescue MessagePack::UnpackError => e unpacker.reset error_occured(e) rescue => e error_occured(e) end end |