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 Http server module of proxima search engine
19 */
20
21#pragma once
22
23#include <thread>
24#include <brpc/server.h>
25#include "common/macro_define.h"
26#include "proxima_request_handler.h"
27
28namespace proxima {
29namespace be {
30namespace server {
31
32class HttpServer;
33using HttpServerUPtr = std::unique_ptr<HttpServer>;
34
35/*
36 * HttpServer provides http service with http1.1 protocol.
37 * Remind it doesn't support complete http1.1 protocol.
38 */
39class HttpServer {
40 public:
41 PROXIMA_DISALLOW_COPY_AND_ASSIGN(HttpServer);
42
43 //! Constructor
44 HttpServer() = default;
45
46 //! Destructor
47 ~HttpServer();
48
49 //! Constructor
50 static HttpServerUPtr Create();
51
52 public:
53 //! Start http server
54 int bind_and_start(const agent::IndexAgentPtr &index_agent,
55 const query::QueryAgentPtr &query_agent,
56 const admin::AdminAgentPtr &admin_gent,
57 const std::string &version);
58
59 //! Stop http server
60 int stop();
61
62 //! Check if server is running
63 bool is_running();
64
65 private:
66 int start_server();
67
68 int stop_server();
69
70 private:
71 brpc::Server server_{};
72 std::unique_ptr<std::thread> thread_{};
73};
74
75
76} // end namespace server
77} // namespace be
78} // end namespace proxima
79