Module: Thrift::Client
- Included in:
- BaseClient
- Defined in:
- lib/thrift/client.rb
Instance Method Summary collapse
- #handle_exception(mtype) ⇒ Object
- #initialize(iprot, oprot = nil) ⇒ Object
- #receive_message(result_klass, name = nil) ⇒ Object
- #send_message(name, args_class, args = {}) ⇒ Object
- #send_message_args(args_class, args) ⇒ Object
- #send_message_instance(data) ⇒ Object
- #send_oneway_message(name, args_class, args = {}) ⇒ Object
Instance Method Details
#handle_exception(mtype) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/thrift/client.rb', line 87 def handle_exception(mtype) return if mtype != MessageTypes::EXCEPTION x = ApplicationException.new x.read(@iprot) @iprot. raise x end |
#initialize(iprot, oprot = nil) ⇒ Object
23 24 25 26 27 |
# File 'lib/thrift/client.rb', line 23 def initialize(iprot, oprot = nil) @iprot = iprot @oprot = oprot || iprot @seqid = 0 end |
#receive_message(result_klass, name = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/thrift/client.rb', line 62 def (result_klass, name=nil) fname, mtype, seqid = @iprot. handle_exception(mtype) raise ApplicationException.new( ApplicationException::BAD_SEQUENCE_ID, 'out of seq' ) if seqid != @seqid raise ApplicationException.new( ApplicationException::INVALID_MESSAGE_TYPE, 'invalid message type' ) if mtype != MessageTypes::REPLY raise ApplicationException.new( ApplicationException::WRONG_METHOD_NAME, 'wrong method name' ) if !name.nil? && name != fname result = result_klass.new result.read(@iprot) @iprot. result end |
#send_message(name, args_class, args = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/thrift/client.rb', line 29 def (name, args_class, args = {}) @seqid += 1 @oprot.(name, MessageTypes::CALL, @seqid) (args_class, args) end |
#send_message_args(args_class, args) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/thrift/client.rb', line 41 def (args_class, args) data = args_class.new args.each do |k, v| data.send("#{k.to_s}=", v) end (data) end |
#send_message_instance(data) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/thrift/client.rb', line 51 def (data) 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
35 36 37 38 39 |
# File 'lib/thrift/client.rb', line 35 def (name, args_class, args = {}) @seqid += 1 @oprot.(name, MessageTypes::ONEWAY, @seqid) (args_class, args) end |