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

ChkptCache.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:29:57 EDT 2004 by ken@xorian.net  
00020 //      modified on Sat Feb 12 12:03:46 PST 2000 by mann  
00021 //      modified on Mon Mar 30 13:12:42 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::Checkpoint" method to
00025    synchronously flush its logs to disk. */
00026 
00027 // basics
00028 #include <Basics.H>
00029 
00030 // cache-common
00031 #include <CacheConfig.H>
00032 #include <Model.H>
00033 #include <CacheIndex.H>
00034 #include <Debug.H>
00035 
00036 // local includes
00037 #include "CacheC.H"
00038 
00039 using std::ostream;
00040 using std::cout;
00041 using std::cerr;
00042 using std::endl;
00043 
00044 static void ExitClient() throw ()
00045 {
00046     cerr << "SYNTAX: ChkptCache [ -n ]" << endl;
00047     cerr.flush();
00048     exit(1);
00049 }
00050 
00051 static void PrintSRPCFailure(ostream &os, SRPC::failure &f) throw ()
00052 {
00053     os << "SRPC Failure (code " << f.r << "):" << endl;
00054     os << "  " << f.msg << endl << endl;
00055     os.flush();
00056 }
00057 
00058 static void Chkpt() throw ()
00059 {
00060     FP::Tag pkgVersion("", /*len=*/ 0); // fingerprint of empty string
00061     Model::T model = 0;
00062     CacheEntry::Indices cis;
00063     bool done = false;
00064 
00065     // print args
00066     cout << Debug::Timestamp() << "CALLING Checkpoint" << endl;
00067     cout << "  pkgVersion = " << pkgVersion << endl;
00068     cout << "  model = " << model << endl;
00069     cout << "  cis = " << cis << endl;
00070     cout << "  done = " << BoolName[done] << endl;
00071     cout << endl;
00072 
00073     // checkpoint cache
00074     try {
00075       CacheC client;
00076 
00077       client.Checkpoint(pkgVersion, model, cis, done);
00078     } catch (SRPC::failure &f) {
00079         PrintSRPCFailure(cerr, f);
00080     }
00081 
00082     cout << Debug::Timestamp() << "RETURNED Checkpoint" << endl;
00083     cout << endl;
00084 }
00085 
00086 int main(int argc, char *argv[])
00087 {
00088     bool doIt = true;
00089 
00090     // process command-line
00091     if (argc > 4) {
00092         cerr << "Error: too many arguments" << endl;
00093         ExitClient();
00094     }
00095     for (int arg = 1; arg < argc; arg++) {
00096         if (!strcmp(argv[arg], "-n")) {
00097             doIt = false;
00098         } else if (*argv[arg] == '-') {
00099             cerr << "Error: unrecognized option: " << argv[arg] << endl;
00100             ExitClient();
00101         } else {
00102             cerr << "Error: invalid command-line" << endl;
00103             ExitClient();
00104         }
00105     }
00106 
00107     // start program
00108     cout << Debug::Timestamp() << "Checkpointing cache:" << endl;
00109     cout << "  Host = " << Config_Host << endl;
00110     cout << "  Port = " << Config_Port << endl << endl;
00111     cout.flush();
00112 
00113     // make "Checkpoint" call
00114     if (doIt) {
00115         Chkpt();
00116         cout << Debug::Timestamp() << "Done!" << endl;
00117         cout.flush();
00118     } else {
00119         cout << "NOTE: No action taken at your request." << endl;
00120         cout.flush();
00121     }
00122     return 0;
00123 }

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