officer 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/officer/client.rb +3 -2
- data/lib/officer/connection.rb +4 -4
- data/lib/officer/lock_store.rb +15 -9
- data/officer.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.3
|
data/lib/officer/client.rb
CHANGED
@@ -41,9 +41,10 @@ module Officer
|
|
41
41
|
def with_lock name, options={}
|
42
42
|
response = lock name, options
|
43
43
|
result = response['result']
|
44
|
+
queue = (response['queue'] || []).join ','
|
44
45
|
|
45
|
-
raise LockTimeoutError if result == 'timed_out'
|
46
|
-
raise LockQueuedMaxError if result == 'queue_maxed'
|
46
|
+
raise LockTimeoutError.new("queue=#{queue}") if result == 'timed_out'
|
47
|
+
raise LockQueuedMaxError.new("queue=#{queue}") if result == 'queue_maxed'
|
47
48
|
raise LockError unless %w(acquired already_acquired).include?(result)
|
48
49
|
|
49
50
|
begin
|
data/lib/officer/connection.rb
CHANGED
@@ -65,9 +65,9 @@ module Officer
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def timed_out name
|
68
|
+
def timed_out name, options={}
|
69
69
|
@timers.delete name
|
70
|
-
send_result 'timed_out', :name => name
|
70
|
+
send_result 'timed_out', :name => name, :queue => options[:queue]
|
71
71
|
end
|
72
72
|
|
73
73
|
def locks locks_hash
|
@@ -78,8 +78,8 @@ module Officer
|
|
78
78
|
send_result 'connections', :value => conns_hash
|
79
79
|
end
|
80
80
|
|
81
|
-
def queue_maxed name
|
82
|
-
send_result 'queue_maxed', :name => name
|
81
|
+
def queue_maxed name, options={}
|
82
|
+
send_result 'queue_maxed', :name => name, :queue => options[:queue]
|
83
83
|
end
|
84
84
|
|
85
85
|
def my_locks names
|
data/lib/officer/lock_store.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
module Officer
|
2
2
|
|
3
|
+
class LockQueue < Array
|
4
|
+
def to_host_a
|
5
|
+
map {|conn| conn.to_host_s}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
class Lock
|
4
10
|
attr_reader :name
|
5
11
|
attr_reader :queue
|
6
12
|
|
7
13
|
def initialize name
|
8
14
|
@name = name
|
9
|
-
@queue =
|
15
|
+
@queue = LockQueue.new
|
10
16
|
end
|
11
17
|
end
|
12
18
|
|
@@ -29,7 +35,7 @@ module Officer
|
|
29
35
|
|
30
36
|
l.info "locks:"
|
31
37
|
@locks.each do |name, lock|
|
32
|
-
l.info "#{name}: connections=[#{lock.queue.
|
38
|
+
l.info "#{name}: connections=[#{lock.queue.to_host_a.join(', ')}]"
|
33
39
|
end
|
34
40
|
l.info ''
|
35
41
|
|
@@ -47,11 +53,11 @@ module Officer
|
|
47
53
|
|
48
54
|
def acquire name, connection, options={}
|
49
55
|
if options[:queue_max]
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
56
|
+
lock = @locks[name]
|
57
|
+
|
58
|
+
if lock && !lock.queue.include?(connection) && lock.queue.length >= options[:queue_max]
|
59
|
+
connection.queue_maxed name, :queue => lock.queue.to_host_a
|
60
|
+
return
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
@@ -125,14 +131,14 @@ module Officer
|
|
125
131
|
lock.queue.delete connection
|
126
132
|
names.delete name
|
127
133
|
|
128
|
-
connection.timed_out name
|
134
|
+
connection.timed_out name, :queue => lock.queue.to_host_a
|
129
135
|
end
|
130
136
|
|
131
137
|
def locks connection
|
132
138
|
locks = {}
|
133
139
|
|
134
140
|
@locks.each do |name, lock|
|
135
|
-
locks[name] = lock.queue.
|
141
|
+
locks[name] = lock.queue.to_host_a
|
136
142
|
end
|
137
143
|
|
138
144
|
connection.locks locks
|
data/officer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{officer}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chad Remesch"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-19}
|
13
13
|
s.default_executable = %q{officer}
|
14
14
|
s.description = %q{Distributed lock server and client written in Ruby and EventMachine}
|
15
15
|
s.email = %q{chad@remesch.com}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: officer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Remesch
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-19 00:00:00 -05:00
|
13
13
|
default_executable: officer
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|