server.h 1.2 KB
Newer Older
W
wangguibao 已提交
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
#ifndef BAIDU_PADDLE_SERVING_PREDICTOR_SERVER_H
#define BAIDU_PADDLE_SERVING_PREDICTOR_SERVER_H

#include "common/inner_common.h"

namespace baidu {
namespace paddle_serving {
namespace predictor {

class ServerManager {
public: 
    typedef google::protobuf::Service Service;
    ServerManager();

    static ServerManager& instance() {
        static ServerManager server; 
        return server;
    }

    static bool reload_starting() {
        return _s_reload_starting;
    }

    static void stop_reloader() {
        _s_reload_starting = false;
    }

    int add_service_by_format(const std::string& format);

    int start_and_wait();

private:
    int _start_reloader();
    
    int _wait_reloader();

    static void* _reload_worker(void* args);
    
    bool _compare_string_piece_without_case(
W
wangguibao 已提交
40
            const butil::StringPiece& s1, const char* s2);
W
wangguibao 已提交
41

W
wangguibao 已提交
42
    void _set_server_option_by_protocol(const ::butil::StringPiece& protocol_type);
W
wangguibao 已提交
43

W
wangguibao 已提交
44 45
    brpc::ServerOptions _options;
    brpc::Server _server;
W
wangguibao 已提交
46 47 48 49 50 51 52 53 54 55
    boost::unordered_map<std::string, Service*> _format_services;
    THREAD_T _reload_thread;
    static volatile bool _s_reload_starting;
};

} // predictor
} // paddle_serving
} // baidu

#endif