Module: OverSIP::Modules::Mysql

Extended by:
Logger
Defined in:
lib/oversip-mod-mysql.rb,
lib/oversip-mod-mysql/version.rb

Defined Under Namespace

Modules: Version Classes: Pool

Constant Summary collapse

DEFAULT_POOL_SIZE =
10
VERSION =
[Version::MAJOR, Version::MINOR, Version::TINY].join(".")

Class Method Summary collapse

Class Method Details

.add_pool(options) ⇒ Object

Raises:

  • (::ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oversip-mod-mysql.rb', line 19

def self.add_pool options
  raise ::ArgumentError, "`options' must be a Hash"  unless options.is_a? ::Hash

  # Avoid the hash to be modified internally.
  options = options.clone
  # Delete options not existing in mysql2.
  pool_name = options.delete(:pool_name)
  pool_size = options.delete(:pool_size) || DEFAULT_POOL_SIZE

  raise ::ArgumentError, "`options[:pool_name]' must be a Symbol"  unless pool_name.is_a? ::Symbol
  raise ::ArgumentError, "`options[:pool_size]' must be a positive Fixnum"  unless pool_size.is_a? ::Fixnum and pool_size > 0

  block = ::Proc.new  if block_given?

  ::OverSIP::SystemCallbacks.on_started do
    log_info "Adding MySQL connection pool (name: #{pool_name.inspect}, size: #{pool_size})..."
    @pools[pool_name] = Pool.new pool_size, options, block
  end
end

.pool(pool_name) ⇒ Object Also known as: get_pool

def self.add_pool

Raises:

  • (::ArgumentError)


39
40
41
42
43
# File 'lib/oversip-mod-mysql.rb', line 39

def self.pool pool_name
  pool = @pools[pool_name]
  raise ::ArgumentError, "no pool with `name' #{pool_name.inspect}"  unless pool
  pool
end