pools 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pools/connection_pool.rb +18 -19
  2. metadata +29 -57
@@ -5,7 +5,6 @@
5
5
  require 'thread'
6
6
  require 'monitor'
7
7
  require 'set'
8
- require 'active_support/core_ext/module/synchronization'
9
8
 
10
9
  module Pools
11
10
  # Raised when a connection could not be obtained within the connection
@@ -60,6 +59,7 @@ module Pools
60
59
  # * +wait_timeout+: number of seconds to block and wait for a connection
61
60
  # before giving up and raising a timeout error (default 5 seconds).
62
61
  class ConnectionPool
62
+ include MonitorMixin
63
63
  attr_reader :options, :connections
64
64
 
65
65
  # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification
@@ -69,6 +69,7 @@ module Pools
69
69
  #
70
70
  # The default ConnectionPool maximum size is 5.
71
71
  def initialize(pooled, options)
72
+ super()
72
73
  @pooled = pooled
73
74
  @options = options
74
75
 
@@ -76,8 +77,7 @@ module Pools
76
77
  @reserved_connections = {}
77
78
 
78
79
  # The mutex used to synchronize pool access
79
- @connection_mutex = Monitor.new
80
- @queue = @connection_mutex.new_cond
80
+ @queue = self.new_cond
81
81
 
82
82
  # default 5 second timeout unless on ruby 1.9
83
83
  @timeout = options[:wait_timeout] || 5
@@ -119,27 +119,29 @@ module Pools
119
119
 
120
120
  # Returns true if a connection has already been opened.
121
121
  def connected?
122
- !@connections.empty?
122
+ synchronize { !@connections.empty? }
123
123
  end
124
124
 
125
125
  # Disconnects all connections in the pool, and clears the pool.
126
126
  def disconnect!
127
- @reserved_connections.each do |name,conn|
128
- checkin conn
129
- end
130
- @reserved_connections = {}
131
- @connections.each do |conn|
132
- @pooled.__disconnect(conn)
127
+ synchronize do
128
+ @reserved_connections = {}
129
+ @connections.each do |conn|
130
+ checkin conn
131
+ @pooled.__disconnect(conn)
132
+ end
133
+ @connections = []
133
134
  end
134
- @connections = []
135
135
  end
136
136
 
137
137
  # Verify active connections and remove and disconnect connections
138
138
  # associated with stale threads.
139
139
  def verify_active_connections! #:nodoc:
140
- clear_stale_cached_connections!
141
- @connections.each do |connection|
142
- @pooled.__disconnect(connection)
140
+ synchronize do
141
+ clear_stale_cached_connections!
142
+ @connections.each do |connection|
143
+ @pooled.__disconnect(connection)
144
+ end
143
145
  end
144
146
  end
145
147
 
@@ -173,7 +175,7 @@ module Pools
173
175
  # within the timeout period.
174
176
  def checkout
175
177
  # Checkout an available connection
176
- @connection_mutex.synchronize do
178
+ synchronize do
177
179
  loop do
178
180
  conn = if @checked_out.size < @connections.size
179
181
  checkout_existing_connection
@@ -203,15 +205,12 @@ module Pools
203
205
  # +conn+: an AbstractAdapter object, which was obtained by earlier by
204
206
  # calling +checkout+ on this pool.
205
207
  def checkin(conn)
206
- @connection_mutex.synchronize do
208
+ synchronize do
207
209
  @checked_out.delete conn
208
210
  @queue.signal
209
211
  end
210
212
  end
211
213
 
212
- synchronize :verify_active_connections!, :connected?, :disconnect!,
213
- :with => :@connection_mutex
214
-
215
214
  private
216
215
  def current_connection_id #:nodoc:
217
216
  Thread.current.object_id
metadata CHANGED
@@ -1,56 +1,38 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pools
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael Rykov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-09 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70307295130540 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 3.0.0
34
22
  - - <
35
- - !ruby/object:Gem::Version
36
- hash: 3
37
- segments:
38
- - 3
39
- - 2
40
- version: "3.2"
23
+ - !ruby/object:Gem::Version
24
+ version: '4.0'
41
25
  type: :runtime
42
- version_requirements: *id001
43
- description: |
44
- Generalized connection pooling
26
+ prerelease: false
27
+ version_requirements: *70307295130540
28
+ description: ! 'Generalized connection pooling
45
29
 
30
+ '
46
31
  email: mrykov@gmail
47
32
  executables: []
48
-
49
33
  extensions: []
50
-
51
34
  extra_rdoc_files: []
52
-
53
- files:
35
+ files:
54
36
  - README.md
55
37
  - Rakefile
56
38
  - LICENSE
@@ -65,36 +47,26 @@ files:
65
47
  - lib/redis/pooled_store.rb
66
48
  homepage: http://github.com/rykov/pools
67
49
  licenses: []
68
-
69
50
  post_install_message:
70
51
  rdoc_options: []
71
-
72
- require_paths:
52
+ require_paths:
73
53
  - lib
74
- required_ruby_version: !ruby/object:Gem::Requirement
54
+ required_ruby_version: !ruby/object:Gem::Requirement
75
55
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
61
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
92
66
  requirements: []
93
-
94
67
  rubyforge_project:
95
68
  rubygems_version: 1.8.11
96
69
  signing_key:
97
70
  specification_version: 3
98
71
  summary: Generalized connection pooling
99
72
  test_files: []
100
-