XAS::Lib::Lockmgr - The base class for locking within XAS
my $lock = 'testing'; my $lockmgr = XAS::Lib::Lockmgr->new(); $lockmgr->add(-key => $lock); if ($lockmgr->try_lock($lock)) { if ($lockmgr->lock($lock)) { .... $lockmgr->unlock($lock); } }
This module provides a general purpose locking mechanism to protect shared resources. It is rather interesting to ask a developer how they protect global shared data. They usually answer, "what do you mean by "global shared data" ?". Well, for those who understand the need, this module provides it for XAS.
This method initializes the module. It takes the following parameters:
The number of minutes before a lock is considered deadlocked. At which point an attempt will be made to remove the lock. Defaults to 5.
After a deadlock has been detected, break the lock, irregardless of who owns the lock. Defaults to false. The default will also throw an exception instead of breaking the lock.
The number of attempts to aquire the lock. Default to 30.
The number of seconds to wait between each lock attempt. Defaults to 30.
This method adds a key and defines the module that is used to manage that key. It takes the following named parameters:
The name of the key. This parameter is required.
The module that will manage the lock. The default is 'Filesystem'. Which will load XAS::Lib::Lockmgr::Filesystem.
An optional hash reference of arguments to pass to the driver.
This method will remove the key from management. This will call the destroy method of the managing module.
The name of the managed key.
Aquires a lock, returns true if successful.
Releases the lock. Returns true if successful.
Tests to see if the lock is available, returns true if the lock is available.
Kevin L. Esteb, <kevin@kesteb.us>
Copyright (c) 2012-2016 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.
To install XAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAS
CPAN shell
perl -MCPAN -e shell install XAS
For more information on module installation, please visit the detailed CPAN module installation guide.