Class: ThriftHelpers::Server
Defined Under Namespace
Modules: TransportInterface
Classes: ServerMarkedDown
Instance Method Summary
collapse
#flush, #read, #read_all, #read_byte, #read_into_buffer, #timeout, #timeout=, #write
Constructor Details
#initialize(connection_string, client_class, options = {}) ⇒ Server
Returns a new instance of Server.
7
8
9
10
11
12
13
14
15
|
# File 'lib/thrift_client/server.rb', line 7
def initialize(connection_string, client_class, options = {})
@connection_string = connection_string
@client_class = client_class
@options = options
@cached = @options.has_key?(:cached_connections) ? @options[:cached_connections] : true
@marked_down_til = nil
end
|
Instance Method Details
#client ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/thrift_client/server.rb', line 48
def client
@client ||= begin
connect!
@client_class.new(
@options[:protocol].new(self, *@options[:protocol_extra_params]))
end
end
|
#close(teardown = false) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/thrift_client/server.rb', line 61
def close(teardown = false)
if teardown || !@cached
connection.close if open?
@client = nil
end
end
|
#connect! ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/thrift_client/server.rb', line 40
def connect!
return if open?
self.timeout = @options[:connect_timeout]
connection.connect!
self.timeout = @options[:timeout]
end
|
#connection ⇒ Object
34
35
36
37
38
|
# File 'lib/thrift_client/server.rb', line 34
def connection
@connection ||= Connection::Factory.create(
@options[:transport], @options[:transport_wrapper],
@connection_string, @options[:connect_timeout])
end
|
#down? ⇒ Boolean
26
27
28
|
# File 'lib/thrift_client/server.rb', line 26
def down?
@marked_down_til && @marked_down_til > Time.now
end
|
#mark_down!(til) ⇒ Object
17
18
19
20
|
# File 'lib/thrift_client/server.rb', line 17
def mark_down!(til)
close(true)
@marked_down_til = Time.now + til
end
|
#open? ⇒ Boolean
57
58
59
|
# File 'lib/thrift_client/server.rb', line 57
def open?
connection.open?
end
|
#to_s ⇒ Object
30
31
32
|
# File 'lib/thrift_client/server.rb', line 30
def to_s
@connection_string
end
|
#transport ⇒ Object
68
69
70
|
# File 'lib/thrift_client/server.rb', line 68
def transport
connection.transport
end
|
#up? ⇒ Boolean
22
23
24
|
# File 'lib/thrift_client/server.rb', line 22
def up?
!down?
end
|