abtest.h 2.0 KB
Newer Older
W
sdk-cpp  
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/***************************************************************************
 * 
 * Copyright (c) 2018 Baidu.com, Inc. All Rights Reserved
 * 
 **************************************************************************/
 
/**
 * @file abtest.h
 * @author wanlijin01(wanlijin01@baidu.com)
 * @date 2018/07/06 17:11:38
 * @brief 
 *  
 **/

#ifndef  BAIDU_PADDLE_SERVING_SDK_CPP_ABTEST_H
#define  BAIDU_PADDLE_SERVING_SDK_CPP_ABTEST_H

#include "stub.h"
#include "common.h"
#include "factory.h"
W
wangguibao 已提交
21
#include <google/protobuf/message.h>
W
sdk-cpp  
wangguibao 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

namespace baidu {
namespace paddle_serving {
namespace sdk_cpp {

class Stub;
class Variant;

static const std::string WEIGHT_SEPERATOR = "|";

class EndpointRouterBase {
public:
    typedef std::vector<Variant*> VariantList;

    virtual ~EndpointRouterBase() {}

    virtual int initialize(
W
wangguibao 已提交
39
            const google::protobuf::Message& conf) = 0;
W
sdk-cpp  
wangguibao 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

    virtual Variant* route(const VariantList&) = 0;

    virtual Variant* route(
            const VariantList&,
            const void*) = 0;
};

class WeightedRandomRender : public EndpointRouterBase {
public:
    static int register_self() {
        INLINE_REGIST_OBJECT(WeightedRandomRender, EndpointRouterBase, -1);
        return 0;
    }

    WeightedRandomRender() : _normalized_sum(0) {}

    ~WeightedRandomRender() {}

    int initialize(
W
wangguibao 已提交
60
            const google::protobuf::Message& conf);
W
sdk-cpp  
wangguibao 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    Variant* route(const VariantList&);

    Variant* route(
            const VariantList&,
            const void*);

private:
    std::vector<uint32_t> _variant_weight_list;
    uint32_t _normalized_sum;
};

class VariantRouterBase {
public:
    typedef std::map<std::string, Stub*> StubMap;

    virtual ~VariantRouterBase() {}

    virtual int initialize(
            const comcfg::ConfigUnit& conf) = 0;

    virtual Stub* route(const StubMap&) = 0;

    virtual Stub* route(
            const StubMap&,
            const void*) = 0;
};

} // sdk_cpp
} // paddle_serving
} // baidu

#endif  //BAIDU_PADDLE_SERVING_SDK_CPP_ABTEST_H

/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */