leopard, 一个在线代码调试框架

leopard是一个在线代码调试框架。

如果你有下列需求,可以使用这个框架

(1)动态修改线上程序的一些配置参数,比如说,线程池的数目,timeout的阈值等

(2)得到线上程序的一些状态,比如,搜索引擎中,一个请求对应的排序后文档列表


leopard提供了一个注册callback机制,用户只需提供实现自己的callback函数,并注册到一个唯一的路径,就可以在线的按照指定的路径来请求函数,并得到相应的结果。


leopard使用非常简单,直接嵌入到你的程序中即可。具体使用步骤可以参考提供的例子。


#include <string>
#include <utility>
#include <vector>

#include <boost/bind.hpp>

#include "cpp_leopard/leopard/leopard.h"

using namespace cpp_leopard::leopard;
using namespace std;

// Note:
// For convenience, this file unit does not follow the
// google coding style in a way.

typedef vector<pair<string, string> > vector_pair_type;

string non_member_function(const vector_pair_type& parameters) {
  return "A non-member function";;
}

class Foo {
 public:
  string operator() (const vector_pair_type& parameters) {
    return "A function object";
  }

  string NonStaticMemberFunction(const vector_pair_type& parameters) const {
    return "A non-static member function";
  }

  static string StaticMemberFunction(const vector_pair_type& parameters) {
    return "A static member function";
  }
};

int main() {
  AbstractHttpServer& server = GetDefaultServer();
  RegisterCommonHandlers(&server);

  if (!server.Start()) {
    return -1;
  }

  // Register a free function(non-member function)
  server.RegisterHandler("/function/non_member_function",
                         non_member_function);

  // Register a functor(function object)
  server.RegisterHandler("/function/function_object", Foo());

  // Register a static member function
  server.RegisterHandler("/function/static_member_function",
                         Foo::StaticMemberFunction);

  // Register a member function with boost::bind or std::bindxxx
  // Note: I have a while loop below, so the local var 'foo' will
  // never be destroyed. It's just an example here. Beware don't
  // do this in your project.
  Foo foo;
  server.RegisterHandler("/function/non_static_member_function",
                         boost::bind(&Foo::NonStaticMemberFunction, &foo, _1));

  while (true) {
    sleep(10);
  }
}


注意:

(1)提供了C++的版本,后续会推出java等版本。

(2)不支持跨平台,目前仅支持unix/linux平台

(3)leopard采用腾讯开源的blade编译工具进行编译

(4)非常轻量级,基本不会影响线上程序的性能

(5)leopard采用一个轻量级的web server,mongoose来提供http通信服务。 用户也可以定制,只需实现相应的接口即可。

(6)线程安全


具体项目已开源在github上,请关注https://github.com/JianboZhu/leopard

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值