module Thrift::Client
Constants
- MAX_SEQUENCE_ID
- MIN_SEQUENCE_ID
Public Class Methods
Source
# File lib/thrift/client.rb 26 def initialize(iprot, oprot = nil) 27 @iprot = iprot 28 @oprot = oprot || iprot 29 @seqid = 0 30 @pending_seqids = [] 31 end
Public Instance Methods
Source
# File lib/thrift/client.rb 79 def receive_message(result_klass) 80 result = result_klass.new 81 result.read(@iprot) 82 @iprot.read_message_end 83 result 84 end
Source
# File lib/thrift/client.rb 45 def receive_message_begin 46 fname, mtype, rseqid = @iprot.read_message_begin 47 [fname, mtype, rseqid] 48 end
Source
# File lib/thrift/client.rb 33 def send_message(name, args_class, args = {}) 34 write_message(name, MessageTypes::CALL, args_class, args) 35 end
Source
# File lib/thrift/client.rb 41 def send_message_args(args_class, args) 42 write_message(nil, nil, args_class, args) 43 end
Source
# File lib/thrift/client.rb 37 def send_oneway_message(name, args_class, args = {}) 38 write_message(name, MessageTypes::ONEWAY, args_class, args) 39 end
Source
# File lib/thrift/client.rb 50 def validate_message_begin(fname, mtype, rseqid, expected_name) 51 expected_seqid = dequeue_pending_seqid 52 53 if mtype == MessageTypes::EXCEPTION 54 raise_application_exception 55 end 56 57 if mtype != MessageTypes::REPLY 58 raise ApplicationException.new( 59 ApplicationException::INVALID_MESSAGE_TYPE, 60 "#{expected_name} failed: invalid message type", 61 ) 62 end 63 64 if fname != expected_name 65 raise ApplicationException.new( 66 ApplicationException::WRONG_METHOD_NAME, 67 "#{expected_name} failed: wrong method name", 68 ) 69 end 70 71 return if !expected_seqid.nil? && rseqid == expected_seqid 72 73 raise ApplicationException.new( 74 ApplicationException::BAD_SEQUENCE_ID, 75 "#{expected_name} failed: out of sequence response", 76 ) 77 end
Private Instance Methods
Source
# File lib/thrift/client.rb 118 def dequeue_pending_seqid 119 @pending_seqids.shift 120 end
Source
# File lib/thrift/client.rb 112 def next_seqid! 113 seqid = @seqid 114 @seqid = (seqid == MAX_SEQUENCE_ID) ? MIN_SEQUENCE_ID : seqid + 1 115 seqid 116 end
Source
# File lib/thrift/client.rb 122 def raise_application_exception 123 x = ApplicationException.new 124 x.read(@iprot) 125 @iprot.read_message_end 126 raise x 127 end
Source
# File lib/thrift/client.rb 88 def write_message(name, type, args_class, args) 89 data = args_class.new 90 args.each do |k, v| 91 data.send("#{k}=", v) 92 end 93 seqid = next_seqid! unless name.nil? 94 95 flush_result = begin 96 @oprot.write_message_begin(name, type, seqid) unless name.nil? 97 data.write(@oprot) 98 @oprot.write_message_end 99 @oprot.trans.flush 100 rescue StandardError 101 begin 102 @oprot.trans.close 103 rescue StandardError 104 # Preserve the original send error. 105 end 106 raise 107 end 108 109 type == MessageTypes::CALL ? @pending_seqids << seqid : flush_result 110 end