| Class | AbstractThriftClient |
| In: |
lib/thrift_client/abstract_thrift_client.rb
lib/thrift_client/abstract_thrift_client.rb |
| Parent: | Object |
| DISCONNECT_ERRORS | = | [ IOError, Thrift::Exception, Thrift::ApplicationException, Thrift::TransportException |
| DEFAULT_WRAPPED_ERRORS | = | [ Thrift::ApplicationException, Thrift::TransportException, ] |
| DEFAULTS | = | { :protocol => Thrift::BinaryProtocol, :protocol_extra_params => [], :transport => Thrift::Socket, :transport_wrapper => Thrift::FramedTransport, :raise => true, :defaults => {}, :exception_classes => DISCONNECT_ERRORS, :retries => 0, :server_retry_period => 1, :server_max_requests => nil, :retry_overrides => {}, :wrapped_exception_classes => DEFAULT_WRAPPED_ERRORS, :timeout => 1, :timeout_overrides => {} |
| DISCONNECT_ERRORS | = | [ IOError, Thrift::Exception, Thrift::ApplicationException, Thrift::TransportException |
| DEFAULT_WRAPPED_ERRORS | = | [ Thrift::ApplicationException, Thrift::TransportException, ] |
| DEFAULTS | = | { :protocol => Thrift::BinaryProtocol, :protocol_extra_params => [], :transport => Thrift::Socket, :transport_wrapper => Thrift::FramedTransport, :raise => true, :defaults => {}, :exception_classes => DISCONNECT_ERRORS, :retries => 0, :server_retry_period => 1, :server_max_requests => nil, :retry_overrides => {}, :wrapped_exception_classes => DEFAULT_WRAPPED_ERRORS, :timeout => 1, :timeout_overrides => {} |
| client | [R] | |
| client | [R] | |
| client_class | [R] | |
| client_class | [R] | |
| client_methods | [R] | |
| client_methods | [R] | |
| current_server | [R] | |
| current_server | [R] | |
| options | [R] | |
| options | [R] | |
| server_list | [R] | |
| server_list | [R] |
# File lib/thrift_client/abstract_thrift_client.rb, line 47
47: def initialize(client_class, servers, options = {})
48: @options = DEFAULTS.merge(options)
49: @options[:server_retry_period] ||= 0
50: @client_class = client_class
51: @server_list = Array(servers).collect{|s| Server.new(s)}.sort_by { rand }
52: @current_server = @server_list.first
53:
54: @client_methods = []
55: @client_class.instance_methods.each do |method_name|
56: if method_name != 'send_message' && method_name =~ /^send_(.*)$/
57: instance_eval("def #{$1}(*args); handled_proxy(:'#{$1}', *args); end", __FILE__, __LINE__)
58: @client_methods << $1
59: end
60: end
61: @request_count = 0
62: @options[:wrapped_exception_classes].each do |exception_klass|
63: name = exception_klass.to_s.split('::').last
64: begin
65: @client_class.const_get(name)
66: rescue NameError
67: @client_class.const_set(name, Class.new(exception_klass))
68: end
69: end
70: end
# File lib/thrift_client/abstract_thrift_client.rb, line 47
47: def initialize(client_class, servers, options = {})
48: @options = DEFAULTS.merge(options)
49: @options[:server_retry_period] ||= 0
50: @client_class = client_class
51: @server_list = Array(servers).collect{|s| Server.new(s)}.sort_by { rand }
52: @current_server = @server_list.first
53:
54: @client_methods = []
55: @client_class.instance_methods.each do |method_name|
56: if method_name != 'send_message' && method_name =~ /^send_(.*)$/
57: instance_eval("def #{$1}(*args); handled_proxy(:'#{$1}', *args); end", __FILE__, __LINE__)
58: @client_methods << $1
59: end
60: end
61: @request_count = 0
62: @options[:wrapped_exception_classes].each do |exception_klass|
63: name = exception_klass.to_s.split('::').last
64: begin
65: @client_class.const_get(name)
66: rescue NameError
67: @client_class.const_set(name, Class.new(exception_klass))
68: end
69: end
70: end
Force the client to connect to the server. Not necessary to be called as the connection will be made on the first RPC method call.
# File lib/thrift_client/abstract_thrift_client.rb, line 79
79: def connect!
80: @current_server = next_live_server
81: @connection = Connection::Factory.create(@options[:transport], @options[:transport_wrapper], @current_server.connection_string, @options[:timeout])
82: @connection.connect!
83: @client = @client_class.new(@options[:protocol].new(@connection.transport, *@options[:protocol_extra_params]))
84: end
Force the client to connect to the server. Not necessary to be called as the connection will be made on the first RPC method call.
# File lib/thrift_client/abstract_thrift_client.rb, line 79
79: def connect!
80: @current_server = next_live_server
81: @connection = Connection::Factory.create(@options[:transport], @options[:transport_wrapper], @current_server.connection_string, @options[:timeout])
82: @connection.connect!
83: @client = @client_class.new(@options[:protocol].new(@connection.transport, *@options[:protocol_extra_params]))
84: end
# File lib/thrift_client/abstract_thrift_client.rb, line 86
86: def disconnect!
87: @connection.close rescue nil #TODO
88: @client = nil
89: @current_server = nil
90: @request_count = 0
91: end
# File lib/thrift_client/abstract_thrift_client.rb, line 86
86: def disconnect!
87: @connection.close rescue nil #TODO
88: @client = nil
89: @current_server = nil
90: @request_count = 0
91: end