src_other/tuplebase/ZTBServer.h

00001 /*  @(#) $Id: ZTBServer.h,v 1.8 2007/07/06 16:55:56 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2003 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZTBServer__
00026 #define __ZTBServer__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZRefCount.h"
00030 #include "ZThread.h"
00031 #include "ZTuple.h"
00032 
00033 #include <set>
00034 
00035 class ZStreamR;
00036 class ZStreamW;
00037 class ZTB;
00038 class ZTBRep;
00039 
00040 // =================================================================================================
00041 #pragma mark -
00042 #pragma mark * ZTBServer
00043 
00044 class ZTBServer
00045         {
00046 private:
00047         class Transaction;
00048         class Search_t;
00049         class Count_t;
00050 
00051 public:
00052         ZTBServer(ZTB iTB);
00053         ZTBServer(ZTB iTB, const std::string& iLogFacility);
00054 
00055         ~ZTBServer();
00056 
00057         void RunReader(const ZStreamR& iStream);
00058         void RunWriter(const ZStreamW& iStream);
00059 
00060 private:
00061         static void sCallback_AllocateIDs(void* iRefcon, uint64 iBaseID, size_t iCount);
00062         void Handle_AllocateIDs(const ZTuple& iReq);
00063 
00064         void Handle_Create(const ZTuple& iReq);
00065 
00066         static void sCallback_GetTupleForSearch(
00067                 void* iRefcon, size_t iCount, const uint64* iIDs, const ZTuple* iTuples);
00068 
00069         static void sCallback_Search(void* iRefcon, std::vector<uint64>& ioResults);
00070         void Handle_Search(const ZTuple& iReq);
00071 
00072         static void sCallback_Count(void* iRefcon, size_t iResult);
00073         void Handle_Count(const ZTuple& iReq);
00074 
00075         void Handle_Abort(const ZTuple& iReq);
00076 
00077         static void sCallback_Validate(bool iSucceeded, void* iRefcon);
00078         void Handle_Validate(const ZTuple& iReq);
00079 
00080         static void sCallback_Commit(void* iRefcon);
00081         void Handle_Commit(const ZTuple& iReq);
00082 
00083         static void sCallback_GetTuple(
00084                 void* iRefcon, size_t iCount, const uint64* iIDs, const ZTuple* iTuples);
00085 
00086         void Handle_Actions(const ZTuple& iReq);
00087 
00088         void Reader(const ZStreamR& iStream);
00089         void Writer(const ZStreamW& iStream);
00090 
00091         void TearDown();
00092 
00093         ZRef<ZTBRep> fTBRep;
00094 
00095         ZMutex fMutex_Structure;
00096         ZCondition fCondition_Sender;
00097                 bool fReaderExited;
00098                 bool fWriterExited;
00099 
00100                 ZTime fTime_LastRead;
00101                 bool fPingRequested;
00102                 bool fPingSent;
00103 
00104                 std::vector<Transaction*> fTransactions_Create_Unsent;
00105                 std::vector<Transaction*> fTransactions_Created;
00106 
00107                 std::vector<Transaction*> fTransactions_Validate_Waiting;
00108                 std::vector<Transaction*> fTransactions_Validate_Succeeded;
00109                 std::vector<Transaction*> fTransactions_Validate_Failed;
00110                 std::vector<Transaction*> fTransactions_Validated;
00111 
00112                 std::vector<Transaction*> fTransactions_Commit_Waiting;
00113                 std::vector<Transaction*> fTransactions_Commit_Acked;
00114 
00115                 std::set<Transaction*> fTransactions_HaveTuplesToSend;
00116 
00117                 std::vector<Search_t*> fSearches_Waiting;
00118                 std::vector<Search_t*> fSearches_Unsent;
00119 
00120                 std::vector<Count_t*> fCounts_Waiting;
00121                 std::vector<Count_t*> fCounts_Unsent;
00122 
00123                 std::vector<std::pair<uint64, size_t> > fIDs;
00124 
00125         std::string fLogFacility;
00126         };
00127 
00128 #endif // __ZTBServer__

Generated on Thu Jul 26 11:21:57 2007 for ZooLib by  doxygen 1.4.7