|
DotLock - Multi-host advisory queing locking system |
DotLock - Multi-host advisory queing locking system
use DotLock;
see CONSTRUCTOR & METHODS section below
DotLock is a multipurpose queing locking system. Originally designed to take some of the pain away from locking on NFS filesystems.
This module allows script writers to develop on multiple hosts when locking between these hosts is an issue. It allows queing - scary but true. It also provides an atomic method of locking by using the ``link'' function between files.
The locking/queing method provided is purely on a file manipulation level. Also note that this object does not handle signals. If the program is interrupted, any open lockfiles will be left behind.
DotLock object.
OPTIONS are passed to the object in a hash-like fashion using keys and values. The keys are the same as the methods provided below, as shown:
$t = new DotLock( path => ``/home/ken/perl/locking/'', errmode => ``die'', timeout => 100, maxqueue => 8, retrytime => 1, domain => 'optusnet.com.au', );
So you can define all settings in one go. Besides the ``lock'' method, this is the heart and soul of the module.
The process is basically as follows:
1. A temporary lockfile is created which is associated with the script and host.
2. The lockfile directory is listed to find the highest free lock.
3. Depending on the maxqueue setting, the highest lock is obtained.
4. If for some reason the highest lock was nabbed before the current script could get it, the current script will try the next higher up lock que until it obtains a placing.
5. Once a place in the que is obtained, lock will attempt to get the next lock. It will retry every second, or the time defined in the retrytime method.
6. Unless the process has reached the point of obtaining the main lock, the script will return to step 5 to obtain the next que placing.
7. Once the main lock is obtained, the script using this object will do its business.
Set this method to the amount of time you want your script to wait for a lock. The TIMEOUT value is in seconds.
If you fail to obtain the lock with the set time, the object will return an error and react based on the errmode method set when creating the object.
For two processes to use the same lockfiles, this path must be the same in both processes.
With this method you can either set the path of the lockfiles, or return the previous path.
The default setting for errmode is ``die''.
lock method. When attempting to find a place in the que, it will look at this figure - if the figure is higher than the highest free que then DotLock will return an error.
By default, queing is turned off.
errmode is set to ``return'' this variable will be loaded with the error message.
Some other good modules for locking:
LockFile::Simple
IPC::Locker
use DotLock;
$t = new DotLock( path => ``/home/ken/perl/locking/locktest'', errmode => ``return'', timeout => 100, maxqueue => 8, retrytime => 1, domain => 'optusnet.com.au', );
$t->lock || print $t->errmsg . ``\n'';
print ``Locked\n'';
$blah = <STDIN>;
$t->unlock;
Ken Barber <ken@optusnet.com.au>
Copyright (c) 1999 Ken Barber. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
DotLock - Multi-host advisory queing locking system |