Module: Thrift::Client
- Defined in:
- lib/thrift/client.rb
Constant Summary collapse
- MIN_SEQUENCE_ID =
-(2**31)
- MAX_SEQUENCE_ID =
(2**31) - 1
Instance Method Summary collapse
- #handle_exception(mtype) ⇒ Object
- #initialize(iprot, oprot = nil) ⇒ Object
- #receive_message(result_klass) ⇒ Object
- #receive_message_begin ⇒ Object
- #reply_seqid(rseqid) ⇒ Object
- #send_message(name, args_class, args = {}) ⇒ Object
- #send_message_args(args_class, args) ⇒ Object
- #send_oneway_message(name, args_class, args = {}) ⇒ Object
- #validate_message_begin(fname, mtype, rseqid, expected_name) ⇒ Object
Instance Method Details
#handle_exception(mtype) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/thrift/client.rb', line 105 def handle_exception(mtype) if mtype == MessageTypes::EXCEPTION dequeue_pending_seqid raise_application_exception end end |
#initialize(iprot, oprot = nil) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/thrift/client.rb', line 25 def initialize(iprot, oprot = nil) @iprot = iprot @oprot = oprot || iprot @seqid = 0 @pending_seqids = [] end |
#receive_message(result_klass) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/thrift/client.rb', line 98 def (result_klass) result = result_klass.new result.read(@iprot) @iprot. result end |
#receive_message_begin ⇒ Object
59 60 61 62 |
# File 'lib/thrift/client.rb', line 59 def () fname, mtype, rseqid = @iprot. [fname, mtype, rseqid] end |
#reply_seqid(rseqid) ⇒ Object
64 65 66 67 |
# File 'lib/thrift/client.rb', line 64 def reply_seqid(rseqid) expected_seqid = dequeue_pending_seqid !expected_seqid.nil? && rseqid == expected_seqid end |
#send_message(name, args_class, args = {}) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/thrift/client.rb', line 32 def (name, args_class, args = {}) seqid = next_seqid! @oprot.(name, MessageTypes::CALL, seqid) (args_class, args) @pending_seqids << seqid end |
#send_message_args(args_class, args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/thrift/client.rb', line 44 def (args_class, args) data = args_class.new args.each do |k, v| data.send("#{k.to_s}=", v) end begin data.write(@oprot) rescue StandardError => e @oprot.trans.close raise e end @oprot. @oprot.trans.flush end |
#send_oneway_message(name, args_class, args = {}) ⇒ Object
39 40 41 42 |
# File 'lib/thrift/client.rb', line 39 def (name, args_class, args = {}) @oprot.(name, MessageTypes::ONEWAY, next_seqid!) (args_class, args) end |
#validate_message_begin(fname, mtype, rseqid, expected_name) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/thrift/client.rb', line 69 def (fname, mtype, rseqid, expected_name) expected_seqid = dequeue_pending_seqid if mtype == MessageTypes::EXCEPTION raise_application_exception end if mtype != MessageTypes::REPLY raise ApplicationException.new( ApplicationException::INVALID_MESSAGE_TYPE, "#{expected_name} failed: invalid message type" ) end if fname != expected_name raise ApplicationException.new( ApplicationException::WRONG_METHOD_NAME, "#{expected_name} failed: wrong method name" ) end return if !expected_seqid.nil? && rseqid == expected_seqid raise ApplicationException.new( ApplicationException::BAD_SEQUENCE_ID, "#{expected_name} failed: out of sequence response" ) end |