-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbcoordinator.hpp
62 lines (51 loc) · 1.6 KB
/
dbcoordinator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _dbcoordinator_hpp
#define _dbcoordinator_hpp
#define WIN32_LEAN_AND_MEAN /* required by xmlrpc-c/server_abyss.hpp */
#include <cassert>
#include <stdexcept>
#include <iostream>
#include <unistd.h>
#include <pthread.h>
using namespace std;
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/base64.hpp>
#include <xmlrpc-c/registry.hpp>
#include <xmlrpc-c/server_abyss.hpp>
#include "common.hpp"
#include "dbworker.hpp"
#include "transaction.hpp"
class ExcuteTransaction;
class dbcoordinator {
private:
/*RPC Server*/
xmlrpc_c::serverAbyss* dbServer;
xmlrpc_c::registry* dbRegistry;
/*DB Worker*/
int workerNums;
int maxKeyNums;
int keysPerWorker;
dbworker* workers;
pthread_t* worker_threads;
map<int, TransactionReq> mapTransaction(TransactionReq transreq);
public:
friend class ExcuteTransaction;
dbcoordinator(int workerNums, int maxKeyNums);
void setupWorkers();
void setupRPC(ExcuteTransaction* rpc_method);
void runRPC() {dbServer->run();}
};
class ExcuteTransaction : public xmlrpc_c::method {
private:
dbcoordinator& rpc_method;
public:
ExcuteTransaction(dbcoordinator co) : rpc_method(co) {
// signature and help strings are documentation -- the client
// can query this information with a system.methodSignature and
// system.methodHelp RPC.
this->_signature = "s:s";
// method's result and two arguments are integers
this->_help = "This method receive a string and put it into db";
}
void execute(xmlrpc_c::paramList const& paramList, xmlrpc_c::value * const retvalP);
};
#endif