-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dispatcher.h
52 lines (38 loc) · 1.18 KB
/
Dispatcher.h
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
#ifndef DISPATCHER_H_
#define DISPATCHER_H_
#include "AbstractDistributor.h"
#include <mutex>
#include <condition_variable>
#include <queue>
#include <thread>
#include <vector>
#include <sys/types.h>
#include <sys/socket.h>
#define READ 0
#define WRITE 1
#define LOAD 2
class Dispatcher {
private:
std::queue<int> request_queue;
std::mutex request_queue_mutex;
std::condition_variable request_queue_empty;
char *port;
int thread_pool_size;
std::vector<std::thread> parser_thread_pool;
std::vector<struct Host*> *cluster_nodes;
std::mutex cluster_nodes_mutex;
AbstractDistributor *distributor;
Dispatcher( const Dispatcher& other ); // non construction-copyable
Dispatcher& operator=( const Dispatcher& ); // non copyable
void sendToAll(struct HttpRequest *request, int sock);
void sendNodeInfo(struct HttpRequest *request, int sock);
public:
Dispatcher(char *port, char *settings_file);
void dispatch_requests(int id);
void start();
void shut_down();
void set_master(const char *url, int port);
void add_host(const char *url, int port);
void remove_host(const char *url, int port);
};
#endif // DISPATCHER_H_