1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | |
16 | * \author Haichao.chc |
17 | * \date Oct 2020 |
18 | * \brief Main class to describe proxima search engine |
19 | * interface and action. It's designed as sigleton. |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include <string> |
25 | #include <ailego/io/pid_file.h> |
26 | #include <ailego/pattern/singleton.h> |
27 | #include "admin/admin_agent.h" |
28 | #include "agent/index_agent.h" |
29 | #include "common/macro_define.h" |
30 | #include "meta/meta_agent.h" |
31 | #include "query/query_agent.h" |
32 | #include "grpc_server.h" |
33 | #include "http_server.h" |
34 | |
35 | namespace proxima { |
36 | namespace be { |
37 | namespace server { |
38 | |
39 | class ProximaSearchEngine : public ailego::Singleton<ProximaSearchEngine> { |
40 | public: |
41 | //! Initialize |
42 | int init(bool daemonized, const std::string &pid_file); |
43 | |
44 | //! Cleanup memory |
45 | int cleanup(); |
46 | |
47 | //! Start server |
48 | int start(); |
49 | |
50 | //! Stop server |
51 | int stop(); |
52 | |
53 | public: |
54 | //! Set version |
55 | void set_version(const char *val) { |
56 | version_ = val; |
57 | } |
58 | |
59 | private: |
60 | //! Initilize logger |
61 | int init_logger(); |
62 | |
63 | //! Start as daemon |
64 | void daemonize(); |
65 | |
66 | //! Return if support brpc protocol |
67 | bool support_brpc_protocol(); |
68 | |
69 | //! Return if support http protocol |
70 | bool support_http_protocol(); |
71 | |
72 | private: |
73 | bool daemonized_{false}; |
74 | ailego::PidFile pid_file_{}; |
75 | std::string version_{}; |
76 | |
77 | agent::IndexAgentPtr index_agent_{}; |
78 | query::QueryAgentPtr query_agent_{}; |
79 | meta::MetaAgentPtr meta_agent_{}; |
80 | admin::AdminAgentPtr admin_agent_{}; |
81 | |
82 | GrpcServerUPtr grpc_server_{}; |
83 | HttpServerUPtr http_server_{}; |
84 | |
85 | std::atomic<bool> is_stopping_{false}; |
86 | }; |
87 | |
88 | } // end namespace server |
89 | } // namespace be |
90 | } // end namespace proxima |
91 | |