Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DemoClients.cc

Go to the documentation of this file.
00001 #include "TROOT.h"
00002 #include "TSystem.h"
00003 #include "MessageService/MsgService.h"
00004 #include "Dispatcher/DDS.h"
00005 #include "Dispatcher/DDSClient.h"
00006 
00007 TROOT root("DemoClient","MINOS Data Dispatcher System Demo Client");
00008 CVSID("$Id: DemoClients.cc,v 1.4 2003/09/30 19:49:38 kasahara Exp $");
00009 
00011 //                                                                          //
00012 // Data Distribution System demo client.  This program uses the DDSClient   //
00013 // class to connect to the dispatcher server.                               //
00014 //                                                                          //
00015 // Arguments: serverhostname = host on which dispatcher parent server       //
00016 //                             is running.  If not specified, the default   //
00017 //                             is to attempt to connect to a parent server  //
00018 //                             running on the same machine as this client.  //
00019 //                                                                          //
00020 //                                                                          //
00021 // This demo only illustrates the process of connecting to ddsparentserver, //
00022 // requesting data (which spawns the ddschildserver) and sending a shutdown //
00023 // message to the ddschildserver.  No data is received since this isn't     //
00024 // implemented yet in the dispatcher classes.                               //
00026 
00027 int main(int argc, char **argv) {
00028 
00029   MsgStream& ms = MSGSTREAM("DDS",Msg::kInfo);
00030 
00031   ms << "This demo will attempt to set up 11 client connections\n"
00032      << "with the dispatcher server.  The first 10 will succeed.  The\n"
00033      << "11th will be rejected with a server 'Saturated' error message.\n"
00034      << "(The saturation level of the server is set by the kMaxChild\n"
00035      << "constant in the DDSParentServer class.  It has arbitrarily\n"
00036      << "been set to 10 for now.)" << endl;
00037 
00038   const char* serverhostname;
00039   if (argc > 1) {
00040     serverhostname = argv[1];
00041     ms << "The user has requested that the client will attempt to connect\n"
00042        << "to a parent server running on host " << serverhostname 
00043        << ".\n" << endl;
00044   }
00045   else {
00046     // Determine the host name of the current machine
00047     serverhostname = gSystem -> HostName();
00048     ms << "Since the user has not specified the host of the parent server\n"          << "as an argument to this demo, the default is to assume that the\n"
00049        << "parent server runs on the local host " << serverhostname 
00050        << ".\n" << endl;
00051   }
00052 
00053   const Int_t nclient = 11;
00054   // Create an array of DDSClient pointers to keep track of client connections
00055   DDSClient* ddsclient[nclient];
00056 
00057   for (Int_t ic= 0; ic < nclient; ic++) {
00058     // Create a DDSClient object connected to the DDS server running on 
00059     // node kasahara.hep.umn.edu and port 9090.
00060     ddsclient[ic] = new DDSClient(serverhostname,9090);
00061 
00062     // Check validity of connected socket before using it
00063     if (! ddsclient[ic]->IsValid() ) {
00064       ms << "Error in creation of socket connected to server for client " 
00065          << ic + 1 << ".\n" << endl;
00066       delete ddsclient[ic]; ddsclient[ic] = 0;
00067     }
00068     else {
00069       ms << "Successfully connected to dispatcher server for client " 
00070          << ic + 1 << "." << endl;
00071       ms << ddsclient[ic] << endl;
00072     }
00073   }
00074 
00075   // Normally subscribe and execute entry retrieval loop here.
00076   ms << "The demo will now shutdown the connected clients."
00077      << endl; 
00078 
00079   for (Int_t ic = 0; ic < nclient; ic++) {
00080     if ( ddsclient[ic] ) {
00081       ms << "Sending shutdown message to server for client " << ic + 1
00082          << "." << endl;
00083       ddsclient[ic] -> Shutdown();
00084       delete ddsclient[ic]; ddsclient[ic] = 0;
00085     }
00086   }
00087 
00088   return 0;
00089 
00090 }
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1