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 Thu Feb 13 18:31:34 EST 2003 by ken@xorian.net 00020 // modified on Sat May 31 15:39:05 PDT 1997 by heydon 00021 00022 // ExpCache -- Export the Vesta-2 cache server via SRPC 00023 00024 /* An "ExpCache" object exports the Vesta-2 cache server interface via SRPC. 00025 This modules uses the "LimService" interface to limit access to the server, 00026 limiting both the maximum number of concurrent threads allowed to run in 00027 the server and the maximum number of threads blocked waiting to run in it. 00028 The limits are specified in the "ExpCache" object constructor. 00029 00030 The "ExpCache" object also de-multiplexes incoming calls and unmarshals 00031 arguments for the appropriate server function. The "CacheS" object 00032 implementing the server is supplied to the "ExpCache" object constructor, 00033 and that object's methods are invoked in response to server SRPC calls. */ 00034 00035 #ifndef _EXP_CACHE_H 00036 #define _EXP_CACHE_H 00037 00038 #include <Basics.H> 00039 #include <SRPC.H> 00040 #include <LimService.H> 00041 #include <CacheIntf.H> 00042 00043 #include "CacheS.H" 00044 00045 class ExpCache { 00046 public: 00047 // type of value passed as "arg" parameter to callbacks 00048 class CallArg { 00049 public: 00050 ExpCache *expCache; 00051 CacheS *cacheS; 00052 CallArg(ExpCache *expCache=NULL, CacheS *cacheS=NULL) 00053 { this->expCache = expCache; this->cacheS = cacheS; } 00054 }; 00055 00056 ExpCache(CacheS *cs, int maxRunning, int maxBlocked, 00057 LimService_FailureCallback failureCallback = NULL, 00058 const Text& hostName = Text("")) throw (); 00059 /* Initialize an "ExpCache" object to export an instance of the Vesta-2 00060 cache server. To run the server, use the "Run" method below. */ 00061 00062 void Run() throw (SRPC::failure); 00063 /* Export version "cs.version()" of the Vesta-2 cache server, on the host 00064 named "hostname". If "hostName" is defaulted, then the interface is 00065 exported from the current host. However, if the local machine has 00066 multiple IP addresses, "hostName" can be used to differentiate among 00067 them. 00068 00069 The exported interface allows at most "maxRunning" threads to run 00070 concurrently in the server, and at most "maxBlocked" additional 00071 threads to be blocked waiting to run. If another client attempts 00072 to invoke a server function when both limits are reached, an 00073 "SRPC::failure" exception is thrown to indicate to the client that 00074 the server is busy. 00075 00076 On a successful client call, a thread is forked in the server that 00077 determines the server procedure to run, unmarshals the arguments, 00078 and then invokes the correct method of the "cs" object. If an SRPC 00079 failure occurs while handling the call, "failureCallback" is invoked 00080 with the relevant SRPC connection, the failure itself, and a "CallArg" 00081 structure. 00082 00083 Storage for "cs" should not be deleted until after the storage for 00084 the "ExpCache" object is deleted. */ 00085 00086 private: 00087 // read-only after initialization 00088 CacheIntf::DebugLevel debug; 00089 00090 // data fields 00091 CacheS *cs; 00092 LimService *ls; 00093 00094 // Perform the server instance check for calls protected by it. 00095 // Return true if call should proceed as normal (which means the 00096 // instance matches). 00097 bool check_server_instance(SRPC *srpc, const FP::Tag &server_instance, 00098 const char *func_name) 00099 const throw(SRPC::failure); 00100 00101 // callbacks 00102 void AddEntry(SRPC *srpc) throw (SRPC::failure); 00103 void FreeVars(SRPC *srpc) throw (SRPC::failure); 00104 void Lookup(SRPC *srpc) throw (SRPC::failure); 00105 void Checkpoint(SRPC *srpc) throw (SRPC::failure); 00106 void RenewLeases(SRPC *srpc) throw (SRPC::failure); 00107 void WeederRecovering(SRPC *srpc) throw (SRPC::failure); 00108 void StartMark(SRPC *srpc) throw (SRPC::failure); 00109 void SetHitFilter(SRPC *srpc) throw (SRPC::failure); 00110 void GetLeases(SRPC *srpc) throw (SRPC::failure); 00111 void ResumeLeaseExp(SRPC *srpc) throw (SRPC::failure); 00112 void EndMark(SRPC *srpc) throw (SRPC::failure); 00113 void CommitChkpt(SRPC *srpc) throw (SRPC::failure); 00114 void FlushAll(SRPC *srpc) throw (SRPC::failure); 00115 void GetCacheId(SRPC *srpc) throw (SRPC::failure); 00116 void GetCacheState(SRPC *srpc) throw (SRPC::failure); 00117 void GetCacheInstance(SRPC *srpc) throw (SRPC::failure); 00118 00119 // friend 00120 friend void ExpCache_NewCall(SRPC*, int, void*) throw (SRPC::failure); 00121 00122 // hide copy constructor from clients 00123 ExpCache(const ExpCache&); 00124 }; 00125 00126 #endif // _EXP_CACHE_H