Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

multest.cpp

Go to the documentation of this file.
00001 
00005 /* --------------------------------------------------------------
00006 Copyright (C) 2001 LifeLine Networks BV <soap2corba@lifeline.nl>
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either
00011 version 2 of the License, or (at your option) any later
00012 version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022 -------------------------------------------------------------- */
00023 #include <OB/CORBA.h>
00024 #include <OB/CosNaming.h>
00025 #include <ServerTime.h>
00026 #include "BridgeStub.h"
00027 
00028 CORBA::ORB_var orb;
00029 ServerTime::Time_var tv;
00030 
00031 class Overhead : public JTCMonitor
00032 {
00033 public:
00034     double mn, mx, sm, cn;
00035 
00036     Overhead ()
00037     {
00038         mn = 100000;
00039         mx = -100000;
00040         cn = sm = 0;
00041     };
00042     void Stats (double ov)
00043     {
00044         JTCSynchronized sync (*this);
00045         if (ov < mn) mn = ov;
00046         if (ov > mx) mx = ov;
00047         sm += ov;
00048         cn ++;
00049         printf ("%8.3lf %8.3lf/%5.0lf=%8.3lf %8.3lf\r", mn, sm, cn, sm / cn, mx);
00050         fflush (stdout);
00051     };
00052 } *OV;
00053 
00054 class Torture : public JTCThread
00055 {
00056 public:
00057     virtual void run ()
00058     {
00059         for (;;) {
00060             int w4 = 1;
00061             double start = -sec_u ();       
00062             tv->WaitThisLong (w4);
00063             start += sec_u ();
00064             OV->Stats (start - (double) w4);
00065         }
00066     }
00067 };
00068 
00069 
00070 int main (int argc, char *argv [])
00071 {
00072     sbInitialize (argc, argv);
00073     OV = new Overhead;
00074     int ntr = (argc == 2) ? atoi (argv [1]) : 5;
00075     try {
00076         CosNaming::Name name;
00077         CosNaming::NamingContext_var inc;
00078         CosNaming::NamingContext_var myinc;
00079         orb = CORBA::ORB_init(argc, argv);
00080         try {
00081             CORBA::Object_var obj = orb->resolve_initial_references ("NameService");
00082             inc = CosNaming::NamingContext::_narrow (obj);
00083             assert (!CORBA::is_nil (inc));
00084             name.length (2);
00085             printf ("Resolving 'ServerTime/Time'\n");
00086             name [0].id = CORBA::string_dup ("ServerTime");
00087             name [0].kind = CORBA::string_dup ("");
00088             name [1].id = CORBA::string_dup ("Time");
00089             name [1].kind = CORBA::string_dup ("");
00090             try {
00091                 obj = inc->resolve (name);
00092                 tv = ServerTime::Time::_narrow (obj);
00093                 int i;
00094                 for (i = 0; i < ntr; i ++) {
00095                     JTCThread *t = new Torture;
00096                     t->start ();
00097                 }
00098             }
00099             catch (...) {
00100                 printf ("Failed\n");
00101                 return 1;
00102             }
00103         }
00104         catch (...) {
00105             printf ("NameService down?\n");
00106             return 1;
00107         }
00108     }
00109     catch (...) {
00110         printf ("Oops!\n");
00111         return 1;
00112     }
00113     return 0;
00114 }
00115 

This documentation is part of the "SOAP to CORBA bridge" project
Copyright © 2000 by Lifeline Networks bv.
All rights are reserved.