distlock 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/distlock.rb +16 -1
- data/lib/distlock/version.rb +1 -1
- data/lib/distlock/zk/exclusive_lock.rb +7 -1
- metadata +4 -4
data/lib/distlock.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require 'distlock/version'
|
2
3
|
require 'distlock/lock_error'
|
3
4
|
require 'distlock/zk/zk'
|
4
5
|
|
5
6
|
module Distlock
|
7
|
+
def Distlock.logger
|
8
|
+
@logger ||= Logger.new(STDOUT)
|
9
|
+
end
|
10
|
+
|
11
|
+
def Distlock.logger=(logger)
|
12
|
+
@logger = logger
|
13
|
+
end
|
14
|
+
|
15
|
+
# factory method for creating instances of lock managers
|
16
|
+
def Distlock.new_instance(lock_type = :zk_exclusive_lock, options={})
|
17
|
+
locker = Distlock::ZK::ExclusiveLock.new(options)
|
18
|
+
locker.logger = Distlock.logger
|
19
|
+
locker
|
20
|
+
end
|
6
21
|
end
|
7
22
|
|
8
23
|
# convenience so we can use either Distlock or DistLock
|
9
24
|
module DistLock
|
10
25
|
include Distlock
|
11
|
-
end
|
26
|
+
end
|
data/lib/distlock/version.rb
CHANGED
@@ -49,6 +49,7 @@ module Distlock
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def lock(path)
|
52
|
+
raise LockError.new("invalid lock path, must start with '/'") unless path.start_with?("/")
|
52
53
|
@owner = false
|
53
54
|
|
54
55
|
safe_create(path)
|
@@ -85,8 +86,13 @@ module Distlock
|
|
85
86
|
|
86
87
|
path = lock.split('/')[0...-1].join('/')
|
87
88
|
|
88
|
-
# TODO - pass
|
89
|
+
# TODO - pass children in as parameter?
|
89
90
|
children = zk.get_children(:path => path)[:children].sort{|a,b|a.split('-').last <=> b.split('-').last}
|
91
|
+
|
92
|
+
puts lock
|
93
|
+
puts path
|
94
|
+
puts children.inspect
|
95
|
+
|
90
96
|
lock_last = lock.split('/').last
|
91
97
|
lock_idx = children.index(lock_last)
|
92
98
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distlock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Simon Horne
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-13 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|