]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/rb/lib/thrift/client.rb
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / rb / lib / thrift / client.rb
CommitLineData
f67539c2
TL
1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
20module Thrift
21 module Client
22 def initialize(iprot, oprot=nil)
23 @iprot = iprot
24 @oprot = oprot || iprot
25 @seqid = 0
26 end
27
28 def send_message(name, args_class, args = {})
29 @oprot.write_message_begin(name, MessageTypes::CALL, @seqid)
30 send_message_args(args_class, args)
31 end
32
33 def send_oneway_message(name, args_class, args = {})
34 @oprot.write_message_begin(name, MessageTypes::ONEWAY, @seqid)
35 send_message_args(args_class, args)
36 end
37
38 def send_message_args(args_class, args)
39 data = args_class.new
40 args.each do |k, v|
41 data.send("#{k.to_s}=", v)
42 end
43 begin
44 data.write(@oprot)
45 rescue StandardError => e
46 @oprot.trans.close
47 raise e
48 end
49 @oprot.write_message_end
50 @oprot.trans.flush
51 end
52
53 def receive_message(result_klass)
54 fname, mtype, rseqid = @iprot.read_message_begin
55 handle_exception(mtype)
56 result = result_klass.new
57 result.read(@iprot)
58 @iprot.read_message_end
59 result
60 end
61
62 def handle_exception(mtype)
63 if mtype == MessageTypes::EXCEPTION
64 x = ApplicationException.new
65 x.read(@iprot)
66 @iprot.read_message_end
67 raise x
68 end
69 end
70 end
71end