server.h 1.8 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
#include <string>
W
wangguibao 已提交
17
#include "predictor/common/inner_common.h"
W
wangguibao 已提交
18 19 20 21 22

namespace baidu {
namespace paddle_serving {
namespace predictor {

W
wangguibao 已提交
23 24 25 26
#ifdef BCLOUD
namespace brpc = baidu::rpc;
#endif

W
wangguibao 已提交
27
class ServerManager {
W
wangguibao 已提交
28 29 30
 public:
  typedef google::protobuf::Service Service;
  ServerManager();
W
wangguibao 已提交
31

W
wangguibao 已提交
32 33 34 35
  static ServerManager& instance() {
    static ServerManager server;
    return server;
  }
W
wangguibao 已提交
36

W
wangguibao 已提交
37
  static bool reload_starting() { return _s_reload_starting; }
W
wangguibao 已提交
38

W
wangguibao 已提交
39
  static void stop_reloader() { _s_reload_starting = false; }
W
wangguibao 已提交
40

W
wangguibao 已提交
41
  int add_service_by_format(const std::string& format);
W
wangguibao 已提交
42

W
wangguibao 已提交
43
  int start_and_wait();
W
wangguibao 已提交
44

W
wangguibao 已提交
45 46
 private:
  int _start_reloader();
W
wangguibao 已提交
47

W
wangguibao 已提交
48
  int _wait_reloader();
W
wangguibao 已提交
49

W
wangguibao 已提交
50
  static void* _reload_worker(void* args);
W
wangguibao 已提交
51

W
wangguibao 已提交
52 53
  bool _compare_string_piece_without_case(const butil::StringPiece& s1,
                                          const char* s2);
W
wangguibao 已提交
54

W
wangguibao 已提交
55 56 57 58 59 60 61 62 63
  void _set_server_option_by_protocol(
      const ::butil::StringPiece& protocol_type);

  brpc::ServerOptions _options;
  brpc::Server _server;
  boost::unordered_map<std::string, Service*> _format_services;
  THREAD_T _reload_thread;
  static volatile bool _s_reload_starting;
};
W
wangguibao 已提交
64

W
wangguibao 已提交
65 66 67
}  // namespace predictor
}  // namespace paddle_serving
}  // namespace baidu