forked from OpenAtomFoundation/pikiwidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_monitor_thread.h
48 lines (38 loc) · 1.51 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
// 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 <atomic>
#include <deque>
#include <list>
#include <queue>
#include "net/include/net_thread.h"
#include "pstd/include/pstd_mutex.h"
#include "include/pika_client_conn.h"
#include "include/pika_define.h"
class PikaMonitorThread : public net::Thread {
public:
PikaMonitorThread();
~PikaMonitorThread() override;
void AddMonitorClient(const std::shared_ptr<PikaClientConn>& client_ptr);
void AddMonitorMessage(const std::string& monitor_message);
int32_t ThreadClientList(std::vector<ClientInfo>* client = nullptr);
bool ThreadClientKill(const std::string& ip_port = "all");
bool HasMonitorClients();
private:
void AddCronTask(const MonitorCronTask& task);
bool FindClient(const std::string& ip_port);
net::WriteStatus SendMessage(int32_t fd, std::string& message);
void RemoveMonitorClient(const std::string& ip_port);
std::atomic<bool> has_monitor_clients_;
pstd::Mutex monitor_mutex_protector_;
pstd::CondVar monitor_cond_;
std::list<ClientInfo> monitor_clients_;
std::deque<std::string> monitor_messages_;
std::queue<MonitorCronTask> cron_tasks_;
void* ThreadMain() override;
void RemoveMonitorClient(int32_t client_fd);
};
#endif