Class: Teapot::BaseThriftClient
- Inherits:
-
Object
- Object
- Teapot::BaseThriftClient
show all
- Defined in:
- lib/base_thrift_client.rb
Instance Method Summary
collapse
Constructor Details
#initialize(server, port, max_retries = 3) ⇒ BaseThriftClient
Returns a new instance of BaseThriftClient.
11
12
13
14
15
16
|
# File 'lib/base_thrift_client.rb', line 11
def initialize(server, port, max_retries = 3)
@server = server
@port = port
@executor = init_executor(init_protocol())
@max_retries = max_retries
end
|
Instance Method Details
#close ⇒ Object
28
29
30
|
# File 'lib/base_thrift_client.rb', line 28
def close
@transport.close
end
|
#get_executor ⇒ Object
32
33
34
|
# File 'lib/base_thrift_client.rb', line 32
def get_executor
@executor
end
|
#init_executor(protocol) ⇒ Object
24
25
26
|
# File 'lib/base_thrift_client.rb', line 24
def init_executor(protocol)
raise NotImplementedError, 'Undefined method in BaseThriftClient. init_executor() method should be implemented by the subclass.'
end
|
#init_protocol ⇒ Object
18
19
20
21
22
|
# File 'lib/base_thrift_client.rb', line 18
def init_protocol
@transport = Thrift::BufferedTransport.new(Thrift::Socket.new(@server, @port))
@transport.open
Thrift::BinaryProtocol.new(@transport)
end
|
#with_retries(&f) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/base_thrift_client.rb', line 37
def with_retries(&f)
(0..@max_retries).each do |retry_count|
begin
return f.call(get_executor)
rescue Thrift::TransportException, IOError
if retry_count == @max_retries then
raise
else
puts "For call #{caller[3][/`([^']*)'/, 1]}, attempting to reconnect to #{@server}:#{@port}..."
@executor = init_executor(init_protocol())
end
end
end
end
|