forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pika_monitor_thread.h
51 lines (43 loc) · 1.54 KB
/
pika_monitor_thread.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
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_MONITOR_THREAD_H_
#define PIKA_MONITOR_THREAD_H_
#include <map>
#include <set>
#include <atomic>
#include <list>
#include <deque>
#include <queue>
#include "pink_thread.h"
#include "pink_epoll.h"
#include "pika_client_conn.h"
#include "slash_mutex.h"
#include "pika_define.h"
class PikaMonitorThread : public pink::Thread {
public:
PikaMonitorThread();
virtual ~PikaMonitorThread();
void AddMonitorClient(pink::RedisConn* client_ptr);
void AddMonitorMessage(const std::string &monitor_message);
int32_t ThreadClientList(std::vector<ClientInfo>* client = NULL);
bool ThreadClientKill(const std::string& ip_port = "all");
bool HasMonitorClients();
private:
void AddCronTask(MonitorCronTask task);
bool FindClient(const std::string& ip_port);
pink::WriteStatus SendMessage(int32_t fd, std::string& message);
void RemoveMonitorClient(const std::string& ip_port);
slash::Mutex monitor_mutex_protector_;
slash::CondVar monitor_cond_;
std::list<ClientInfo> monitor_clients_;
std::deque<std::string> monitor_messages_;
std::atomic<bool> is_running_;
std::atomic<bool> should_exit_;
std::queue<MonitorCronTask> cron_tasks_;
virtual void* ThreadMain();
void RemoveMonitorClient(int32_t client_fd);
void StartThread();
};
#endif