From 32a06f16258c9345cafeda2cc3bd5edd666da934 Mon Sep 17 00:00:00 2001 From: etienne Date: Thu, 28 Sep 2006 14:43:31 +0000 Subject: Ajout d'un ajout d'un systeme de polling pour detecter les pbms de perfo. --- src/IvyIO.pm | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'src/IvyIO.pm') diff --git a/src/IvyIO.pm b/src/IvyIO.pm index f39d96b..cc9aa8d 100644 --- a/src/IvyIO.pm +++ b/src/IvyIO.pm @@ -2,19 +2,28 @@ package IvyIO; use strict; use Ivy; +use Carp; +use Tk; my $ivy; +my %appNameByhostAndPort = (); +my %diedApp = (); +my $pingcallback; # init an ivy bus sub init { - my ($appname, $bus, $conncb, $disconncb) = @_; + my ($appname, $bus, $conncb, $disconncb, $pingcb, $mw) = @_; Ivy->init(-loopMode => 'TK', -appName => $appname, -ivyBus => $bus, ); + + $pingcallback = $pingcb; + $ivy = Ivy->new(-statusFunc => sub {&_status($conncb, $disconncb, @_);}); $ivy->start; + $mw->repeat (3000 ,[\&sendPings]) if defined $pingcb; } # end init @@ -27,13 +36,17 @@ sub kill { sub _status { - my ($conncb, $disconncb, $ref_array_present, $ref_array_absent, - $ref_hash_present, $agent, $status, $host) = @_; - if ($status eq "new") { - &$conncb($agent, $host); - } elsif ($status eq "died") { - &$disconncb($agent, $host); - } + my ($conncb, $disconncb, $ref_array_present, $ref_array_absent, + $ref_hash_present, $agent, $status, $host) = @_; + #print "Status : @_\n"; + if ($status eq "new") { + &$conncb($agent, $host); + $appNameByhostAndPort{$host} = $agent; + delete $diedApp{$host}; + } elsif ($status eq "died") { + &$disconncb($agent, $host); + $diedApp{$host} = 1; + } } # end _status @@ -110,6 +123,7 @@ sub bind_for_clock_and_rate_event { } # end bind_for_clock_event + # execute the callback kill all sub bind_for_kill_all { my $cb = shift; @@ -121,4 +135,27 @@ sub bind_for_kill_all { } # end bind_for_clock_event +# send a ping to agent(s) +sub sendPings () +{ + my $appf; + foreach $appf (keys (%appNameByhostAndPort)) { + next if exists $diedApp{$appf}; + $ivy->ping ($appf, \&receivePongCb); + } +} # end sendPings + + +# received pong, Agent is notified with the ping/pong time value +sub receivePongCb($$) +{ + my ($time, $appf) = @_; # time = ping/pong duration in ms + + $received ++; + #printf ("DBG> :$received: $appf [$time]".$appNameByhostAndPort{$appf}."\n"); + &$pingcallback($appNameByhostAndPort{$appf}, $appf, $time); + +} # end receivePongCb + + 1; -- cgit v1.1