Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

FlushCache.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Wed Aug  4 17:49:12 EDT 2004 by ken@xorian.net  
00020 //      modified on Mon Feb 14 18:20:53 PST 2000 by mann  
00021 //      modified on Mon Mar 30 13:11:28 PST 1998 by heydon
00022 
00023 /* This is a simple program that establishes a connection to the Vesta-2
00024    cache server, and then invokes the "Cache::FlushAll" method to
00025    synchronously flush all of its volatile cache entries to the stable
00026    cache. */
00027 
00028 // basics
00029 #include <Basics.H>
00030 
00031 // cache-common
00032 #include <CacheConfig.H>
00033 #include <Debug.H>
00034 
00035 // local includes
00036 #include "DebugC.H"
00037 
00038 using std::ostream;
00039 using std::cout;
00040 using std::cerr;
00041 using std::endl;
00042 
00043 static void ExitClient() throw ()
00044 {
00045     cerr << "SYNTAX: FlushCache [ -n ]" << endl;
00046     cerr.flush();
00047     exit(1);
00048 }
00049 
00050 static void PrintSRPCFailure(ostream &os, SRPC::failure &f) throw ()
00051 {
00052     os << "SRPC Failure (code " << f.r << "):" << endl;
00053     os << "  " << f.msg << endl << endl;
00054     os.flush();
00055 }
00056 
00057 static void FlushAll() throw ()
00058 {
00059     DebugC debug;
00060 
00061     // print args
00062     cout << Debug::Timestamp() << "CALLING FlushAll" << endl;
00063     cout << endl;
00064 
00065     // make call
00066     try {
00067         debug.FlushAll();
00068     } catch (SRPC::failure &f) {
00069         PrintSRPCFailure(cerr, f);
00070     }
00071 
00072     // print result
00073     cout << Debug::Timestamp() << "RETURNED FlushAll" << endl;
00074     cout << endl;
00075 }
00076 
00077 int main(int argc, char *argv[]) 
00078 {
00079     bool doIt = true;
00080 
00081     // process command-line
00082     if (argc > 4) {
00083         cerr << "Error: too many arguments" << endl;
00084         ExitClient();
00085     }
00086     for (int arg = 1; arg < argc; arg++) {
00087         if (!strcmp(argv[arg], "-n")) {
00088             doIt = false;
00089         } else if (*argv[arg] == '-') {
00090             cerr << "Error: unrecognized option: " << argv[arg] << endl;
00091             ExitClient();
00092         } else {
00093             cerr << "Error: invalid command-line" << endl;
00094             ExitClient();
00095         }
00096     }
00097 
00098     // start program
00099     cout << Debug::Timestamp() << "Flushing cache:" << endl;
00100     cout << "  Host = " << Config_Host << endl;
00101     cout << "  Port = " << Config_Port << endl << endl;
00102     cout.flush();
00103 
00104     // make "FlushAll" call
00105     if (doIt) {
00106         FlushAll();
00107         cout << Debug::Timestamp() << "Done!" << endl;
00108         cout.flush();
00109     } else {
00110         cout << "NOTE: No action taken at your request." << endl;
00111         cout.flush();
00112     }
00113     return 0;
00114 }

Generated on Mon May 8 00:48:30 2006 for Vesta by  doxygen 1.4.2