blob: 280997e32a616b384d4a99fe92dc5b6d58a7c0f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
class Bundler::Persistent::Net::HTTP::Persistent::TimedStackMulti < Bundler::ConnectionPool::TimedStack # :nodoc:
def initialize(size = 0, &block)
super
@enqueued = 0
@ques = Hash.new { |h, k| h[k] = [] }
@lru = {}
@key = :"connection_args-#{object_id}"
end
def empty?
(@created - @enqueued) >= @max
end
def length
@max - @created + @enqueued
end
private
def connection_stored? options = {} # :nodoc:
!@ques[options[:connection_args]].empty?
end
def fetch_connection options = {} # :nodoc:
connection_args = options[:connection_args]
@enqueued -= 1
lru_update connection_args
@ques[connection_args].pop
end
def lru_update connection_args # :nodoc:
@lru.delete connection_args
@lru[connection_args] = true
end
def shutdown_connections # :nodoc:
@ques.each_key do |key|
super connection_args: key
end
end
def store_connection obj, options = {} # :nodoc:
@ques[options[:connection_args]].push obj
@enqueued += 1
end
def try_create options = {} # :nodoc:
connection_args = options[:connection_args]
if @created >= @max && @enqueued >= 1
oldest, = @lru.first
@lru.delete oldest
@ques[oldest].pop
@created -= 1
end
if @created < @max
@created += 1
lru_update connection_args
return @create_block.call(connection_args)
end
end
end
|