thrift-client 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02cbfa3837919e23cc7f2d62998025440cde2ab7
4
- data.tar.gz: 7fad55e8761f1a9154abe35b005aaad88085ad11
3
+ metadata.gz: 3ba417e66ac3216b8a6490adb38bf90a85db127b
4
+ data.tar.gz: a4d4bcf81f1a5541d93b1b719581b12bf0c2021b
5
5
  SHA512:
6
- metadata.gz: 433bc811fc642c33ffa21244d69e5ef2cf88aea4610efeb21f7b646d0743fbd4f040c1c2d961a1fe6d2345781a841ec036b2173246ac7a272a33e40f3bf6f0cc
7
- data.tar.gz: cd261fa3ddeb856f19cddef85a2af7ff7f14d580326fdb6ba13769dc68037cf2de9cd544be15d4cf6d3d5db00907c32944909297db8e0b628b857e901c331bf2
6
+ metadata.gz: 1df06deed7d3742dc314235bb5ba66202e0056ec52a80c4552b3e7b9c307bdf1039fb60674cf18219e8f7b1d3d95382447aef7b862b32d6023e547134caf7226
7
+ data.tar.gz: 1c83f131fb7021cd85bee6a948b47e9ee5f33366afc2230a1fb54e4e25006f3aef34d31d9b184477c9367aff8959411bf389bda1da306c15d14825359da8b5ef
@@ -1,5 +1,7 @@
1
1
  require 'thrift'
2
2
  require 'thrift_client/thrift'
3
+ require 'thrift_client/multiplexed_processor'
4
+ require 'thrift_client/multiplexed_client'
3
5
  require 'thrift_client/abstract_server'
4
6
  require 'thrift_client/single_client_server'
5
7
  require 'thrift_client/multi_client_server'
@@ -0,0 +1,26 @@
1
+ module Thrift
2
+ module Client
3
+ alias :old_initialize :initialize
4
+
5
+ def initialize(service, iprot, oprot=nil)
6
+ old_initialize(iprot, oprot)
7
+ @service = service
8
+ end
9
+
10
+ def send_message(name, args_class, args = {})
11
+ @oprot.write_message_begin(@service + ':' + name, MessageTypes::CALL, @seqid)
12
+ data = args_class.new
13
+ args.each do |k, v|
14
+ data.send("#{k.to_s}=", v)
15
+ end
16
+ begin
17
+ data.write(@oprot)
18
+ rescue StandardError => e
19
+ @oprot.trans.close
20
+ raise e
21
+ end
22
+ @oprot.write_message_end
23
+ @oprot.trans.flush
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ module Thrift
2
+ class MultiplexedProcessor
3
+ def initialize
4
+ @map = Hash.new
5
+ end
6
+
7
+ def register(service, processor)
8
+ processor.instance_variable_set(:@service, service)
9
+ @map[service] = processor
10
+ end
11
+
12
+ def process(iprot, oprot)
13
+ name, type, seqid = iprot.read_message_begin
14
+
15
+ service, method = name.split(':')
16
+ processor = @map[service]
17
+ if processor.respond_to?("process_#{method}")
18
+ processor.send("process_#{method}", seqid, iprot, oprot)
19
+ true
20
+ else
21
+ iprot.skip(Types::STRUCT)
22
+ iprot.read_message_end
23
+ x = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, 'Unknown function ' + name)
24
+ oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
25
+ x.write(oprot)
26
+ oprot.write_message_end
27
+ oprot.trans.flush
28
+ false
29
+ end
30
+ end
31
+ end
32
+
33
+ module Processor
34
+ def write_result(result, oprot, name, seqid)
35
+ oprot.write_message_begin(@service + ':' + name, MessageTypes::REPLY, seqid)
36
+ result.write(oprot)
37
+ oprot.write_message_end
38
+ oprot.trans.flush
39
+ end
40
+ end
41
+ end
@@ -13,6 +13,20 @@ module Thrift
13
13
  end
14
14
  end
15
15
 
16
+ module Struct
17
+ def to_hash
18
+ hash = {}
19
+ each_field do |fid, field_info|
20
+ name = field_info[:name]
21
+ value = instance_variable_get("@#{name}")
22
+ unless field_info[:optional] && value.nil?
23
+ hash.store(name, value)
24
+ end
25
+ end
26
+ return hash
27
+ end
28
+ end
29
+
16
30
  class MultiplexedProcessor
17
31
  def initialize
18
32
  @actual_processors = Hash.new
@@ -69,7 +83,7 @@ module Thrift
69
83
 
70
84
  def write_message_begin(name, type, seqid)
71
85
  case type
72
- when ::Thrift::MessageTypes.CALL, ::Thrift::MessageTypes.ONEWAY
86
+ when MessageTypes::CALL, MessageTypes::ONEWAY
73
87
  @protocol.write_message_begin(@service_name + ":" + name, type, seqid)
74
88
  else
75
89
  @protocol.write_message_begin(name, type, seqid)
@@ -15,7 +15,7 @@ class ClientTest < Test::Unit::TestCase
15
15
  transport = Thrift::Socket.new('127.0.0.1', 9999)
16
16
  transport = Thrift::FramedTransport.new(transport)
17
17
  protocol = Thrift::BinaryProtocol.new(transport)
18
- protocol = Thrift::MultiplexedProtocol.new(protocol,"foo")
18
+ # protocol = Thrift::MultiplexedProtocol.new(protocol,"foobar")
19
19
  @client = Foo::FoobarService::Client.new(protocol)
20
20
  transport.open
21
21
  puts "setup"
@@ -31,7 +31,14 @@ class ClientTest < Test::Unit::TestCase
31
31
  end
32
32
 
33
33
  bar = @client.getBar
34
+
34
35
  assert_not_nil(bar)
36
+ # puts bar.to_hash.class
37
+ # hash_bar = bar.to_hash
38
+ # puts hash_bar['first']
39
+ # puts hash_bar['second']
40
+ # puts hash_bar['third']
41
+ # puts hash_bar['fourth']
35
42
 
36
43
  foo = Foo::Foo.new
37
44
  foo.first = 1
@@ -44,13 +44,13 @@ module Server
44
44
  def self.start_server(host, port, serverClass)
45
45
  handler = FooHandler.new
46
46
  foo_processor = Foo::FoobarService::Processor.new(handler)
47
- puts foo_processor.class.name.split("::")[-2].downcase.gsub("service","")
48
- multi_processor = Thrift::MultiplexedProcessor.new
49
- multi_processor.register(foo_processor.class.name.split("::")[-2], foo_processor)
47
+ # puts foo_processor.class.name.split("::")[-2].downcase.gsub("service","")
48
+ # multi_processor = Thrift::MultiplexedProcessor.new
49
+ # multi_processor.register(foo_processor.class.name.split("::")[-2].downcase.gsub("service",""), foo_processor)
50
50
  transport = ServerSocket.new(host, port)
51
51
  # transport = FramedTransport.new(transport)
52
52
  transport_factory = FramedTransportFactory.new
53
- args = [multi_processor, transport, transport_factory]
53
+ args = [foo_processor, transport, transport_factory]
54
54
  if serverClass == NonblockingServer
55
55
  # logger = Logger.new(STDOUT)
56
56
  # logger.level = Logger::WARN
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrift-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ted Wang
@@ -30,20 +30,22 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - lib/thrift_client/abstract_server.rb
34
33
  - lib/thrift_client/abstract_thrift_client.rb
34
+ - lib/thrift_client/abstract_server.rb
35
35
  - lib/thrift_client/multi_client_server.rb
36
- - lib/thrift_client/single_client_server.rb
36
+ - lib/thrift_client/multiplexed_client.rb
37
37
  - lib/thrift_client/thrift.rb
38
+ - lib/thrift_client/multiplexed_processor.rb
39
+ - lib/thrift_client/single_client_server.rb
38
40
  - lib/thrift_client.rb
39
- - test/client_test.rb
40
- - test/foobar_constants.rb
41
41
  - test/foobar_service.rb
42
+ - test/server.rb
42
43
  - test/foobar_types.rb
44
+ - test/foobar_constants.rb
45
+ - test/client_test.rb
43
46
  - test/multiplexed_protocol_test.rb
44
- - test/multiplexed_server.rb
45
47
  - test/options_config_test.rb
46
- - test/server.rb
48
+ - test/multiplexed_server.rb
47
49
  homepage: http://www.ximalaya.com
48
50
  licenses:
49
51
  - MIT2.0
@@ -69,11 +71,11 @@ signing_key:
69
71
  specification_version: 4
70
72
  summary: A Thrift client wrapper that encapsulates some common behavior.
71
73
  test_files:
72
- - test/client_test.rb
73
- - test/foobar_constants.rb
74
74
  - test/foobar_service.rb
75
+ - test/server.rb
75
76
  - test/foobar_types.rb
77
+ - test/foobar_constants.rb
78
+ - test/client_test.rb
76
79
  - test/multiplexed_protocol_test.rb
77
- - test/multiplexed_server.rb
78
80
  - test/options_config_test.rb
79
- - test/server.rb
81
+ - test/multiplexed_server.rb