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

TestMarshalS.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:27:16 EDT 2005 by ken@xorian.net  
00020 //      modified on Fri Jul 27 19:01:42 PDT 2001 by mann  
00021 //      modified on Sat Jan 29 14:27:43 PST 2000 by heydon
00022 
00023 /* This program is a simple test of the marshalling interfaces for the Vesta
00024    cache server. The modules are:
00025 
00026    Client side: CacheC, ParCacheC
00027    Server side: CacheS, ExpCache
00028    Both sides:  CacheIntf, Repository, CacheIndex, FV, Derived, VestaVal
00029 
00030    The syntax for the server application is:
00031 
00032      server [ maxRunning [ maxBlocked ] ]
00033 
00034    Any omitted argument defaults to a large integer. The first argument
00035    specifies the maximum number of server threads allowed to run at once. If
00036    it is specified, a supplied second argument specifies the maximum number of
00037    threads allowed to block when the maximum number of threads are running
00038    before refusing the connection. */
00039 
00040 // basics
00041 #include <Basics.H>
00042 #include <Table.H>
00043 #include <FP.H>
00044 
00045 // cache-common
00046 #include <CacheIntf.H>
00047 #include <Debug.H>
00048 #include <ReadConfig.H>
00049 #include <PKPrefix.H>
00050 #include <CacheState.H>
00051 #include <Model.H>
00052 #include <CacheIndex.H>
00053 #include <FV.H>
00054 #include <VestaVal.H>
00055 #include <NewVal.H>
00056 
00057 // local includes
00058 #include "CacheS.H"
00059 #include "ExpCache.H"
00060 
00061 CacheS::CacheS(CacheIntf::DebugLevel debug, bool noHits) throw ()
00062 {
00063     this->debug = CacheIntf::All;
00064 }
00065 
00066 FV::Epoch CacheS::FreeVariables(const FP::Tag& pk,
00067   /*OUT*/ FV::List &names, /*OUT*/ bool &isEmpty) throw ()
00068 {
00069     FV::Epoch res;
00070     NewVal::NewNames(/*OUT*/ names);
00071     isEmpty = ((names.len == 0) && (Debug::MyRand(0, 5) > 1));
00072     res = Debug::MyRand(0, 1000);
00073     return(res);
00074 }
00075 
00076 CacheIntf::LookupRes
00077 CacheS::Lookup(const FP::Tag &pk, FV::Epoch id, const FP::List &fps,
00078   /*OUT*/ CacheEntry::Index &ci, /*OUT*/ const VestaVal::T* &value) throw ()
00079 {
00080     CacheIntf::LookupRes res;
00081     int i = Debug::MyRand(1, 10);
00082     if (i < 6) res = CacheIntf::Hit;
00083     else if (i < 8) res = CacheIntf::Miss;
00084     else res = CacheIntf::FVMismatch;
00085     if (res == CacheIntf::Hit) {
00086         ci = (int)Debug::MyRand(0,9999);
00087         VestaVal::T *newValue = NEW(VestaVal::T);// allocate non-const local
00088         NewVal::NewValue(*(newValue));           // fill it in
00089         value = (const VestaVal::T *)newValue;   // cast it to result
00090     }
00091     return(res);
00092 }
00093 
00094 CacheIntf::AddEntryRes
00095 CacheS::AddEntry(FP::Tag *pk, FV::List *names, FP::List *fps,
00096   VestaVal::T *value, Model::T model, CacheEntry::Indices* kids,
00097   /*OUT*/ CacheEntry::Index& ci) throw ()
00098 {
00099     CacheIntf::AddEntryRes res;
00100     int i = Debug::MyRand(0, 7);
00101     res = (i == 0) ? CacheIntf::NoLease : CacheIntf::EntryAdded;
00102     if (res == CacheIntf::EntryAdded) {
00103         ci = Debug::MyRand(0, 9999);
00104     }
00105     return res;
00106 }
00107 
00108 void CacheS::WeederRecovering(bool doneMarking) throw ()
00109 {
00110     /* SKIP */
00111 }
00112 
00113 BitVector* CacheS::StartMark(/*OUT*/ int &newLogVer) throw ()
00114 {
00115   BitVector *res = NEW(BitVector);
00116   for (int i = 0; i < 10; i++) {
00117     int j = Debug::MyRand(0, 60);
00118     (void) res->Set(j);
00119   }
00120   newLogVer = 0;
00121   return res;
00122 }
00123 
00124 void CacheS::SetHitFilter(const BitVector &cis) throw ()
00125 {
00126     /* SKIP */
00127 }
00128 
00129 BitVector* CacheS::GetLeases() throw ()
00130 {
00131   BitVector *res = NEW(BitVector);
00132   for (int i = 0; i < 10; i++) {
00133     int j = Debug::MyRand(0, 60);
00134     (void) res->Set(j);
00135   }
00136   return res;
00137 }
00138 
00139 void CacheS::ResumeLeaseExp() throw ()
00140 {
00141     /* SKIP */
00142 }
00143 
00144 int CacheS::EndMark(const BitVector &cis, const PKPrefix::List &pfxs) throw ()
00145 {
00146     return 1;
00147 }
00148 
00149 void CacheS::CommitChkpt() throw ()
00150 {
00151     /* SKIP */
00152 }
00153 
00154 void CacheS::Checkpoint(const FP::Tag &pkgVersion, Model::T model,
00155   CacheEntry::Indices *cis, bool done) throw ()
00156 {
00157     /* SKIP */
00158 }
00159 
00160 void CacheS::FlushAll() throw ()
00161 {
00162     /* SKIP */
00163 }
00164 
00165 void CacheS::GetCacheId(/*OUT*/ CacheId &id) throw ()
00166 {
00167     /* SKIP */
00168 }
00169 
00170 void CacheS::GetCacheState(/*OUT*/ CacheState &state) throw ()
00171 {
00172     /* SKIP */
00173 }
00174 
00175 bool CacheS::RenewLeases(CacheEntry::Indices *cis) throw ()
00176 {
00177     int i = Debug::MyRand(0,1);
00178     bool res = (i == 0);
00179     return res;
00180 }
00181 
00182 void CacheWorker::Start() throw ()
00183 {
00184     /* NO-OP */
00185 }
00186 
00187 void ExitServer() throw ()
00188 {
00189     cerr << "SYNTAX: server [ maxRunning [ maxBlocked ] ]" << endl;
00190     exit(1);
00191 }
00192 
00193 void HandleFailure(SRPC *srpc, const SRPC::failure &f, void *arg) throw ()
00194 {
00195     cerr << "SRPC failure (code " << f.r << "):" << endl;
00196     cerr << "  " << f.msg << endl << endl;
00197 }
00198 
00199 void Server(int argc, char *argv[]) throw ()
00200 {
00201     int maxRunning, maxBlocked;
00202 
00203     // parse arguments
00204     if (argc > 3) {
00205         cerr << "Error: Too many arguments" << endl;
00206         ExitServer();
00207     }
00208     maxRunning = maxBlocked = 10000;
00209     if (argc > 1) sscanf(argv[1], "%d", &maxRunning);
00210     if (argc > 2) sscanf(argv[2], "%d", &maxBlocked);
00211 
00212     // start server
00213     CacheS cs;
00214     Debug::Lock();
00215     cout << "Starting server:" << endl;
00216     cout << "  Config file = " << ReadConfig::Location() << endl;
00217     cout << "  Maximum number of running threads = " << maxRunning << endl;
00218     cout << "  Maximum number of blocked threads = " << maxBlocked << endl;
00219     cout << endl;
00220     Debug::Unlock();
00221     ExpCache exp(&cs, maxRunning, maxBlocked, HandleFailure);
00222 
00223     // Run the cache server
00224     while (1) {
00225         try {
00226             exp.Run();
00227         }
00228         catch (SRPC::failure f) {
00229             HandleFailure((SRPC *)NULL, f, (void *)NULL);
00230             // exit immediately if another server is already running
00231             if (f.r == SRPC::transport_failure) break;
00232         }
00233     }
00234 }
00235 
00236 int main(int argc, char *argv[]) throw ()
00237 {
00238     Server(argc, argv);
00239     return(0);
00240 }

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