NAME
IPC::Locker - Distributed lock handler
SYNOPSIS
use IPC::Locker;
my $lock = IPC::Locker->lock(lock=>'one_per_machine',
host=>'example.std.com',
port=>223);
if ($lock->lock()) { something; }
if ($lock->locked()) { something; }
$lock->unlock();
DESCRIPTION
IPC::Locker
will query a remote server to obtain a lock. This is useful for distributed utilities which run on many machines, and cannot use file locks or other such mechanisms due to NFS or lack of common file systems.
- new ([parameter=>value ...]);
-
Create a lock structure.
- lock ([parameter=>value ...]);
-
Try to obtain the lock, return the lock object if successful, else undef.
- locked ()
-
Return true if the lock has been obtained.
- lock_name ()
-
Return the name of the lock.
- unlock ()
-
Remove the given lock. This will be called automatically when the object is destroyed.
- ping ()
-
Polls the server to see if it is up. Returns true if up, otherwise undef.
- break_lock ()
-
Remove current locker for the given lock.
- owner ([parameter=>value ...]);
-
Returns a string of who has the lock or undef if not currently . Note that this information is not atomic, and may change asyncronously; do not use this to tell if the lock will be available, to do that, try to obtain the lock and then release it if you got it.
PARAMETERS
- block
-
Boolean flag, true indicates wait for the lock when calling lock() and die if a error occurs. False indicates to just return false. Defaults to true.
- family
-
The family of transport to use, either INET or UNIX. Defaults to INET.
- host
-
The name of the host containing the lock server. It may also be a array of hostnames, where if the first one is down, subsequent ones will be tried.
- port
-
The port number (INET) or name (UNIX) of the lock server. Defaults to 'lockerd' looked up via /etc/services, else 1751.
- lock
-
The name of the lock. This may also be a reference to an array of lock names, and the first free lock will be returned.
- print_broke
-
A function to print a message when the lock is broken. The only argument is self. Defaults to print a message if verbose is set.
- print_obtained
-
A function to print a message when the lock is obtained after a delay. The only argument is self. Defaults to print a message if verbose is set.
- print_waiting
-
A function to print a message when the lock is busy and needs to be waited for. The first argument is self, second the name of the lock. Defaults to print a message if verbose is set.
- print_down
-
A function to print a message when the lock server is unavailable. The first argument is self. Defaults to a croak message.
- timeout
-
The maximum time in seconds that the lock may be held before being forced open, passed to the server when the lock is created. Thus if the requestor dies, the lock will be released after that amount of time. Zero disables the timeout. Defaults to 10 minutes.
- user
-
Name to request the lock under, defaults to host_pid_user
- autounlock
-
True to cause the server to automatically timeout a lock if the locking process has died. For the process to be detected, it must be on the same host as either the locker client (the host making the lock call), or the locker server. Defaults false.
- verbose
-
True to print messages when waiting for locks. Defaults false.
SEE ALSO
lockerd
,
DISTRIBUTION
This package is distributed via CPAN.
AUTHORS
Wilson Snyder <wsnyder@wsnyder.org>