diff options
author | etienne | 2006-09-28 14:43:31 +0000 |
---|---|---|
committer | etienne | 2006-09-28 14:43:31 +0000 |
commit | 32a06f16258c9345cafeda2cc3bd5edd666da934 (patch) | |
tree | 7378707d4e8de77169b631d50485bdb79abeca7f /src/IvyIO.pm | |
parent | 9488f7ce932b85f806987a7b7d8988b8b4b253d7 (diff) | |
download | ivycontrolpanel-32a06f16258c9345cafeda2cc3bd5edd666da934.zip ivycontrolpanel-32a06f16258c9345cafeda2cc3bd5edd666da934.tar.gz ivycontrolpanel-32a06f16258c9345cafeda2cc3bd5edd666da934.tar.bz2 ivycontrolpanel-32a06f16258c9345cafeda2cc3bd5edd666da934.tar.xz |
Ajout d'un ajout d'un systeme de polling pour detecter les pbms de perfo.
Diffstat (limited to 'src/IvyIO.pm')
-rw-r--r-- | src/IvyIO.pm | 53 |
1 files changed, 45 insertions, 8 deletions
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; |