mongoo 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoo/async.rb +58 -55
- data/mongoo.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/lib/mongoo/async.rb
CHANGED
@@ -34,55 +34,56 @@ module Mongo
|
|
34
34
|
#
|
35
35
|
def initialize(connection, host, port, opts={})
|
36
36
|
@connection = connection
|
37
|
-
|
38
37
|
@host, @port = host, port
|
39
38
|
|
40
|
-
# Pool size and timeout.
|
41
|
-
@size = opts[:size]
|
42
|
-
@timeout = opts[:timeout]
|
39
|
+
# # Pool size and timeout.
|
40
|
+
# @size = opts[:size] || 1
|
41
|
+
# @timeout = opts[:timeout] || 5.0
|
43
42
|
|
44
|
-
# Operations to perform on a socket
|
45
|
-
@socket_ops = Hash.new { |h, k| h[k] = [] }
|
43
|
+
# # Operations to perform on a socket
|
44
|
+
# @socket_ops = Hash.new { |h, k| h[k] = [] }
|
46
45
|
|
47
|
-
@all = []
|
48
|
-
@reserved = {} # map of in-progress connections
|
49
|
-
@available = [] # pool of free connections
|
50
|
-
@pending = [] # pending reservations (FIFO)
|
46
|
+
# @all = []
|
47
|
+
# @reserved = {} # map of in-progress connections
|
48
|
+
# @available = [] # pool of free connections
|
49
|
+
# @pending = [] # pending reservations (FIFO)
|
51
50
|
|
52
|
-
setup_pool!(host, port)
|
51
|
+
# setup_pool!(host, port)
|
53
52
|
end
|
54
53
|
|
55
54
|
def setup_pool!(host, port)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
true
|
56
|
+
# @size.times do |i|
|
57
|
+
# sock = checkout_new_socket(host, port)
|
58
|
+
# @all << sock
|
59
|
+
# @available << sock
|
60
|
+
# end
|
61
61
|
end
|
62
62
|
|
63
63
|
def close
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
@
|
73
|
-
@
|
74
|
-
@
|
75
|
-
@
|
64
|
+
true
|
65
|
+
# @all.each do |sock|
|
66
|
+
# begin
|
67
|
+
# sock.close
|
68
|
+
# rescue IOError => ex
|
69
|
+
# warn "IOError when attempting to close socket connected to #{@host}:#{@port}: #{ex.inspect}"
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
# @host = @port = nil
|
73
|
+
# @all.clear
|
74
|
+
# @reserved.clear
|
75
|
+
# @available.clear
|
76
|
+
# @pending.clear
|
76
77
|
end
|
77
78
|
|
78
79
|
# Return a socket to the pool.
|
79
80
|
def checkin(socket)
|
80
|
-
|
81
|
-
|
82
|
-
@available.push(@reserved.delete(fiber.object_id))
|
83
|
-
if pending = @pending.shift
|
84
|
-
|
85
|
-
end
|
81
|
+
socket.close
|
82
|
+
# fiber = Fiber.current
|
83
|
+
# @available.push(@reserved.delete(fiber.object_id))
|
84
|
+
# if pending = @pending.shift
|
85
|
+
# pending.resume
|
86
|
+
# end
|
86
87
|
true
|
87
88
|
end
|
88
89
|
|
@@ -91,36 +92,39 @@ module Mongo
|
|
91
92
|
# So we store the apply_authentication method, and this will be
|
92
93
|
# applied right before the next use of each socket.
|
93
94
|
def authenticate_existing
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
95
|
+
true
|
96
|
+
# @all.each do |socket|
|
97
|
+
# @socket_ops[socket] << Proc.new do
|
98
|
+
# @connection.apply_saved_authentication(:socket => socket)
|
99
|
+
# end
|
100
|
+
# end
|
99
101
|
end
|
100
102
|
|
101
103
|
# Store the logout op for each existing socket to be applied before
|
102
104
|
# the next use of each socket.
|
103
105
|
def logout_existing(db)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
106
|
+
true
|
107
|
+
# @all.each do |socket|
|
108
|
+
# @socket_ops[socket] << Proc.new do
|
109
|
+
# @connection.db(db).issue_logout(:socket => socket)
|
110
|
+
# end
|
111
|
+
# end
|
109
112
|
end
|
110
113
|
|
111
114
|
# Check out an existing socket or create a new socket if the maximum
|
112
115
|
# pool size has not been exceeded. Otherwise, wait for the next
|
113
116
|
# available socket.
|
114
117
|
def checkout
|
115
|
-
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
118
|
+
checkout_new_socket(@host, @port)
|
119
|
+
# fiber = Fiber.current
|
120
|
+
# #puts "[P: #{@pending.size}, A: #{@available.size}, ALL: #{@all.size}]"
|
121
|
+
# if socket = @available.pop
|
122
|
+
# @reserved[fiber.object_id] = socket
|
123
|
+
# socket
|
124
|
+
# else
|
125
|
+
# Fiber.yield @pending.push fiber
|
126
|
+
# checkout
|
127
|
+
# end
|
124
128
|
end
|
125
129
|
|
126
130
|
# Adds a new socket to the pool and checks it out.
|
@@ -128,8 +132,7 @@ module Mongo
|
|
128
132
|
# This method is called exclusively from #checkout;
|
129
133
|
# therefore, it runs within a mutex.
|
130
134
|
def checkout_new_socket(host, port)
|
131
|
-
return nil if @all.size >= @size
|
132
|
-
|
135
|
+
# return nil if @all.size >= @size
|
133
136
|
begin
|
134
137
|
socket = TCPSocket.new(host, port)
|
135
138
|
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
data/mongoo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoo}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Myles"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-29}
|
13
13
|
s.description = %q{Simple object mapper for MongoDB}
|
14
14
|
s.email = %q{ben.myles@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mongoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Myles
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-29 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
197
|
requirements:
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
hash:
|
200
|
+
hash: 3510321131763489211
|
201
201
|
segments:
|
202
202
|
- 0
|
203
203
|
version: "0"
|