Class: MongoHelper::DataLocker
- Inherits:
-
Object
- Object
- MongoHelper::DataLocker
- Defined in:
- lib/ec2-consistent-backup.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(port = 27017, host = 'localhost') ⇒ DataLocker
constructor
A new instance of DataLocker.
- #lock ⇒ Object
- #locked? ⇒ Boolean
- #unlock ⇒ Object
Constructor Details
#initialize(port = 27017, host = 'localhost') ⇒ DataLocker
Returns a new instance of DataLocker.
95 96 97 98 99 100 101 102 |
# File 'lib/ec2-consistent-backup.rb', line 95 def initialize(port = 27017, host = 'localhost') @m = Mongo::Connection.new(host, port) args = @m['admin'].command({'getCmdLineOpts' => 1 })['argv'] p = args.index('--dbpath') @path = args[p+1] @path = File.readlink(@path) if File.symlink?(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
94 95 96 |
# File 'lib/ec2-consistent-backup.rb', line 94 def path @path end |
Instance Method Details
#lock ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/ec2-consistent-backup.rb', line 103 def lock return if locked? @m.lock! while !locked? do sleep(1) end raise "Not locked as asked" if !locked? end |
#locked? ⇒ Boolean
111 112 113 |
# File 'lib/ec2-consistent-backup.rb', line 111 def locked? @m.locked? end |
#unlock ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/ec2-consistent-backup.rb', line 114 def unlock return if !locked? raise "Already unlocked" if !locked? @m.unlock! while locked? do sleep(1) end end |