Class: Roma::Client::ClientPool
- Inherits:
-
Object
- Object
- Roma::Client::ClientPool
- Defined in:
- lib/roma/client/client_pool.rb
Overview
Instance Attribute Summary collapse
-
#default_hash_name ⇒ Object
Returns the value of attribute default_hash_name.
-
#max_pool_size ⇒ Object
Returns the value of attribute max_pool_size.
-
#servers ⇒ Object
Returns the value of attribute servers.
-
#start_sync_routing_proc ⇒ Object
Returns the value of attribute start_sync_routing_proc.
Class Method Summary collapse
-
.client_pools ⇒ Object
get all pool.
-
.instance(type = :default) ⇒ Object
- get ClientPool instance type
-
identifier for client groups.
-
.release_all ⇒ Object
release all pool.
Instance Method Summary collapse
-
#add_plugin_module(m) ⇒ Object
add plugin module.
-
#client ⇒ Object
get RomaClient instance.
-
#clients ⇒ Object
get all clients.
-
#plugin_modules ⇒ Object
get plugin_modules.
-
#plugin_modules=(modules) ⇒ Object
set plugin modules.
-
#pool_count ⇒ Object
get pool count of clients.
-
#push_client(client) ⇒ Object
push RomaClient instance.
-
#release ⇒ Object
release all pool clients.
Instance Attribute Details
#default_hash_name ⇒ Object
Returns the value of attribute default_hash_name.
18 19 20 |
# File 'lib/roma/client/client_pool.rb', line 18 def default_hash_name @default_hash_name end |
#max_pool_size ⇒ Object
Returns the value of attribute max_pool_size.
20 21 22 |
# File 'lib/roma/client/client_pool.rb', line 20 def max_pool_size @max_pool_size end |
#servers ⇒ Object
Returns the value of attribute servers.
17 18 19 |
# File 'lib/roma/client/client_pool.rb', line 17 def servers @servers end |
#start_sync_routing_proc ⇒ Object
Returns the value of attribute start_sync_routing_proc.
19 20 21 |
# File 'lib/roma/client/client_pool.rb', line 19 def start_sync_routing_proc @start_sync_routing_proc end |
Class Method Details
.client_pools ⇒ Object
get all pool
30 31 32 |
# File 'lib/roma/client/client_pool.rb', line 30 def self.client_pools @@client_pools ||= {} end |
.instance(type = :default) ⇒ Object
get ClientPool instance
- type
-
identifier for client groups.
24 25 26 27 |
# File 'lib/roma/client/client_pool.rb', line 24 def self.instance(type = :default) client_pools[type] ||= new client_pools[type] end |
.release_all ⇒ Object
release all pool
35 36 37 38 39 |
# File 'lib/roma/client/client_pool.rb', line 35 def self.release_all client_pools.each do |k,v| v.release end end |
Instance Method Details
#add_plugin_module(m) ⇒ Object
add plugin module
96 97 98 99 |
# File 'lib/roma/client/client_pool.rb', line 96 def add_plugin_module(m) @plugin_modules ||= [] @plugin_modules.push(m) end |
#client ⇒ Object
get RomaClient instance
- type
-
RomaClient instance group.
- return
-
RomaClient instance
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/roma/client/client_pool.rb', line 45 def client c = nil if @clients.empty? c = Roma::Client::RomaClient.new(servers, plugin_modules, start_sync_routing_proc) c.default_hash_name = default_hash_name else c = @clients.pop end if block_given? begin yield c ensure push_client(c) end else return c end end |
#clients ⇒ Object
get all clients
86 87 88 |
# File 'lib/roma/client/client_pool.rb', line 86 def clients @clients end |
#plugin_modules ⇒ Object
get plugin_modules
91 92 93 |
# File 'lib/roma/client/client_pool.rb', line 91 def plugin_modules @plugin_modules end |
#plugin_modules=(modules) ⇒ Object
set plugin modules
You can set class Array.
104 105 106 |
# File 'lib/roma/client/client_pool.rb', line 104 def plugin_modules=(modules) @plugin_modules = modules end |
#pool_count ⇒ Object
get pool count of clients
68 69 70 |
# File 'lib/roma/client/client_pool.rb', line 68 def pool_count @clients.size end |
#push_client(client) ⇒ Object
push RomaClient instance
79 80 81 82 83 |
# File 'lib/roma/client/client_pool.rb', line 79 def push_client(client) if @clients.size < max_pool_size @clients.push(client) end end |
#release ⇒ Object
release all pool clients
73 74 75 76 |
# File 'lib/roma/client/client_pool.rb', line 73 def release @clients.clear true end |