00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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
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
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
00148 if (f.r == SRPC::transport_failure) break;
00149 }
00150 }
00151 }
00152
00153 int main(int argc, char *argv[])
00154 {
00155
00156 system("if [ -e core ] ; then mv core core.`date +%m-%d-%y.%T` ; fi");
00157
00158
00159 Server(argc, argv);
00160 return(0);
00161 }