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 #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__