Class: MultiClientServer
- Inherits:
-
AbstractServer
- Object
- AbstractServer
- MultiClientServer
- Defined in:
- lib/thrift_client/multi_client_server.rb
Overview
multi client connection thrift server encapsulation
Instance Attribute Summary
Attributes inherited from AbstractServer
Instance Method Summary collapse
- #active? ⇒ Boolean
- #destroy ⇒ Object
- #get_client ⇒ Object
-
#initialize(connect_string, options = {}) ⇒ MultiClientServer
constructor
A new instance of MultiClientServer.
- #return_client(client) ⇒ Object
Methods inherited from AbstractServer
Constructor Details
#initialize(connect_string, options = {}) ⇒ MultiClientServer
Returns a new instance of MultiClientServer.
8 9 10 11 12 13 14 |
# File 'lib/thrift_client/multi_client_server.rb', line 8 def initialize(connect_string, = {}) super @pool_timeout = @options[:pool_timeout] @pool = Array.new(@options[:size]) { client = create_client } @mutex = Mutex.new @resource = ConditionVariable.new end |
Instance Method Details
#active? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/thrift_client/multi_client_server.rb', line 16 def active? active = false @pool.each {|client| active = client.open?; break if active} return active end |
#destroy ⇒ Object
22 23 24 |
# File 'lib/thrift_client/multi_client_server.rb', line 22 def destroy @pool.each {|client| client.close if client} end |
#get_client ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/thrift_client/multi_client_server.rb', line 26 def get_client client = pop if @test_on_borrow if check_client(client) return client else return nil end else client end end |
#return_client(client) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/thrift_client/multi_client_server.rb', line 39 def return_client(client) client = create_client unless client.open? @mutex.synchronize do @pool.push client @resource.broadcast end end |