Class: Arrow::Session::PosixLock
- Defined in:
- lib/arrow/session/posixlock.rb
Overview
The Arrow::Session::PosixLock class, a derivative of Arrow::Session::Lock. This lock type uses the ‘posixlock’ library (raa.ruby-lang.org/project/posixlock/).
VCS Id
$Id$
Authors
-
Michael Granger <[email protected]>
Please see the file LICENSE in the top-level directory for licensing details.
Constant Summary collapse
- DefaultLockDir =
The path to the default lockdir
'/tmp'
- LockfileFormat =
The format string that will be used for the name of the lock file. The first ‘%s’ will be replaced with a sanitized version of the session id.
"arrow-session-%s.plock"
- FileMode =
The mode to open the lockfile in
File::CREAT|File::RDWR
Constants inherited from Lock
Lock::READ, Lock::UNLOCKED, Lock::WRITE
Instance Attribute Summary collapse
-
#lockDir ⇒ Object
The path to the directory where session lockfiles are kept.
Class Method Summary collapse
-
.clean(directory = DefaultLockDir, threshold = 3600) ⇒ Object
Clean the specified
directory
of lock files older thanthreshold
seconds.
Instance Method Summary collapse
-
#finish ⇒ Object
Indicate to the lock that the caller will no longer be using it, and it may free any resources it had been using.
-
#initialize(uri, id) ⇒ PosixLock
constructor
Create a new Arrow::Session::FileLock object.
Methods inherited from Lock
create, derivativeDirs, #locked?, #read_lock, #read_locked?, #read_unlock, #release_all_locks, #with_read_lock, #with_write_lock, #write_lock, #write_locked?, #write_unlock
Methods inherited from Object
deprecate_class_method, deprecate_method, inherited
Constructor Details
#initialize(uri, id) ⇒ PosixLock
Create a new Arrow::Session::FileLock object.
73 74 75 76 77 78 79 80 81 |
# File 'lib/arrow/session/posixlock.rb', line 73 def initialize( uri, id ) @lockDir = uri.path || DefaultLockDir super File.mkpath( @lockDir ) @filename = File.join( @lockDir, LockfileFormat % id.to_s.gsub(/\W/, '_') ).untaint self.log.debug "Filename is: #@filename" @lockfile = nil end |
Instance Attribute Details
#lockDir ⇒ Object
The path to the directory where session lockfiles are kept.
89 90 91 |
# File 'lib/arrow/session/posixlock.rb', line 89 def lockDir @lockDir end |
Class Method Details
.clean(directory = DefaultLockDir, threshold = 3600) ⇒ Object
Clean the specified directory
of lock files older than threshold
seconds.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/arrow/session/posixlock.rb', line 43 def self::clean( directory=DefaultLockDir, threshold=3600 ) pat = File.join( directory, LockfileFormat.gsub(/%s/, '*') ) threshold = Time.now - threshold Dir[ pat ].each do |file| if File.mtime( file ) < threshold Arrow::Logger[self].info \ "Removing stale lockfile '%s'" % file begin fh = File.open( file, FileMode ) fh.posixlock( File::LOCK_EX|File::LOCK_NB ) File.delete( file ) fh.posixlock( File::LOCK_UN ) fh.close rescue => err Arrow::Logger[self].warning \ "Could not clean up '%s': %s" % [ file, err. ] next end end end end |
Instance Method Details
#finish ⇒ Object
Indicate to the lock that the caller will no longer be using it, and it may free any resources it had been using.
94 95 96 97 |
# File 'lib/arrow/session/posixlock.rb', line 94 def finish super self.close_lock_file end |