X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=blobdiff_plain;f=lib%2FZOOM%2FIRSpy.pm;h=3bd1aafa7391b8fd2d3e356640d53308d73343c3;hp=0fe969eafded6b1da4992e881f25becdee7cf6f2;hb=df249d500ca3cfefbc1e0fd82e3a7c1bd7f85142;hpb=393f5d3e8ba6ee9d8e15174914c060d6ff0f0c9d diff --git a/lib/ZOOM/IRSpy.pm b/lib/ZOOM/IRSpy.pm index 0fe969e..3bd1aaf 100644 --- a/lib/ZOOM/IRSpy.pm +++ b/lib/ZOOM/IRSpy.pm @@ -1,4 +1,4 @@ -# $Id: IRSpy.pm,v 1.85 2007-06-27 11:09:03 mike Exp $ +# $Id: IRSpy.pm,v 1.89 2007-09-20 10:14:37 mike Exp $ package ZOOM::IRSpy; @@ -21,7 +21,7 @@ use ZOOM::IRSpy::Utils qw(cql_target render_record irspy_record2identifier); our @ISA = qw(); -our $VERSION = '0.02'; +our $VERSION = '1.01'; our $irspy_to_zeerex_xsl = dirname(__FILE__) . '/../../xsl/irspy2zeerex.xsl'; @@ -87,6 +87,8 @@ sub new { my $this = bless { conn => $conn, query => "cql.allRecords=1", # unless overridden + modn => undef, # Filled in by restrict_modulo() + modi => undef, # Filled in by restrict_modulo() targets => undef, # Filled in later if targets() is # called; used only to keep state from # targets() until initialise() is @@ -96,6 +98,7 @@ sub new { libxml => $libxml, irspy_to_zeerex_style => $irspy_to_zeerex_style, test => undef, # Filled in by initialise() + timeout => undef, # Filled in by initialise() tests => undef, # Tree of tests to be executed activeSetSize => defined $activeSetSize ? $activeSetSize : 10, }, $class; @@ -163,6 +166,15 @@ sub _parse_target_string { } +sub restrict_modulo { + my $this = shift(); + my($n, $i) = @_; + + $this->{modn} = $n; + $this->{modi} = $i; +} + + # Records must be fetched for all records satisfying $this->{query} If # $this->{targets} is already set (i.e. a specific list of targets to # check was specified by a call to targets()), then new, empty records @@ -179,7 +191,7 @@ sub initialise { $this->{tree}->resolve(); #$this->{tree}->print(0); - my $timeout = "ZOOM::IRSpy::Test::$tname"->timeout(); + $this->{timeout} = "ZOOM::IRSpy::Test::$tname"->timeout(); my @targets; my $targets = $this->{targets}; @@ -200,16 +212,51 @@ sub initialise { my $n = $this->{activeSetSize}; $n = @targets if $n == 0 || $n > @targets; - my @connections; - foreach my $i (1..$n) { - push @connections, create ZOOM::IRSpy::Connection($this, - shift @targets, - async => 1, - timeout => $timeout); + $this->{queue} = \@targets; + $this->{connections} = []; + while (@{ $this->{connections} } < $n) { + my $conn = $this->_next_connection(); + last if !defined $conn; + push @{ $this->{connections} }, $conn; } +} - $this->{connections} = \@connections; - $this->{queue} = \@targets; + +sub _next_connection { + my $this = shift(); + + my $target; + my $n = $this->{modn}; + my $i = $this->{modi}; + if (!defined $n) { + $target = shift @{ $this->{queue} }; + return undef if !defined $target; + } else { + while (1) { + $target = shift @{ $this->{queue} }; + return undef if !defined $target; + my $h = _hash($target); + my $hmodn = $h % $n; + last if $hmodn == $i; + $this->log("irspy", "'$target' hash $h % $n = $hmodn != $i"); + } + } + + die "oops -- target is undefined" if !defined $target; + return create ZOOM::IRSpy::Connection($this, $target, async => 1, + timeout => $this->{timeout}); +} + + +sub _hash { + my($target) = @_; + + my $n = 0; + foreach my $s (split //, $target) { + $n += ord($s); + } + + return $n; } @@ -354,7 +401,7 @@ sub check { my $this = shift(); my $topname = $this->{tree}->name(); - my $timeout = "ZOOM::IRSpy::Test::$topname"->timeout(); + my $timeout = $this->{timeout}; $this->log("irspy", "beginnning with test '$topname' (timeout $timeout)"); my $nskipped = 0; @@ -386,15 +433,13 @@ sub check { $conn->log("irspy", "has no more tests: removing"); $this->_rewrite_record($conn); $conn->option(rewrote_record => 1); - if (@{ $this->{queue} } == 0) { - # Do not destroy: we need this for later sanity checks + my $newconn = $this->_next_connection(); + if (!defined $newconn) { + # Do not destroy: needed for later sanity checks splice @conn, $i0, 1; } else { $conn->destroy(); - $conn[$i0] = create - ZOOM::IRSpy::Connection($this, - shift @{ $this->{queue} }, async => 1, - timeout => $timeout); + $conn[$i0] = $newconn; $conn[$i0]->option(current_test_address => ""); $conn[$i0]->log("irspy", "entering active pool - ", scalar(@{ $this->{queue} }),