garru-ruby_scribe_client 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/LICENSE +0 -0
- data/Manifest +39 -0
- data/README +0 -0
- data/Rakefile +8 -0
- data/etc/scribe_cat.rb +23 -0
- data/lib/ruby_scribe_client/FacebookService.rb +685 -0
- data/lib/ruby_scribe_client/fb303_types.rb +16 -0
- data/lib/ruby_scribe_client/reflection_limited_types.rb +148 -0
- data/lib/ruby_scribe_client/scribe.rb +82 -0
- data/lib/ruby_scribe_client/scribe_types.rb +32 -0
- data/lib/ruby_scribe_client.rb +33 -0
- data/ruby_scribe_client.gemspec +31 -0
- data/vendor/thrift/client.rb +44 -0
- data/vendor/thrift/deprecation.rb +155 -0
- data/vendor/thrift/exceptions.rb +65 -0
- data/vendor/thrift/processor.rb +39 -0
- data/vendor/thrift/protocol/binaryprotocol.rb +213 -0
- data/vendor/thrift/protocol/binaryprotocolaccelerated.rb +19 -0
- data/vendor/thrift/protocol/tbinaryprotocol.rb +2 -0
- data/vendor/thrift/protocol/tprotocol.rb +2 -0
- data/vendor/thrift/protocol.rb +270 -0
- data/vendor/thrift/serializer.rb +27 -0
- data/vendor/thrift/server/httpserver.rb +44 -0
- data/vendor/thrift/server/nonblockingserver.rb +278 -0
- data/vendor/thrift/server/thttpserver.rb +2 -0
- data/vendor/thrift/server/tserver.rb +2 -0
- data/vendor/thrift/server.rb +135 -0
- data/vendor/thrift/struct.rb +272 -0
- data/vendor/thrift/thrift.rb +14 -0
- data/vendor/thrift/transport/httpclient.rb +29 -0
- data/vendor/thrift/transport/socket.rb +153 -0
- data/vendor/thrift/transport/thttpclient.rb +2 -0
- data/vendor/thrift/transport/tsocket.rb +2 -0
- data/vendor/thrift/transport/ttransport.rb +2 -0
- data/vendor/thrift/transport/unixsocket.rb +58 -0
- data/vendor/thrift/transport.rb +319 -0
- data/vendor/thrift/types.rb +83 -0
- data/vendor/thrift.rb +28 -0
- metadata +104 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
module TTypeTag
|
8
|
+
T_VOID = 1
|
9
|
+
T_BOOL = 2
|
10
|
+
T_BYTE = 3
|
11
|
+
T_I16 = 6
|
12
|
+
T_I32 = 8
|
13
|
+
T_I64 = 10
|
14
|
+
T_DOUBLE = 4
|
15
|
+
T_STRING = 11
|
16
|
+
T_STRUCT = 12
|
17
|
+
T_MAP = 13
|
18
|
+
T_SET = 14
|
19
|
+
T_LIST = 15
|
20
|
+
T_ENUM = 101
|
21
|
+
T_NOT_REFLECTED = 102
|
22
|
+
VALID_VALUES = Set.new([T_VOID, T_BOOL, T_BYTE, T_I16, T_I32, T_I64, T_DOUBLE, T_STRING, T_STRUCT, T_MAP, T_SET, T_LIST, T_ENUM, T_NOT_REFLECTED]).freeze
|
23
|
+
end
|
24
|
+
|
25
|
+
class SimpleType
|
26
|
+
include ::Thrift::Struct
|
27
|
+
TTYPE = 1
|
28
|
+
NAME = 2
|
29
|
+
|
30
|
+
Thrift::Struct.field_accessor self, :ttype, :name
|
31
|
+
FIELDS = {
|
32
|
+
TTYPE => {:type => Thrift::Types::I32, :name => 'ttype'},
|
33
|
+
NAME => {:type => Thrift::Types::STRING, :name => 'name'}
|
34
|
+
}
|
35
|
+
|
36
|
+
def struct_fields; FIELDS; end
|
37
|
+
|
38
|
+
def validate
|
39
|
+
unless @ttype.nil? || TTypeTag::VALID_VALUES.include?(@ttype)
|
40
|
+
raise Thrift::ProtocolException.new(Thrift::ProtocolException::UNKNOWN, 'Invalid value of field ttype!')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class ContainerType
|
47
|
+
include ::Thrift::Struct
|
48
|
+
TTYPE = 1
|
49
|
+
SUBTYPE1 = 2
|
50
|
+
SUBTYPE2 = 3
|
51
|
+
|
52
|
+
Thrift::Struct.field_accessor self, :ttype, :subtype1, :subtype2
|
53
|
+
FIELDS = {
|
54
|
+
TTYPE => {:type => Thrift::Types::I32, :name => 'ttype'},
|
55
|
+
SUBTYPE1 => {:type => Thrift::Types::STRUCT, :name => 'subtype1', :class => SimpleType},
|
56
|
+
SUBTYPE2 => {:type => Thrift::Types::STRUCT, :name => 'subtype2', :class => SimpleType, :optional => true}
|
57
|
+
}
|
58
|
+
|
59
|
+
def struct_fields; FIELDS; end
|
60
|
+
|
61
|
+
def validate
|
62
|
+
unless @ttype.nil? || TTypeTag::VALID_VALUES.include?(@ttype)
|
63
|
+
raise Thrift::ProtocolException.new(Thrift::ProtocolException::UNKNOWN, 'Invalid value of field ttype!')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
class ThriftType
|
70
|
+
include ::Thrift::Struct
|
71
|
+
IS_CONTAINER = 1
|
72
|
+
SIMPLE_TYPE = 2
|
73
|
+
CONTAINER_TYPE = 3
|
74
|
+
|
75
|
+
Thrift::Struct.field_accessor self, :is_container, :simple_type, :container_type
|
76
|
+
FIELDS = {
|
77
|
+
IS_CONTAINER => {:type => Thrift::Types::BOOL, :name => 'is_container'},
|
78
|
+
SIMPLE_TYPE => {:type => Thrift::Types::STRUCT, :name => 'simple_type', :class => SimpleType, :optional => true},
|
79
|
+
CONTAINER_TYPE => {:type => Thrift::Types::STRUCT, :name => 'container_type', :class => ContainerType, :optional => true}
|
80
|
+
}
|
81
|
+
|
82
|
+
def struct_fields; FIELDS; end
|
83
|
+
|
84
|
+
def validate
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
class Argument
|
90
|
+
include ::Thrift::Struct
|
91
|
+
KEY = 1
|
92
|
+
NAME = 2
|
93
|
+
TYPE = 3
|
94
|
+
|
95
|
+
Thrift::Struct.field_accessor self, :key, :name, :type
|
96
|
+
FIELDS = {
|
97
|
+
KEY => {:type => Thrift::Types::I16, :name => 'key'},
|
98
|
+
NAME => {:type => Thrift::Types::STRING, :name => 'name'},
|
99
|
+
TYPE => {:type => Thrift::Types::STRUCT, :name => 'type', :class => ThriftType}
|
100
|
+
}
|
101
|
+
|
102
|
+
def struct_fields; FIELDS; end
|
103
|
+
|
104
|
+
def validate
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
class Method
|
110
|
+
include ::Thrift::Struct
|
111
|
+
NAME = 1
|
112
|
+
RETURN_TYPE = 2
|
113
|
+
ARGUMENTS = 3
|
114
|
+
|
115
|
+
Thrift::Struct.field_accessor self, :name, :return_type, :arguments
|
116
|
+
FIELDS = {
|
117
|
+
NAME => {:type => Thrift::Types::STRING, :name => 'name'},
|
118
|
+
RETURN_TYPE => {:type => Thrift::Types::STRUCT, :name => 'return_type', :class => ThriftType},
|
119
|
+
ARGUMENTS => {:type => Thrift::Types::LIST, :name => 'arguments', :element => {:type => Thrift::Types::STRUCT, :class => Argument}}
|
120
|
+
}
|
121
|
+
|
122
|
+
def struct_fields; FIELDS; end
|
123
|
+
|
124
|
+
def validate
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
class Service
|
130
|
+
include ::Thrift::Struct
|
131
|
+
NAME = 1
|
132
|
+
METHODS = 2
|
133
|
+
FULLY_REFLECTED = 3
|
134
|
+
|
135
|
+
Thrift::Struct.field_accessor self, :name, :methods, :fully_reflected
|
136
|
+
FIELDS = {
|
137
|
+
NAME => {:type => Thrift::Types::STRING, :name => 'name'},
|
138
|
+
METHODS => {:type => Thrift::Types::LIST, :name => 'methods', :element => {:type => Thrift::Types::STRUCT, :class => Method}},
|
139
|
+
FULLY_REFLECTED => {:type => Thrift::Types::BOOL, :name => 'fully_reflected'}
|
140
|
+
}
|
141
|
+
|
142
|
+
def struct_fields; FIELDS; end
|
143
|
+
|
144
|
+
def validate
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require File.join([File.dirname(__FILE__), '..', '..', 'vendor','thrift'])
|
8
|
+
require File.join([File.dirname(__FILE__) ,'FacebookService'])
|
9
|
+
require File.join([File.dirname(__FILE__), 'scribe_types'])
|
10
|
+
|
11
|
+
module Scribe
|
12
|
+
class Client < FacebookService::Client
|
13
|
+
include ::Thrift::Client
|
14
|
+
|
15
|
+
def Log(messages)
|
16
|
+
send_Log(messages)
|
17
|
+
return recv_Log()
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_Log(messages)
|
21
|
+
send_message('Log', Log_args, :messages => messages)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recv_Log()
|
25
|
+
result = receive_message(Log_result)
|
26
|
+
return result.success unless result.success.nil?
|
27
|
+
raise Thrift::ApplicationException.new(Thrift::ApplicationException::MISSING_RESULT, 'Log failed: unknown result')
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class Processor < FacebookService::Processor
|
33
|
+
include ::Thrift::Processor
|
34
|
+
|
35
|
+
def process_Log(seqid, iprot, oprot)
|
36
|
+
args = read_args(iprot, Log_args)
|
37
|
+
result = Log_result.new()
|
38
|
+
result.success = @handler.Log(args.messages)
|
39
|
+
write_result(result, oprot, 'Log', seqid)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
45
|
+
|
46
|
+
class Log_args
|
47
|
+
include ::Thrift::Struct
|
48
|
+
MESSAGES = 1
|
49
|
+
|
50
|
+
Thrift::Struct.field_accessor self, :messages
|
51
|
+
FIELDS = {
|
52
|
+
MESSAGES => {:type => Thrift::Types::LIST, :name => 'messages', :element => {:type => Thrift::Types::STRUCT, :class => LogEntry}}
|
53
|
+
}
|
54
|
+
|
55
|
+
def struct_fields; FIELDS; end
|
56
|
+
|
57
|
+
def validate
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
class Log_result
|
63
|
+
include ::Thrift::Struct
|
64
|
+
SUCCESS = 0
|
65
|
+
|
66
|
+
Thrift::Struct.field_accessor self, :success
|
67
|
+
FIELDS = {
|
68
|
+
SUCCESS => {:type => Thrift::Types::I32, :name => 'success'}
|
69
|
+
}
|
70
|
+
|
71
|
+
def struct_fields; FIELDS; end
|
72
|
+
|
73
|
+
def validate
|
74
|
+
unless @success.nil? || ResultCode::VALID_VALUES.include?(@success)
|
75
|
+
raise Thrift::ProtocolException.new(Thrift::ProtocolException::UNKNOWN, 'Invalid value of field success!')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
require File.dirname(__FILE__) + '/fb303_types'
|
7
|
+
|
8
|
+
|
9
|
+
module ResultCode
|
10
|
+
OK = 0
|
11
|
+
TRY_LATER = 1
|
12
|
+
VALID_VALUES = Set.new([OK, TRY_LATER]).freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
class LogEntry
|
16
|
+
include ::Thrift::Struct
|
17
|
+
CATEGORY = 1
|
18
|
+
MESSAGE = 2
|
19
|
+
|
20
|
+
Thrift::Struct.field_accessor self, :category, :message
|
21
|
+
FIELDS = {
|
22
|
+
CATEGORY => {:type => Thrift::Types::STRING, :name => 'category'},
|
23
|
+
MESSAGE => {:type => Thrift::Types::STRING, :name => 'message'}
|
24
|
+
}
|
25
|
+
|
26
|
+
def struct_fields; FIELDS; end
|
27
|
+
|
28
|
+
def validate
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#convenience wrapper for scribe
|
2
|
+
require File.join([File.dirname(__FILE__), 'ruby_scribe_client', 'scribe'])
|
3
|
+
|
4
|
+
class ScribeLogger
|
5
|
+
attr_accessor :host, :port, :namespace
|
6
|
+
|
7
|
+
def initialize(host, port, namespace = nil)
|
8
|
+
@transport = Thrift::FramedTransport.new(Thrift::Socket.new(host, port))
|
9
|
+
@protocol = Thrift::BinaryProtocol.new(@transport, false, false)
|
10
|
+
@client = Scribe::Client.new(@protocol)
|
11
|
+
@namespace = namespace
|
12
|
+
end
|
13
|
+
|
14
|
+
def []=(category, message)
|
15
|
+
log(category, message)
|
16
|
+
end
|
17
|
+
|
18
|
+
def log(category, message)
|
19
|
+
begin
|
20
|
+
log_entry = LogEntry.new({:category => category_key(category), :message => message})
|
21
|
+
@transport.open()
|
22
|
+
result = @client.Log([log_entry])
|
23
|
+
@transport.close()
|
24
|
+
return result
|
25
|
+
rescue Thrift::Exception => tx
|
26
|
+
print 'Thrift::Exception: ', tx.message, "\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def category_key(category)
|
31
|
+
[@namespace, category].compact.join('_')
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{ruby_scribe_client}
|
5
|
+
s.version = "0.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Gary Tsang"]
|
9
|
+
s.date = %q{2009-03-12}
|
10
|
+
s.description = %q{Ruby Scribe Client. Package and Wrapper for generated ruby interfaces}
|
11
|
+
s.email = %q{}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/ruby_scribe_client/FacebookService.rb", "lib/ruby_scribe_client/fb303_types.rb", "lib/ruby_scribe_client/reflection_limited_types.rb", "lib/ruby_scribe_client/scribe.rb", "lib/ruby_scribe_client/scribe_types.rb", "lib/ruby_scribe_client.rb", "LICENSE", "README"]
|
13
|
+
s.files = ["CHANGELOG", "etc/scribe_cat.rb", "lib/ruby_scribe_client/FacebookService.rb", "lib/ruby_scribe_client/fb303_types.rb", "lib/ruby_scribe_client/reflection_limited_types.rb", "lib/ruby_scribe_client/scribe.rb", "lib/ruby_scribe_client/scribe_types.rb", "lib/ruby_scribe_client.rb", "LICENSE", "Manifest", "Rakefile", "README", "ruby_scribe_client.gemspec", "vendor/thrift/client.rb", "vendor/thrift/deprecation.rb", "vendor/thrift/exceptions.rb", "vendor/thrift/processor.rb", "vendor/thrift/protocol/binaryprotocol.rb", "vendor/thrift/protocol/binaryprotocolaccelerated.rb", "vendor/thrift/protocol/tbinaryprotocol.rb", "vendor/thrift/protocol/tprotocol.rb", "vendor/thrift/protocol.rb", "vendor/thrift/serializer.rb", "vendor/thrift/server/httpserver.rb", "vendor/thrift/server/nonblockingserver.rb", "vendor/thrift/server/thttpserver.rb", "vendor/thrift/server/tserver.rb", "vendor/thrift/server.rb", "vendor/thrift/struct.rb", "vendor/thrift/thrift.rb", "vendor/thrift/transport/httpclient.rb", "vendor/thrift/transport/socket.rb", "vendor/thrift/transport/thttpclient.rb", "vendor/thrift/transport/tsocket.rb", "vendor/thrift/transport/ttransport.rb", "vendor/thrift/transport/unixsocket.rb", "vendor/thrift/transport.rb", "vendor/thrift/types.rb", "vendor/thrift.rb"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/garru/ruby_scribe_client}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruby_scribe_client", "--main", "README"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{ruby_scribe_client}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Ruby Scribe Client. Package and Wrapper for generated ruby interfaces}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 2
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Thrift
|
2
|
+
module Client
|
3
|
+
def initialize(iprot, oprot=nil)
|
4
|
+
@iprot = iprot
|
5
|
+
@oprot = oprot || iprot
|
6
|
+
@seqid = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def send_message(name, args_class, args = {})
|
10
|
+
@oprot.write_message_begin(name, MessageTypes::CALL, @seqid)
|
11
|
+
data = args_class.new
|
12
|
+
args.each do |k, v|
|
13
|
+
data.send("#{k.to_s}=", v)
|
14
|
+
end
|
15
|
+
begin
|
16
|
+
data.write(@oprot)
|
17
|
+
rescue StandardError => e
|
18
|
+
@oprot.trans.close
|
19
|
+
raise e
|
20
|
+
end
|
21
|
+
@oprot.write_message_end
|
22
|
+
@oprot.trans.flush
|
23
|
+
end
|
24
|
+
|
25
|
+
def receive_message(result_klass)
|
26
|
+
fname, mtype, rseqid = @iprot.read_message_begin
|
27
|
+
handle_exception(mtype)
|
28
|
+
result = result_klass.new
|
29
|
+
result.read(@iprot)
|
30
|
+
@iprot.read_message_end
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_exception(mtype)
|
35
|
+
if mtype == MessageTypes::EXCEPTION
|
36
|
+
x = ApplicationException.new
|
37
|
+
x.read(@iprot)
|
38
|
+
@iprot.read_message_end
|
39
|
+
raise x
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
deprecate_module! :ThriftClient => Client
|
44
|
+
end
|
@@ -0,0 +1,155 @@
|
|
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
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Thrift
|
2
|
+
class Exception < StandardError
|
3
|
+
def initialize(message)
|
4
|
+
super
|
5
|
+
@message = message
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :message
|
9
|
+
end
|
10
|
+
deprecate_class! :TException => Exception
|
11
|
+
|
12
|
+
class ApplicationException < Exception
|
13
|
+
|
14
|
+
UNKNOWN = 0
|
15
|
+
UNKNOWN_METHOD = 1
|
16
|
+
INVALID_MESSAGE_TYPE = 2
|
17
|
+
WRONG_METHOD_NAME = 3
|
18
|
+
BAD_SEQUENCE_ID = 4
|
19
|
+
MISSING_RESULT = 5
|
20
|
+
|
21
|
+
attr_reader :type
|
22
|
+
|
23
|
+
def initialize(type=UNKNOWN, message=nil)
|
24
|
+
super(message)
|
25
|
+
@type = type
|
26
|
+
end
|
27
|
+
|
28
|
+
def read(iprot)
|
29
|
+
iprot.read_struct_begin
|
30
|
+
while true
|
31
|
+
fname, ftype, fid = iprot.read_field_begin
|
32
|
+
if ftype == Types::STOP
|
33
|
+
break
|
34
|
+
end
|
35
|
+
if fid == 1 and ftype == Types::STRING
|
36
|
+
@message = iprot.read_string
|
37
|
+
elsif fid == 2 and ftype == Types::I32
|
38
|
+
@type = iprot.read_i32
|
39
|
+
else
|
40
|
+
iprot.skip(ftype)
|
41
|
+
end
|
42
|
+
iprot.read_field_end
|
43
|
+
end
|
44
|
+
iprot.read_struct_end
|
45
|
+
end
|
46
|
+
|
47
|
+
def write(oprot)
|
48
|
+
oprot.write_struct_begin('Thrift::ApplicationException')
|
49
|
+
unless @message.nil?
|
50
|
+
oprot.write_field_begin('message', Types::STRING, 1)
|
51
|
+
oprot.write_string(@message)
|
52
|
+
oprot.write_field_end
|
53
|
+
end
|
54
|
+
unless @type.nil?
|
55
|
+
oprot.write_field_begin('type', Types::I32, 2)
|
56
|
+
oprot.write_i32(@type)
|
57
|
+
oprot.write_field_end
|
58
|
+
end
|
59
|
+
oprot.write_field_stop
|
60
|
+
oprot.write_struct_end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
deprecate_class! :TApplicationException => ApplicationException
|
65
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Thrift
|
2
|
+
module Processor
|
3
|
+
def initialize(handler)
|
4
|
+
@handler = handler
|
5
|
+
end
|
6
|
+
|
7
|
+
def process(iprot, oprot)
|
8
|
+
name, type, seqid = iprot.read_message_begin
|
9
|
+
if respond_to?("process_#{name}")
|
10
|
+
send("process_#{name}", seqid, iprot, oprot)
|
11
|
+
true
|
12
|
+
else
|
13
|
+
iprot.skip(Types::STRUCT)
|
14
|
+
iprot.read_message_end
|
15
|
+
x = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, 'Unknown function '+name)
|
16
|
+
oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
|
17
|
+
x.write(oprot)
|
18
|
+
oprot.write_message_end
|
19
|
+
oprot.trans.flush
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_args(iprot, args_class)
|
25
|
+
args = args_class.new
|
26
|
+
args.read(iprot)
|
27
|
+
iprot.read_message_end
|
28
|
+
args
|
29
|
+
end
|
30
|
+
|
31
|
+
def write_result(result, oprot, name, seqid)
|
32
|
+
oprot.write_message_begin(name, MessageTypes::REPLY, seqid)
|
33
|
+
result.write(oprot)
|
34
|
+
oprot.write_message_end
|
35
|
+
oprot.trans.flush
|
36
|
+
end
|
37
|
+
end
|
38
|
+
deprecate_module! :TProcessor => Processor
|
39
|
+
end
|