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

VCache.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 Fri Apr 29 00:22:52 EDT 2005 by ken@xorian.net  
00020 //      modified on Sat Feb 12 13:25:49 PST 2000 by mann  
00021 //      modified on Wed Sep  2 13:30:05 PDT 1998 by heydon
00022 
00023 // The Vesta-2 cache server
00024 
00025 #include <Basics.H>
00026 #include <CacheArgs.H>
00027 #include <CacheConfig.H>
00028 #include <Debug.H>
00029 #include <ReadConfig.H>
00030 #include <CacheConfigServer.H>
00031 
00032 #include "VCacheVersion.H"
00033 #include "CacheS.H"
00034 #include "ExpCache.H"
00035 
00036 using std::cout;
00037 using std::cerr;
00038 using std::endl;
00039 
00040 static void ExitServer() throw ()
00041 {
00042     cerr << "Syntax: VCache [ -debug <level> ] [ -noHits ]" << endl;
00043     cerr << "The allowed values for <level> are:";
00044     for (int i = 0, lineCnt = 0; i <= CacheIntf::All; i++, lineCnt++) {
00045         if (i == CacheIntf::WeederScans) continue;
00046         if (i > 0) cerr << ", ";
00047         if (lineCnt % 5 == 0) cerr << endl << "  ";
00048         cerr << CacheIntf::DebugName(i);
00049     }
00050     cerr << endl;
00051     exit(1);
00052 }
00053 
00054 static void HandleFailure(SRPC *srpc, const SRPC::failure &f, void *arg)
00055   throw ()
00056 {
00057     ExpCache::CallArg *args = (ExpCache::CallArg *)arg;
00058 
00059     if (f.r != SRPC::partner_went_away ||
00060         args->cacheS->DebugLevel() >= CacheIntf::StatusMsgs) {
00061         Debug::Lock();
00062         cout << Debug::Timestamp();
00063         if (f.r == SRPC::partner_went_away) {
00064             // remote end disconnected
00065             cout << f.msg << " (continuing...)" << endl;
00066         } else {
00067             cout << "Cache Server Failure:" << endl;
00068             cout << "  SRPC failure (code " << f.r << ')' << endl;
00069             cout << "  " << f.msg << endl;
00070             cout << ((f.r == SRPC::transport_failure) ?"Exiting":"Continuing");
00071         }
00072         cout << endl;
00073         Debug::Unlock();
00074     }
00075 }
00076 
00077 static void Server(int argc, char *argv[]) throw ()
00078 {
00079     CacheIntf::DebugLevel debug = CacheIntf::None;
00080     bool noHits = false;
00081     int arg = 1;
00082 
00083     // parse arguments
00084     while (arg < argc && argv[arg][0] == '-') {
00085         if (CacheArgs::StartsWith(argv[arg], "-debug")) {
00086             if (argc <= ++arg) {
00087                 cerr << "Error: expecting level" << endl;
00088                 ExitServer();
00089             }
00090             if (sscanf(argv[arg], "%d", &debug) != 1) {
00091                 int i;
00092                 for (i = 0; i <= CacheIntf::All; i++) {
00093                     if (strcmp(argv[arg], CacheIntf::DebugName(i)) == 0) break;
00094                 }
00095                 debug = (CacheIntf::DebugLevel)i;
00096             }
00097             if (debug < CacheIntf::None || debug > CacheIntf::All) {
00098                 cerr << "Error: unrecognized debug-level '"
00099                     << argv[arg] << "'" << endl;
00100                 ExitServer();
00101             }
00102             arg++;
00103         } else if (CacheArgs::StartsWith(argv[arg], "-noHits")) {
00104             noHits = true;
00105             arg++;
00106         } else if (CacheArgs::StartsWith(argv[arg], "-help")
00107                    || CacheArgs::StartsWith(argv[arg], "-?")) {
00108             ExitServer();
00109         } else {
00110             cerr << "Error: Unrecognized switch '" << argv[arg] << "'" << endl;
00111             ExitServer();
00112         }
00113     }
00114     if (arg < argc) {
00115         cerr << "Error: Too many arguments" << endl;
00116         ExitServer();
00117     }
00118     
00119     // start server
00120     CacheS *cs = NEW_CONSTR(CacheS, (debug, noHits));
00121     if (debug >= CacheIntf::StatusMsgs) {
00122         Debug::Lock();
00123         cout << Debug::Timestamp() << "Starting server:" << endl;
00124         cout << "  Version = " << VCacheVersion << endl;
00125         cout << "  Interface version = " << CacheIntf::Version << endl;
00126         cout << "  Config file = " << ReadConfig::Location() << endl;
00127         cout << "  Cache root = " << Config_CacheMDPath << endl;
00128         cout << "  Debug level = " << CacheIntf::DebugName(debug) << endl;
00129         cout << "  Disable cache hits = " << BoolName[noHits] << endl;
00130         cout << "  Maximum running threads = " << Config_MaxRunning << endl;
00131         cout << "  Maximum blocked threads = " << Config_MaxBlocked << endl;
00132         cout << endl;
00133         Debug::Unlock();
00134     }
00135     ExpCache *exp =
00136       NEW_CONSTR(ExpCache,
00137                  (cs, Config_MaxRunning, Config_MaxBlocked, HandleFailure));
00138 
00139     // Run the cache server
00140     while (true) {
00141         try {
00142             exp->Run();
00143         }
00144         catch (SRPC::failure f) {
00145             ExpCache::CallArg ca(NULL, cs);
00146             HandleFailure((SRPC *)NULL, f, (void *)(&ca));
00147             // exit immediately if another server is already running
00148             if (f.r == SRPC::transport_failure) break;
00149         }
00150     }
00151 }
00152 
00153 int main(int argc, char *argv[])
00154 {
00155     // rename any existing core file so it won't be overwritten
00156     system("if [ -e core ] ; then mv core core.`date +%m-%d-%y.%T` ; fi");
00157 
00158     // start the server
00159     Server(argc, argv);
00160     return(0);
00161 }

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