cvsuser 02/04/03 11:22:57
Modified: P5EEx/Blue/P5EEx/Blue/SharedResourceSet IPCLocker.pm
Log:
added randomizing capability for pooled resources
Revision Changes Path
1.4 +14 -1 p5ee/P5EEx/Blue/P5EEx/Blue/SharedResourceSet/IPCLocker.pm
Index: IPCLocker.pm
===================================================================
RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/SharedResourceSet/IPCLocker.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- IPCLocker.pm 22 Mar 2002 23:21:18 -0000 1.3
+++ IPCLocker.pm 3 Apr 2002 19:22:57 -0000 1.4
@@ -1,6 +1,6 @@
#############################################################################
-## $Id: IPCLocker.pm,v 1.3 2002/03/22 23:21:18 spadkins Exp $
+## $Id: IPCLocker.pm,v 1.4 2002/04/03 19:22:57 spadkins Exp $
#############################################################################
package P5EEx::Blue::SharedResourceSet::IPCLocker;
@@ -66,6 +66,7 @@
is no longer running. (Note that there is an implicit promise
that the locking process is running on the same server as the
locker daemon.)
+ random Lock a random resource from the pool when a pool is specified
=cut
@@ -133,6 +134,7 @@
sub lock {
my ($self, $arg) = @_;
my ($resource_pool, $args);
+
if (ref($arg) eq "HASH") {
$resource_pool = $arg->{resourcePool};
$args = $arg;
@@ -153,6 +155,17 @@
$resource_names = $resource_pool;
$resource_names = $self->{resourcePool}{$resource_pool}
if (defined $self->{resourcePool}{$resource_pool});
+
+ if ($self->{random} && ref($resource_names) eq "ARRAY") {
+ my (@resources, $idx, @lastresources);
+ @resources = @$resource_names;
+ $idx = $$ % ($#resources + 1);
+ if ($idx > 0) {
+ @lastresources = splice(@resources, 0, $idx);
+ push(@resources, @lastresources);
+ $resource_names = \@resources;
+ }
+ }
push(@params, "lock", $resource_names);
push(@params, "family", $self->{family}) if (defined $self->{family});