Class: Roma::Client::ClientPool

Inherits:
Object
  • Object
show all
Defined in:
lib/roma/client/client_pool.rb

Overview

RomaClient Pool class

This class is implemented as Singleton. You can get RomaClient as follows.

client = Roma::Client::ClientPool.instance.client

You can change pool size of RomaClient to call “max_pool_size=” method . Default max pool size is 1.

Constant Summary collapse

@@client_pools =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_hash_nameObject

Returns the value of attribute default_hash_name.



19
20
21
# File 'lib/roma/client/client_pool.rb', line 19

def default_hash_name
  @default_hash_name
end

#serversObject

Returns the value of attribute servers.



18
19
20
# File 'lib/roma/client/client_pool.rb', line 18

def servers
  @servers
end

#start_sync_routing_procObject

Returns the value of attribute start_sync_routing_proc.



20
21
22
# File 'lib/roma/client/client_pool.rb', line 20

def start_sync_routing_proc
  @start_sync_routing_proc
end

Class Method Details

.client_poolsObject

get all pool



32
33
34
# File 'lib/roma/client/client_pool.rb', line 32

def self.client_pools
  @@client_pools
end

.instance(type = :default) ⇒ Object

get ClientPool instance

type

identifier for client groups.



26
27
28
29
# File 'lib/roma/client/client_pool.rb', line 26

def self.instance(type = :default)
  @@client_pools[type] ||= new
  @@client_pools[type]
end

.release_allObject

release all pool



37
38
39
40
41
# File 'lib/roma/client/client_pool.rb', line 37

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



107
108
109
110
# File 'lib/roma/client/client_pool.rb', line 107

def add_plugin_module(m)
  @plugin_modules ||= []
  @plugin_modules.push(m)
end

#clientObject

get RomaClient instance

type

RomaClient instance group.

return

RomaClient instance



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/roma/client/client_pool.rb', line 47

def client
  c = nil
  if @clients.empty?
    client = Roma::Client::RomaClient.new(servers,
                                          plugin_modules,
                                          start_sync_routing_proc)
    client.default_hash_name = default_hash_name
    c = client
  else
    c = @clients.pop
  end

  return c unless block_given?

  begin
    yield c
  ensure
    push_client(c)
  end
end

#clientsObject

get all clients



97
98
99
# File 'lib/roma/client/client_pool.rb', line 97

def clients
  @clients
end

#max_pool_sizeObject

get max pool size



87
88
89
# File 'lib/roma/client/client_pool.rb', line 87

def max_pool_size
  @max_pool_size
end

#max_pool_size=(count) ⇒ Object

set max_pool_size



92
93
94
# File 'lib/roma/client/client_pool.rb', line 92

def max_pool_size=(count)
  @max_pool_size = count
end

#plugin_modulesObject

get plugin_modules



102
103
104
# File 'lib/roma/client/client_pool.rb', line 102

def plugin_modules
  @plugin_modules
end

#plugin_modules=(modules) ⇒ Object

set plugin modules

You can set class Array.



115
116
117
# File 'lib/roma/client/client_pool.rb', line 115

def plugin_modules=(modules)
  @plugin_modules = modules
end

#pool_countObject

get pool count of clients



69
70
71
# File 'lib/roma/client/client_pool.rb', line 69

def pool_count
  @clients.size
end

#push_client(client) ⇒ Object

push RomaClient instance



80
81
82
83
84
# File 'lib/roma/client/client_pool.rb', line 80

def push_client(client)
  if @clients.size < max_pool_size
    @clients.push(client)
  end
end

#releaseObject

release all pool clients



74
75
76
77
# File 'lib/roma/client/client_pool.rb', line 74

def release
  @clients.clear
  true
end