thrift 0.0.751142 → 0.0.810255.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -1
- data/Manifest +47 -44
- data/README +19 -6
- data/Rakefile +1 -1
- data/benchmark/Benchmark.thrift +19 -0
- data/benchmark/benchmark.rb +20 -3
- data/benchmark/client.rb +20 -2
- data/benchmark/server.rb +22 -4
- data/benchmark/thin_server.rb +22 -4
- data/ext/binary_protocol_accelerated.c +32 -21
- data/ext/binary_protocol_accelerated.h +19 -0
- data/ext/compact_protocol.c +665 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +19 -1
- data/ext/extconf.rb +19 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +29 -5
- data/ext/memory_buffer.h +19 -0
- data/ext/protocol.c +20 -1
- data/ext/protocol.h +19 -0
- data/ext/struct.c +115 -83
- data/ext/struct.h +19 -0
- data/ext/thrift_native.c +23 -2
- data/lib/thrift/client.rb +19 -1
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/exceptions.rb +19 -2
- data/lib/thrift/processor.rb +19 -1
- data/lib/thrift/protocol/base_protocol.rb +290 -0
- data/lib/thrift/protocol/{binaryprotocol.rb → binary_protocol.rb} +27 -15
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +35 -0
- data/lib/thrift/protocol/compact_protocol.rb +422 -0
- data/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/thrift/server/base_server.rb +31 -0
- data/lib/thrift/server/{httpserver.rb → mongrel_http_server.rb} +19 -5
- data/lib/thrift/server/{nonblockingserver.rb → nonblocking_server.rb} +42 -24
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/thrift/struct.rb +73 -47
- data/lib/thrift/thrift_native.rb +24 -0
- data/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/thrift/transport/base_transport.rb +70 -0
- data/lib/thrift/transport/buffered_transport.rb +77 -0
- data/lib/thrift/transport/framed_transport.rb +90 -0
- data/lib/thrift/transport/http_client_transport.rb +45 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +96 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +22 -53
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +20 -2
- data/lib/thrift.rb +50 -19
- data/script/proto_benchmark.rb +121 -0
- data/script/read_struct.rb +43 -0
- data/script/write_struct.rb +30 -0
- data/spec/ThriftSpec.thrift +40 -2
- data/spec/{protocol_spec.rb → base_protocol_spec.rb} +25 -7
- data/spec/{transport_spec.rb → base_transport_spec.rb} +44 -52
- data/spec/binary_protocol_accelerated_spec.rb +41 -0
- data/spec/{binaryprotocol_spec.rb → binary_protocol_spec.rb} +20 -2
- data/spec/{binaryprotocol_spec_shared.rb → binary_protocol_spec_shared.rb} +117 -16
- data/spec/client_spec.rb +23 -4
- data/spec/compact_protocol_spec.rb +117 -0
- data/spec/exception_spec.rb +19 -0
- data/spec/http_client_spec.rb +49 -0
- data/spec/{httpserver_spec.rb → mongrel_http_server_spec.rb} +26 -7
- data/spec/{nonblockingserver_spec.rb → nonblocking_server_spec.rb} +25 -5
- data/spec/processor_spec.rb +19 -0
- data/spec/serializer_spec.rb +27 -10
- data/spec/server_socket_spec.rb +80 -0
- data/spec/server_spec.rb +35 -16
- data/spec/socket_spec.rb +19 -55
- data/spec/socket_spec_shared.rb +19 -0
- data/spec/spec_helper.rb +34 -9
- data/spec/struct_spec.rb +26 -18
- data/spec/types_spec.rb +19 -1
- data/spec/{unixsocket_spec.rb → unix_socket_spec.rb} +19 -1
- data/thrift.gemspec +6 -6
- data.tar.gz.sig +0 -0
- metadata +80 -70
- metadata.gz.sig +0 -0
- data/COPYING +0 -14
- data/LICENSE +0 -14
- data/Makefile.am +0 -15
- data/benchmark/gen-rb/BenchmarkService.rb +0 -81
- data/benchmark/gen-rb/Benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/Benchmark_types.rb +0 -10
- data/lib/thrift/deprecation.rb +0 -155
- data/lib/thrift/protocol/binaryprotocolaccelerated.rb +0 -19
- data/lib/thrift/protocol/tbinaryprotocol.rb +0 -2
- data/lib/thrift/protocol/tprotocol.rb +0 -2
- data/lib/thrift/protocol.rb +0 -270
- data/lib/thrift/serializer.rb +0 -27
- data/lib/thrift/server/thttpserver.rb +0 -2
- data/lib/thrift/server/tserver.rb +0 -2
- data/lib/thrift/server.rb +0 -135
- data/lib/thrift/thrift.rb +0 -14
- data/lib/thrift/transport/httpclient.rb +0 -29
- data/lib/thrift/transport/thttpclient.rb +0 -2
- data/lib/thrift/transport/tsocket.rb +0 -2
- data/lib/thrift/transport/ttransport.rb +0 -2
- data/lib/thrift/transport/unixsocket.rb +0 -58
- data/lib/thrift/transport.rb +0 -319
- data/spec/backwards_compatibility_spec.rb +0 -136
- data/spec/binaryprotocolaccelerated_spec.rb +0 -101
- data/spec/deprecation_spec.rb +0 -443
- data/spec/gen-rb/NonblockingService.rb +0 -268
- data/spec/gen-rb/ThriftSpec_constants.rb +0 -11
- data/spec/gen-rb/ThriftSpec_types.rb +0 -134
- data/spec/httpclient_spec.rb +0 -31
data/lib/thrift/deprecation.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
# provide a backwards-compatible wrapper API and deprecate it
|
2
|
-
|
3
|
-
module Thrift
|
4
|
-
DEPRECATION = true unless const_defined?(:DEPRECATION)
|
5
|
-
end
|
6
|
-
|
7
|
-
class Module
|
8
|
-
# Wraps the given methods to print a warning and call the real method
|
9
|
-
# Example:
|
10
|
-
# deprecate! :readAll => :read_all
|
11
|
-
#--
|
12
|
-
# Yeah, this is ugly, passing a string to module_eval, but unfortunately
|
13
|
-
# using a block removes the ability to pass blocks to the defined method
|
14
|
-
# and breaks spec
|
15
|
-
def deprecate!(methods)
|
16
|
-
return unless Thrift::DEPRECATION
|
17
|
-
methods.each_pair do |old, new|
|
18
|
-
module_eval <<-EOF
|
19
|
-
def #{old}(*args, &block)
|
20
|
-
old, new = #{[old,new].inspect}
|
21
|
-
STDERR.puts "Warning: calling deprecated method \#{self.is_a?(Module) ? "\#{self}." : "\#{self.class}#"}\#{old}"
|
22
|
-
STDERR.puts " from \#{caller.first}"
|
23
|
-
target = (self.is_a?(Module) ? (class << self;self;end) : self.class)
|
24
|
-
target.send :define_method, old, target.instance_method(new) # unwrap
|
25
|
-
target.instance_method(new).bind(self).call(*args, &block)
|
26
|
-
end
|
27
|
-
EOF
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
module Thrift::DeprecationProxy # :nodoc:
|
33
|
-
# there's a really weird bug in Ruby where class variables behave wrong
|
34
|
-
# when used in a Class.new or #class_eval rather than in a class foo block.
|
35
|
-
CLASS_MAPPING = {}
|
36
|
-
MODULE_MAPPING = {}
|
37
|
-
def self.new_class(obj, name)
|
38
|
-
klass_id = CLASS_MAPPING.size
|
39
|
-
CLASS_MAPPING[klass_id] = [obj, name, true]
|
40
|
-
klass = Class.new(obj) do
|
41
|
-
klass = self
|
42
|
-
instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym|
|
43
|
-
undef_method sym
|
44
|
-
end
|
45
|
-
define_method :__thrift_deprecation_proxy_klass_id do
|
46
|
-
klass_id
|
47
|
-
end
|
48
|
-
def method_missing(sym, *args, &block)
|
49
|
-
klass_id = __thrift_deprecation_proxy_klass_id
|
50
|
-
obj, name, warned = CLASS_MAPPING[klass_id]
|
51
|
-
obj.instance_method(sym).bind(self).call(*args, &block)
|
52
|
-
end
|
53
|
-
(class << self;self;end).class_eval do
|
54
|
-
instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym|
|
55
|
-
undef_method sym
|
56
|
-
end
|
57
|
-
define_method :__thrift_deprecation_proxy_klass do
|
58
|
-
[klass, klass_id]
|
59
|
-
end
|
60
|
-
def method_missing(sym, *args, &block)
|
61
|
-
klass, klass_id = __thrift_deprecation_proxy_klass
|
62
|
-
obj, name, warned = CLASS_MAPPING[klass_id]
|
63
|
-
unless warned
|
64
|
-
STDERR.puts "Warning: class #{name} is deprecated"
|
65
|
-
STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}"
|
66
|
-
CLASS_MAPPING[klass_id][2] = true
|
67
|
-
end
|
68
|
-
if klass.__id__ == self.__id__
|
69
|
-
obj.send sym, *args, &block
|
70
|
-
else
|
71
|
-
obj.method(sym).unbind.bind(self).call(*args, &block)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
CLASS_MAPPING[klass_id][2] = false
|
77
|
-
klass
|
78
|
-
end
|
79
|
-
def self.new_module(obj, name)
|
80
|
-
mod_id = MODULE_MAPPING.size
|
81
|
-
MODULE_MAPPING[mod_id] = [obj, name, true]
|
82
|
-
mod = Module.new do
|
83
|
-
include obj
|
84
|
-
instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym|
|
85
|
-
undef_method sym
|
86
|
-
end
|
87
|
-
define_method :__thrift_deprecation_proxy_module_id do
|
88
|
-
mod_id
|
89
|
-
end
|
90
|
-
def method_missing(sym, *args, &block)
|
91
|
-
mod_id = __thrift_deprecation_proxy_module_id
|
92
|
-
obj, name, warned = MODULE_MAPPING[mod_id]
|
93
|
-
unless warned
|
94
|
-
STDERR.puts "Warning: module #{name} is deprecated"
|
95
|
-
STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}"
|
96
|
-
MODULE_MAPPING[mod_id][2] = true
|
97
|
-
end
|
98
|
-
obj.instance_method(sym).bind(self).call(*args, &block)
|
99
|
-
end
|
100
|
-
(class << self;self;end).class_eval do
|
101
|
-
instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym|
|
102
|
-
undef_method sym
|
103
|
-
end
|
104
|
-
define_method :__thrift_deprecation_proxy_module_id do
|
105
|
-
mod_id
|
106
|
-
end
|
107
|
-
def method_missing(sym, *args, &block)
|
108
|
-
mod_id = __thrift_deprecation_proxy_module_id
|
109
|
-
obj, name, warned = MODULE_MAPPING[mod_id]
|
110
|
-
unless warned
|
111
|
-
STDERR.puts "Warning: module #{name} is deprecated"
|
112
|
-
STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}"
|
113
|
-
MODULE_MAPPING[mod_id][2] = true
|
114
|
-
end
|
115
|
-
obj.send sym, *args, &block
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
MODULE_MAPPING[mod_id][2] = false
|
120
|
-
mod
|
121
|
-
end
|
122
|
-
def self.process_caller(stack)
|
123
|
-
dir = File.dirname(__FILE__)
|
124
|
-
stack.find { |frame| frame[0,dir.size] != dir }
|
125
|
-
end
|
126
|
-
def self.reset_deprecation_warnings
|
127
|
-
CLASS_MAPPING.each { |k,v| v[2] = false }
|
128
|
-
MODULE_MAPPING.each { |k,v| v[2] = false }
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
module Kernel
|
133
|
-
# Provides an alternate name for the class for deprecation purposes
|
134
|
-
# Example:
|
135
|
-
# deprecate_class! :TBinaryProtocol => Thrift::BinaryProtocol
|
136
|
-
#--
|
137
|
-
# at the moment this only works for creating top-level constants
|
138
|
-
# if necessary, this can be extended to take something like :'Thrift::TBinaryProtocol'
|
139
|
-
# alternately, Module can be extended with a similar method
|
140
|
-
def deprecate_class!(klasses)
|
141
|
-
return unless Thrift::DEPRECATION
|
142
|
-
klasses.each_pair do |old, new|
|
143
|
-
raise "deprecate_class! expected Class, called with #{new}" unless new.is_a? Class
|
144
|
-
Object.const_set old, Thrift::DeprecationProxy.new_class(new, old)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# like deprecate_class! but for Modules
|
149
|
-
def deprecate_module!(modules)
|
150
|
-
return unless Thrift::DEPRECATION
|
151
|
-
modules.each_pair do |old, new|
|
152
|
-
Object.const_set old, Thrift::DeprecationProxy.new_module(new, old)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'thrift/protocol/binaryprotocol'
|
2
|
-
require 'thrift_native'
|
3
|
-
|
4
|
-
=begin
|
5
|
-
The only change required for a transport to support TBinaryProtocolAccelerated is to implement 2 methods:
|
6
|
-
* borrow(size), which takes an optional argument and returns atleast _size_ bytes from the transport,
|
7
|
-
or the default buffer size if no argument is given
|
8
|
-
* consume!(size), which removes size bytes from the front of the buffer
|
9
|
-
|
10
|
-
See TMemoryBuffer and TBufferedTransport for examples.
|
11
|
-
=end
|
12
|
-
|
13
|
-
module Thrift
|
14
|
-
class BinaryProtocolAcceleratedFactory < ProtocolFactory
|
15
|
-
def get_protocol(trans)
|
16
|
-
BinaryProtocolAccelerated.new(trans)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/thrift/protocol.rb
DELETED
@@ -1,270 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2006- Facebook
|
3
|
-
# Distributed under the Apache Software License
|
4
|
-
#
|
5
|
-
# See accompanying file LICENSE or visit the Thrift site at:
|
6
|
-
# http://developers.facebook.com/thrift/
|
7
|
-
#
|
8
|
-
# Author: Mark Slee <mcslee@facebook.com>
|
9
|
-
#
|
10
|
-
|
11
|
-
# this require is to make generated struct definitions happy
|
12
|
-
require 'set'
|
13
|
-
|
14
|
-
module Thrift
|
15
|
-
class ProtocolException < Exception
|
16
|
-
|
17
|
-
UNKNOWN = 0
|
18
|
-
INVALID_DATA = 1
|
19
|
-
NEGATIVE_SIZE = 2
|
20
|
-
SIZE_LIMIT = 3
|
21
|
-
BAD_VERSION = 4
|
22
|
-
|
23
|
-
attr_reader :type
|
24
|
-
|
25
|
-
def initialize(type=UNKNOWN, message=nil)
|
26
|
-
super(message)
|
27
|
-
@type = type
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
deprecate_class! :TProtocolException => ProtocolException
|
32
|
-
|
33
|
-
class Protocol
|
34
|
-
|
35
|
-
attr_reader :trans
|
36
|
-
|
37
|
-
def initialize(trans)
|
38
|
-
@trans = trans
|
39
|
-
end
|
40
|
-
|
41
|
-
def native?
|
42
|
-
puts "wrong method is being called!"
|
43
|
-
false
|
44
|
-
end
|
45
|
-
|
46
|
-
def write_message_begin(name, type, seqid); nil; end
|
47
|
-
deprecate! :writeMessageBegin => :write_message_begin
|
48
|
-
|
49
|
-
def write_message_end; nil; end
|
50
|
-
deprecate! :writeMessageEnd => :write_message_end
|
51
|
-
|
52
|
-
def write_struct_begin(name); nil; end
|
53
|
-
deprecate! :writeStructBegin => :write_struct_begin
|
54
|
-
|
55
|
-
def write_struct_end; nil; end
|
56
|
-
deprecate! :writeStructEnd => :write_struct_end
|
57
|
-
|
58
|
-
def write_field_begin(name, type, id); nil; end
|
59
|
-
deprecate! :writeFieldBegin => :write_field_begin
|
60
|
-
|
61
|
-
def write_field_end; nil; end
|
62
|
-
deprecate! :writeFieldEnd => :write_field_end
|
63
|
-
|
64
|
-
def write_field_stop; nil; end
|
65
|
-
deprecate! :writeFieldStop => :write_field_stop
|
66
|
-
|
67
|
-
def write_map_begin(ktype, vtype, size); nil; end
|
68
|
-
deprecate! :writeMapBegin => :write_map_begin
|
69
|
-
|
70
|
-
def write_map_end; nil; end
|
71
|
-
deprecate! :writeMapEnd => :write_map_end
|
72
|
-
|
73
|
-
def write_list_begin(etype, size); nil; end
|
74
|
-
deprecate! :writeListBegin => :write_list_begin
|
75
|
-
|
76
|
-
def write_list_end; nil; end
|
77
|
-
deprecate! :writeListEnd => :write_list_end
|
78
|
-
|
79
|
-
def write_set_begin(etype, size); nil; end
|
80
|
-
deprecate! :writeSetBegin => :write_set_begin
|
81
|
-
|
82
|
-
def write_set_end; nil; end
|
83
|
-
deprecate! :writeSetEnd => :write_set_end
|
84
|
-
|
85
|
-
def write_bool(bool); nil; end
|
86
|
-
deprecate! :writeBool => :write_bool
|
87
|
-
|
88
|
-
def write_byte(byte); nil; end
|
89
|
-
deprecate! :writeByte => :write_byte
|
90
|
-
|
91
|
-
def write_i16(i16); nil; end
|
92
|
-
deprecate! :writeI16 => :write_i16
|
93
|
-
|
94
|
-
def write_i32(i32); nil; end
|
95
|
-
deprecate! :writeI32 => :write_i32
|
96
|
-
|
97
|
-
def write_i64(i64); nil; end
|
98
|
-
deprecate! :writeI64 => :write_i64
|
99
|
-
|
100
|
-
def write_double(dub); nil; end
|
101
|
-
deprecate! :writeDouble => :write_double
|
102
|
-
|
103
|
-
def write_string(str); nil; end
|
104
|
-
deprecate! :writeString => :write_string
|
105
|
-
|
106
|
-
def read_message_begin; nil; end
|
107
|
-
deprecate! :readMessageBegin => :read_message_begin
|
108
|
-
|
109
|
-
def read_message_end; nil; end
|
110
|
-
deprecate! :readMessageEnd => :read_message_end
|
111
|
-
|
112
|
-
def read_struct_begin; nil; end
|
113
|
-
deprecate! :readStructBegin => :read_struct_begin
|
114
|
-
|
115
|
-
def read_struct_end; nil; end
|
116
|
-
deprecate! :readStructEnd => :read_struct_end
|
117
|
-
|
118
|
-
def read_field_begin; nil; end
|
119
|
-
deprecate! :readFieldBegin => :read_field_begin
|
120
|
-
|
121
|
-
def read_field_end; nil; end
|
122
|
-
deprecate! :readFieldEnd => :read_field_end
|
123
|
-
|
124
|
-
def read_map_begin; nil; end
|
125
|
-
deprecate! :readMapBegin => :read_map_begin
|
126
|
-
|
127
|
-
def read_map_end; nil; end
|
128
|
-
deprecate! :readMapEnd => :read_map_end
|
129
|
-
|
130
|
-
def read_list_begin; nil; end
|
131
|
-
deprecate! :readListBegin => :read_list_begin
|
132
|
-
|
133
|
-
def read_list_end; nil; end
|
134
|
-
deprecate! :readListEnd => :read_list_end
|
135
|
-
|
136
|
-
def read_set_begin; nil; end
|
137
|
-
deprecate! :readSetBegin => :read_set_begin
|
138
|
-
|
139
|
-
def read_set_end; nil; end
|
140
|
-
deprecate! :readSetEnd => :read_set_end
|
141
|
-
|
142
|
-
def read_bool; nil; end
|
143
|
-
deprecate! :readBool => :read_bool
|
144
|
-
|
145
|
-
def read_byte; nil; end
|
146
|
-
deprecate! :readByte => :read_byte
|
147
|
-
|
148
|
-
def read_i16; nil; end
|
149
|
-
deprecate! :readI16 => :read_i16
|
150
|
-
|
151
|
-
def read_i32; nil; end
|
152
|
-
deprecate! :readI32 => :read_i32
|
153
|
-
|
154
|
-
def read_i64; nil; end
|
155
|
-
deprecate! :readI64 => :read_i64
|
156
|
-
|
157
|
-
def read_double; nil; end
|
158
|
-
deprecate! :readDouble => :read_double
|
159
|
-
|
160
|
-
def read_string; nil; end
|
161
|
-
deprecate! :readString => :read_string
|
162
|
-
|
163
|
-
def write_field(name, type, fid, value)
|
164
|
-
write_field_begin(name, type, fid)
|
165
|
-
write_type(type, value)
|
166
|
-
write_field_end
|
167
|
-
end
|
168
|
-
|
169
|
-
def write_type(type, value)
|
170
|
-
case type
|
171
|
-
when Types::BOOL
|
172
|
-
write_bool(value)
|
173
|
-
when Types::BYTE
|
174
|
-
write_byte(value)
|
175
|
-
when Types::DOUBLE
|
176
|
-
write_double(value)
|
177
|
-
when Types::I16
|
178
|
-
write_i16(value)
|
179
|
-
when Types::I32
|
180
|
-
write_i32(value)
|
181
|
-
when Types::I64
|
182
|
-
write_i64(value)
|
183
|
-
when Types::STRING
|
184
|
-
write_string(value)
|
185
|
-
when Types::STRUCT
|
186
|
-
value.write(self)
|
187
|
-
else
|
188
|
-
raise NotImplementedError
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def read_type(type)
|
193
|
-
case type
|
194
|
-
when Types::BOOL
|
195
|
-
read_bool
|
196
|
-
when Types::BYTE
|
197
|
-
read_byte
|
198
|
-
when Types::DOUBLE
|
199
|
-
read_double
|
200
|
-
when Types::I16
|
201
|
-
read_i16
|
202
|
-
when Types::I32
|
203
|
-
read_i32
|
204
|
-
when Types::I64
|
205
|
-
read_i64
|
206
|
-
when Types::STRING
|
207
|
-
read_string
|
208
|
-
else
|
209
|
-
raise NotImplementedError
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def skip(type)
|
214
|
-
case type
|
215
|
-
when Types::STOP
|
216
|
-
nil
|
217
|
-
when Types::BOOL
|
218
|
-
read_bool
|
219
|
-
when Types::BYTE
|
220
|
-
read_byte
|
221
|
-
when Types::I16
|
222
|
-
read_i16
|
223
|
-
when Types::I32
|
224
|
-
read_i32
|
225
|
-
when Types::I64
|
226
|
-
read_i64
|
227
|
-
when Types::DOUBLE
|
228
|
-
read_double
|
229
|
-
when Types::STRING
|
230
|
-
read_string
|
231
|
-
when Types::STRUCT
|
232
|
-
read_struct_begin
|
233
|
-
while true
|
234
|
-
name, type, id = read_field_begin
|
235
|
-
break if type == Types::STOP
|
236
|
-
skip(type)
|
237
|
-
read_field_end
|
238
|
-
end
|
239
|
-
read_struct_end
|
240
|
-
when Types::MAP
|
241
|
-
ktype, vtype, size = read_map_begin
|
242
|
-
size.times do
|
243
|
-
skip(ktype)
|
244
|
-
skip(vtype)
|
245
|
-
end
|
246
|
-
read_map_end
|
247
|
-
when Types::SET
|
248
|
-
etype, size = read_set_begin
|
249
|
-
size.times do
|
250
|
-
skip(etype)
|
251
|
-
end
|
252
|
-
read_set_end
|
253
|
-
when Types::LIST
|
254
|
-
etype, size = read_list_begin
|
255
|
-
size.times do
|
256
|
-
skip(etype)
|
257
|
-
end
|
258
|
-
read_list_end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
end
|
263
|
-
deprecate_class! :TProtocol => Protocol
|
264
|
-
|
265
|
-
class ProtocolFactory
|
266
|
-
def get_protocol(trans); nil; end
|
267
|
-
deprecate! :getProtocol => :get_protocol
|
268
|
-
end
|
269
|
-
deprecate_class! :TProtocolFactory => ProtocolFactory
|
270
|
-
end
|
data/lib/thrift/serializer.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Thrift
|
2
|
-
class Serializer
|
3
|
-
def initialize(protocolFactory = BinaryProtocolFactory.new)
|
4
|
-
@transport = MemoryBuffer.new
|
5
|
-
@protocol = protocolFactory.get_protocol(@transport)
|
6
|
-
end
|
7
|
-
|
8
|
-
def serialize(base)
|
9
|
-
@transport.reset_buffer
|
10
|
-
base.write(@protocol)
|
11
|
-
@transport.read(@transport.available)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class Deserializer
|
16
|
-
def initialize(protocolFactory = BinaryProtocolFactory.new)
|
17
|
-
@transport = MemoryBuffer.new
|
18
|
-
@protocol = protocolFactory.get_protocol(@transport)
|
19
|
-
end
|
20
|
-
|
21
|
-
def deserialize(base, buffer)
|
22
|
-
@transport.reset_buffer(buffer)
|
23
|
-
base.read(@protocol)
|
24
|
-
base
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/thrift/server.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
# Copyright (c) 2006- Facebook
|
2
|
-
# Distributed under the Apache Software License
|
3
|
-
#
|
4
|
-
# See accompanying file LICENSE or visit the Thrift site at:
|
5
|
-
# http://developers.facebook.com/thrift/
|
6
|
-
#
|
7
|
-
# Author: Mark Slee <mcslee@facebook.com>
|
8
|
-
#
|
9
|
-
require 'thrift/protocol'
|
10
|
-
require 'thrift/protocol/binaryprotocol'
|
11
|
-
require 'thrift/transport'
|
12
|
-
|
13
|
-
module Thrift
|
14
|
-
class Server
|
15
|
-
def initialize(processor, serverTransport, transportFactory=nil, protocolFactory=nil)
|
16
|
-
@processor = processor
|
17
|
-
@serverTransport = serverTransport
|
18
|
-
@transportFactory = transportFactory ? transportFactory : Thrift::TransportFactory.new
|
19
|
-
@protocolFactory = protocolFactory ? protocolFactory : Thrift::BinaryProtocolFactory.new
|
20
|
-
end
|
21
|
-
|
22
|
-
def serve; nil; end
|
23
|
-
end
|
24
|
-
deprecate_class! :TServer => Server
|
25
|
-
|
26
|
-
class SimpleServer < Server
|
27
|
-
def serve
|
28
|
-
begin
|
29
|
-
@serverTransport.listen
|
30
|
-
loop do
|
31
|
-
client = @serverTransport.accept
|
32
|
-
trans = @transportFactory.get_transport(client)
|
33
|
-
prot = @protocolFactory.get_protocol(trans)
|
34
|
-
begin
|
35
|
-
loop do
|
36
|
-
@processor.process(prot, prot)
|
37
|
-
end
|
38
|
-
rescue Thrift::TransportException, Thrift::ProtocolException
|
39
|
-
ensure
|
40
|
-
trans.close
|
41
|
-
end
|
42
|
-
end
|
43
|
-
ensure
|
44
|
-
@serverTransport.close
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
deprecate_class! :TSimpleServer => SimpleServer
|
49
|
-
end
|
50
|
-
|
51
|
-
# do *not* use fastthread
|
52
|
-
# it has a bug that triggers on NonblockingServer
|
53
|
-
require 'thread'
|
54
|
-
|
55
|
-
module Thrift
|
56
|
-
class ThreadedServer < Server
|
57
|
-
def serve
|
58
|
-
begin
|
59
|
-
@serverTransport.listen
|
60
|
-
loop do
|
61
|
-
client = @serverTransport.accept
|
62
|
-
trans = @transportFactory.get_transport(client)
|
63
|
-
prot = @protocolFactory.get_protocol(trans)
|
64
|
-
Thread.new(prot, trans) do |p, t|
|
65
|
-
begin
|
66
|
-
loop do
|
67
|
-
@processor.process(p, p)
|
68
|
-
end
|
69
|
-
rescue Thrift::TransportException, Thrift::ProtocolException
|
70
|
-
ensure
|
71
|
-
t.close
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
ensure
|
76
|
-
@serverTransport.close
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
deprecate_class! :TThreadedServer => ThreadedServer
|
81
|
-
|
82
|
-
class ThreadPoolServer < Server
|
83
|
-
def initialize(processor, serverTransport, transportFactory=nil, protocolFactory=nil, num=20)
|
84
|
-
super(processor, serverTransport, transportFactory, protocolFactory)
|
85
|
-
@thread_q = SizedQueue.new(num)
|
86
|
-
@exception_q = Queue.new
|
87
|
-
@running = false
|
88
|
-
end
|
89
|
-
|
90
|
-
## exceptions that happen in worker threads will be relayed here and
|
91
|
-
## must be caught. 'retry' can be used to continue. (threads will
|
92
|
-
## continue to run while the exception is being handled.)
|
93
|
-
def rescuable_serve
|
94
|
-
Thread.new { serve } unless @running
|
95
|
-
@running = true
|
96
|
-
raise @exception_q.pop
|
97
|
-
end
|
98
|
-
|
99
|
-
## exceptions that happen in worker threads simply cause that thread
|
100
|
-
## to die and another to be spawned in its place.
|
101
|
-
def serve
|
102
|
-
@serverTransport.listen
|
103
|
-
|
104
|
-
begin
|
105
|
-
loop do
|
106
|
-
@thread_q.push(:token)
|
107
|
-
Thread.new do
|
108
|
-
begin
|
109
|
-
loop do
|
110
|
-
client = @serverTransport.accept
|
111
|
-
trans = @transportFactory.get_transport(client)
|
112
|
-
prot = @protocolFactory.get_protocol(trans)
|
113
|
-
begin
|
114
|
-
loop do
|
115
|
-
@processor.process(prot, prot)
|
116
|
-
end
|
117
|
-
rescue Thrift::TransportException, Thrift::ProtocolException => e
|
118
|
-
ensure
|
119
|
-
trans.close
|
120
|
-
end
|
121
|
-
end
|
122
|
-
rescue => e
|
123
|
-
@exception_q.push(e)
|
124
|
-
ensure
|
125
|
-
@thread_q.pop # thread died!
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
ensure
|
130
|
-
@serverTransport.close
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
deprecate_class! :TThreadPoolServer => ThreadPoolServer
|
135
|
-
end
|
data/lib/thrift/thrift.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# This file kept for backwards compatability
|
2
|
-
# require File.join(File.dirname(__FILE__), '../thrift')
|
3
|
-
$:.unshift File.dirname(File.dirname(__FILE__))
|
4
|
-
require 'thrift/deprecation'
|
5
|
-
require 'thrift/types'
|
6
|
-
require 'thrift/processor'
|
7
|
-
require 'thrift/exceptions'
|
8
|
-
require 'thrift/client'
|
9
|
-
require 'thrift/struct'
|
10
|
-
begin
|
11
|
-
require "thrift_native"
|
12
|
-
rescue
|
13
|
-
puts "Could not load thrift_native libraries. Using pure ruby version."
|
14
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'thrift/transport'
|
2
|
-
|
3
|
-
require 'net/http'
|
4
|
-
require 'net/https'
|
5
|
-
require 'uri'
|
6
|
-
require 'stringio'
|
7
|
-
|
8
|
-
## Very simple HTTP client
|
9
|
-
module Thrift
|
10
|
-
class HTTPClient < Transport
|
11
|
-
def initialize(url)
|
12
|
-
@url = URI url
|
13
|
-
@outbuf = ""
|
14
|
-
end
|
15
|
-
|
16
|
-
def open?; true end
|
17
|
-
def read(sz); @inbuf.read sz end
|
18
|
-
def write(buf); @outbuf << buf end
|
19
|
-
def flush
|
20
|
-
http = Net::HTTP.new @url.host, @url.port
|
21
|
-
http.use_ssl = @url.scheme == "https"
|
22
|
-
headers = { 'Content-Type' => 'application/x-thrift' }
|
23
|
-
resp, data = http.post(@url.path, @outbuf, headers)
|
24
|
-
@inbuf = StringIO.new data
|
25
|
-
@outbuf = ""
|
26
|
-
end
|
27
|
-
end
|
28
|
-
deprecate_class! :THttpClient => HTTPClient
|
29
|
-
end
|