2015年5月12日星期二

JDG_009:编写 JDG C++ Client 程序

环境:RHEL 6.5 + JBoss Data Grid Server 6.3.2

1. 下载并解压 jboss-datagrid-6.3.2-server.zip

2. 下载并解压 jboss-datagrid-6.3.2-hotrod-cpp-client-RHEL6-x86_64.zip

3.  编写SimpleMain.cpp,内容如下:

#include "infinispan/hotrod/ConfigurationBuilder.h"
#include "infinispan/hotrod/RemoteCacheManager.h"
#include "infinispan/hotrod/RemoteCache.h"
#include
using namespace std;
using namespace infinispan::hotrod;

int main(int argc, char** argv) {
    ConfigurationBuilder b;
    b.addServer().host(argc>1?argv[1]:"127.0.0.1").port(argc>2?atoi(argv[2]):11222);
    RemoteCacheManager cm(b.build(), false);
    //RemoteCache cache = cm.getCache();
    //cm.start();
    cout << "Hello world !" << endl;
   
    RemoteCache rc = cm.getCache("default",true);
    cm.start();
   
    std::cout << "Cache Name: " << rc.getName() << std::endl;

    std::string k1("key13");
    std::string v1("boron");
   
    // put
    rc.put(k1, v1);
    std::auto_ptr rv(rc.get(k1));
    std::cout << "rv: " << *rv << std::endl;

    rc.putIfAbsent(k1, v1);
    // get
    std::auto_ptr rv2(rc.get(k1));
    std::cout << "rv2: " << *rv << std::endl;

    std::map,HR_SHARED_PTR > map = rc.getBulk(0);
    std::cout << "getBulk size: " << map.size() << std::endl;
    cm.stop();
    return 0;
}


4. 启动JDG Server

5. 编译SimpleMain.cpp
g++ -o SimpleMain SimpleMain.cpp -L/home/maping/test/jboss-datagrid-6.3.2-hotrod-cpp-client-RHEL6-x86_64/lib64 -lhotrod -I/home/maping/test/jboss-datagrid-6.3.2-hotrod-cpp-client-RHEL6-x86_64/include/

6. 运行程序:./SimpleMain

参考文献:
1. http://infinispan.org/docs/hotrod-clients/cpp/

没有评论: