[svn:p5ee] r6782 - p5ee/trunk/App-Context/lib/App/Context

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Fri Aug 11 10:41:56 2006
New Revision: 6782

Modified:
   p5ee/trunk/App-Context/lib/App/Context/ClusterController.pm
   p5ee/trunk/App-Context/lib/App/Context/Server.pm

Log:
improve assignment of async_events

Modified: p5ee/trunk/App-Context/lib/App/Context/ClusterController.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/ClusterController.pm	(original)
+++ p5ee/trunk/App-Context/lib/App/Context/ClusterController.pm	Fri Aug 11 10:41:56 2006
@@ -118,7 +118,7 @@
 sub assign_event_destination {
     &App::sub_entry if ($App::trace);
     my ($self, $event) = @_;
-    my $assigned = 0;
+    my $assigned = undef;
     if ($self->{num_async_events} < $self->{max_async_events}) {
         # SPA 2006-07-01: I just commented this out. I shouldn't need it.
         # $event->{destination} = $self->{host};
@@ -138,7 +138,7 @@
     &App::sub_entry if ($App::trace);
     my ($self, $event) = @_;
     
-    my $assigned = 0;
+    my $assigned = undef;
     my $nodes = $self->{nodes};
     if ($#$nodes > -1) {
         my $node_idx = $self->{node}{ALL}{last_node_idx};

Modified: p5ee/trunk/App-Context/lib/App/Context/Server.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/Server.pm	(original)
+++ p5ee/trunk/App-Context/lib/App/Context/Server.pm	Fri Aug 11 10:41:56 2006
@@ -593,15 +593,22 @@
     my $pending_async_events = $self->{pending_async_events};
     my ($async_event, $assigned);
     my $events_occurred = 0;
-    while ($#$pending_async_events > -1) {
-        $assigned = $self->assign_event_destination($pending_async_events->[0][0]);
+    my $i = 0;
+    while ($i <= $#$pending_async_events) {
+        $async_event = $pending_async_events->[$i];
+        $assigned = $self->assign_event_destination($async_event->[0]);
         if ($assigned) {
             $async_event = shift(@$pending_async_events);
             $self->send_async_event_now(@$async_event);
             $events_occurred ++;
+            splice(@$pending_async_events, $i, 1);  # remove $pending_async_events->[$i]
+            # keep $i the same
         }
-        else {
-            last;
+        elsif (! defined $assigned) {   # [undef] no servers are eligible for assignment
+            last;   # there's no sense looking at the other pending async events
+        }
+        else {      # [0] this async_event is not eligible to run
+            $i++;   # look at the next one
         }
     }
     &App::sub_exit($events_occurred) if ($App::trace);
@@ -611,7 +618,7 @@
 sub assign_event_destination {
     &App::sub_entry if ($App::trace);
     my ($self, $event) = @_;
-    my $assigned = 0;
+    my $assigned = undef;
     if ($self->{num_procs} < $self->{max_procs} &&
         (!defined $self->{max_async_events} || $self->{num_async_events} < $self->{max_async_events})) {
         $event->{destination} = $self->{host};
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.