summaryrefslogtreecommitdiff
path: root/example/ivymainloop.pl
diff options
context:
space:
mode:
authormertz2002-06-10 09:34:28 +0000
committermertz2002-06-10 09:34:28 +0000
commita6cb40bb1196aa3d4d3e48783e7ce32164ba73c9 (patch)
treee5dbfa08ed5eeda498e9cdd24c27e42eae901f73 /example/ivymainloop.pl
parent99f94550fbebf02e3e12f90b9dce39c6b0a1803d (diff)
downloadivy-perl-a6cb40bb1196aa3d4d3e48783e7ce32164ba73c9.zip
ivy-perl-a6cb40bb1196aa3d4d3e48783e7ce32164ba73c9.tar.gz
ivy-perl-a6cb40bb1196aa3d4d3e48783e7ce32164ba73c9.tar.bz2
ivy-perl-a6cb40bb1196aa3d4d3e48783e7ce32164ba73c9.tar.xz
affichage de temps de réponse complet pour une requete
ajout de l'option -delay
Diffstat (limited to 'example/ivymainloop.pl')
-rw-r--r--example/ivymainloop.pl44
1 files changed, 32 insertions, 12 deletions
diff --git a/example/ivymainloop.pl b/example/ivymainloop.pl
index 252afe8..3c21962 100644
--- a/example/ivymainloop.pl
+++ b/example/ivymainloop.pl
@@ -28,7 +28,7 @@ use Carp;
use Time::Gettimeofday; # this module is needed by Ivy!
#delay between every request asking if a distant appli is still living!
-my $delay_between_living_request = 3000;
+my $delay_between_living_request;
# a hash table containing connected applis
my %connected_applications;
@@ -37,11 +37,12 @@ my %connected_applications;
my $running = 1;
my $opt_name;
+my $opt_delay;
my $bus;
&check_options;
-
+$delay_between_living_request = (defined $opt_delay) ? $opt_delay : 3000;
my $appliname = (defined $opt_name) ? $opt_name : "IvyTestLoop";
Ivy->init (-ivyBus => (defined $bus) ? $bus : undef,
@@ -57,7 +58,7 @@ my $IvyObj = Ivy->new(-statusFunc => \&statusFunc,
$IvyObj->start;
-$IvyObj->bindRegexp( "$appliname are you here\?", [ "unused", \&yes_I_am_here] );
+$IvyObj->bindRegexp( "^$appliname are you here\?.*(\\d\\d\\.\\d+)", [ "unused", \&yes_I_am_here] );
$IvyObj->bindRegexp( "^pause", [ "unused", \&pause] );
$IvyObj->bindRegexp("^unpause", [ "unused", \&unpause] );
@@ -71,15 +72,19 @@ Ivy->mainLoop;
# The first 3 parameters are kept only for upward compatibility!
sub statusFunc {
my ($ref_ready, $ref_nonReady, $ref_hashReady, $appname, $status, $host_or_regexp) = @_;
-
if ($status eq "new") {
print "$appname connected from $host_or_regexp\n";
$connected_applications{$appname}="";
+ $IvyObj->bindRegexp("^($appname) is here.*<sent: (.*)> <replied: (.*)>", [\&reply_received]);
&ask_periodic_status($appname);
}
elsif ($status eq "died") {
print "$appname disconnected from $host_or_regexp\n";
- undef $connected_applications{$appname};
+ $IvyObj->bindRegexp("^($appname) is here.*<sent: (.*)> <replied: (.*)>"); #unbinding
+ if (defined $connected_applications{$appname}) {
+ $IvyObj->afterCancel($connected_applications{$appname});
+ undef $connected_applications{$appname};
+ }
}
elsif ($status eq 'subscribing') {
print "$appname subscribed to '$host_or_regexp'\n";
@@ -129,12 +134,22 @@ sub ask_if_living {
sub yes_I_am_here {
- my ($ivy, $appname, @param) = @_;
- my $reply = "$appliname is here and living at " . &preciseTime;
- print "$appname asked if I am here and I reply: '$reply'\n";
+ my ($ivy, $appname, $seconds) = @_;
+ my $reply = "$appliname is here and living <sent: $seconds> <replied: " . &preciseTime . ">";
+# print "$appname asked me at $seconds if I am here and I reply: '$reply'\n";
$IvyObj->sendMsgs($reply);
}
+sub reply_received {
+ my ($ivy, $appli_replying, $request_time, $reply_time) = @_;
+ my ($ss) = (localtime)[0];
+ my $preciseTime = timeofday ();
+ my ($fracSeconds) = $preciseTime =~ /(\.\d*)/ ;
+
+ my $delta = $ss + $fracSeconds - $request_time;
+ printf ("$appli_replying is living and needs %4.3fms for reply\n", $delta);
+}
+
sub check_options {
@@ -143,6 +158,7 @@ sub check_options {
GetOptions("help" => \$opt_help,
"b:s" => \$bus,
"name:s" => \$opt_name,
+ "delay:i" => \$opt_delay,
);
&usage if ($opt_help && $opt_help);
@@ -150,18 +166,22 @@ sub check_options {
sub usage {
- print "ivymainloop.pl [-h] [ -b <network>:<port> ] [ -name ivyname]\n";
+ print "ivymainloop.pl [-h] [-b <network>:<port>] [-name ivyname] [-delay n]\n";
print " ivymainloop.pl is a simple test application for the ivy-perl library\n";
print " It sends periodic request on the bus and replies on similar requests\n";
- print " Both requests and replies are precisely dated to get\n";
- print " a general idea of performance\n";
+ print " Both requests and replies are precisely dated to get a general idea\n";
+ print " of performances\n";
+ print " options are:\n";
+ print " -b <network>:<port> ivy bus port, defaulted to \$IVYBUS or 127:2010\n";
+ print " -name <agent_name> name of this agent, defaulted to 'IvyTestloop'\n";
+ print " -delay ms delay between two requests defaulted to 3000ms\n";
print " To use it as a demo : you should start at least two instances\n";
print " of this script as well as one instance of ivyprobe.pl\n";
print " in 3 xterms and have a look on messages exchanged with ivyprobe\n";
print "Example:\n";
print " > ivymainloop.pl -name foo\n";
print " > ivymainloop.pl -name bar\n";
- print " > ivyprobe.pl\n\n";
+ print " > ivyprobe.pl # to observe all exchanged messages\n\n";
exit;
}