HBASE-24434 Fix building cpp-example DemoClient
Changed boost::shared_ptr to std::shared_ptr for compatibility with apache thrift v0.13. Signed-off-by: Bharath Vissapragada <bharathv@apache.org>
This commit is contained in:
parent
1e86ff09d7
commit
60c125367b
@ -57,11 +57,10 @@ Example code.
|
|||||||
3. Execute {perl DemoClient.pl}.
|
3. Execute {perl DemoClient.pl}.
|
||||||
|
|
||||||
* CPP: hbase-examples/src/main/cpp/DemoClient.cpp
|
* CPP: hbase-examples/src/main/cpp/DemoClient.cpp
|
||||||
1. Make sure you have boost and Thrift C++ libraries; modify Makefile if necessary.
|
1. Make sure you have Thrift C++ libraries; modify Makefile if necessary.
|
||||||
The recent (0.9.0 as of this writing) version of Thrift can be downloaded from http://thrift.apache.org/download/.
|
The recent (0.13.0 as of this writing) version of Thrift can be downloaded from http://thrift.apache.org/download/.
|
||||||
Boost can be found at http://www.boost.org/users/download/.
|
|
||||||
2. Execute {make}.
|
2. Execute {make}.
|
||||||
3. Execute {./DemoClient}.
|
3. Execute {./DemoClient <host> <port>}.
|
||||||
|
|
||||||
ON PROTOBUFS
|
ON PROTOBUFS
|
||||||
This maven module has core protobuf definition files ('.protos') used by hbase
|
This maven module has core protobuf definition files ('.protos') used by hbase
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
#include <protocol/TBinaryProtocol.h>
|
#include <protocol/TBinaryProtocol.h>
|
||||||
#include <transport/TSocket.h>
|
#include <transport/TSocket.h>
|
||||||
#include <transport/TTransportUtils.h>
|
#include <transport/TTransportUtils.h>
|
||||||
@ -79,15 +78,15 @@ main(int argc, char** argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
bool isFramed = false;
|
bool isFramed = false;
|
||||||
boost::shared_ptr<TTransport> socket(new TSocket(argv[1], boost::lexical_cast<int>(argv[2])));
|
std::shared_ptr<TTransport> socket = std::make_shared<TSocket>(argv[1], std::stoi(argv[2]));
|
||||||
boost::shared_ptr<TTransport> transport;
|
std::shared_ptr<TTransport> transport;
|
||||||
|
|
||||||
if (isFramed) {
|
if (isFramed) {
|
||||||
transport.reset(new TFramedTransport(socket));
|
transport = std::make_shared<TFramedTransport>(socket);
|
||||||
} else {
|
} else {
|
||||||
transport.reset(new TBufferedTransport(socket));
|
transport = std::make_shared<TBufferedTransport>(socket);
|
||||||
}
|
}
|
||||||
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
std::shared_ptr<TProtocol> protocol = std::make_shared<TBinaryProtocol>(transport);
|
||||||
|
|
||||||
const std::map<Text, Text> dummyAttributes; // see HBASE-6806 HBASE-4658
|
const std::map<Text, Text> dummyAttributes; // see HBASE-6806 HBASE-4658
|
||||||
HbaseClient client(protocol);
|
HbaseClient client(protocol);
|
||||||
@ -240,10 +239,10 @@ main(int argc, char** argv)
|
|||||||
mutations.clear();
|
mutations.clear();
|
||||||
mutations.push_back(Mutation());
|
mutations.push_back(Mutation());
|
||||||
mutations.back().column = "entry:num";
|
mutations.back().column = "entry:num";
|
||||||
mutations.back().value = boost::lexical_cast<std::string>(i);
|
mutations.back().value = std::to_string(i);
|
||||||
mutations.push_back(Mutation());
|
mutations.push_back(Mutation());
|
||||||
mutations.back().column = "entry:sqr";
|
mutations.back().column = "entry:sqr";
|
||||||
mutations.back().value = boost::lexical_cast<std::string>(i*i);
|
mutations.back().value = std::to_string(i * i);
|
||||||
client.mutateRow(t, row, mutations, dummyAttributes);
|
client.mutateRow(t, row, mutations, dummyAttributes);
|
||||||
client.getRow(rowResult, t, row, dummyAttributes);
|
client.getRow(rowResult, t, row, dummyAttributes);
|
||||||
printRow(rowResult);
|
printRow(rowResult);
|
||||||
|
@ -16127,10 +16127,10 @@ void HbaseProcessor::process_getRegionInfo(int32_t seqid, ::apache::thrift::prot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::boost::shared_ptr< ::apache::thrift::TProcessor > HbaseProcessorFactory::getProcessor(const ::apache::thrift::TConnectionInfo& connInfo) {
|
std::shared_ptr< ::apache::thrift::TProcessor > HbaseProcessorFactory::getProcessor(const ::apache::thrift::TConnectionInfo& connInfo) {
|
||||||
::apache::thrift::ReleaseHandler< HbaseIfFactory > cleanup(handlerFactory_);
|
::apache::thrift::ReleaseHandler< HbaseIfFactory > cleanup(handlerFactory_);
|
||||||
::boost::shared_ptr< HbaseIf > handler(handlerFactory_->getHandler(connInfo), cleanup);
|
std::shared_ptr< HbaseIf > handler(handlerFactory_->getHandler(connInfo), cleanup);
|
||||||
::boost::shared_ptr< ::apache::thrift::TProcessor > processor(new HbaseProcessor(handler));
|
std::shared_ptr< ::apache::thrift::TProcessor > processor(new HbaseProcessor(handler));
|
||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
}}}} // namespace
|
}}}} // namespace
|
||||||
|
@ -72,7 +72,7 @@ class HbaseIfFactory {
|
|||||||
|
|
||||||
class HbaseIfSingletonFactory : virtual public HbaseIfFactory {
|
class HbaseIfSingletonFactory : virtual public HbaseIfFactory {
|
||||||
public:
|
public:
|
||||||
HbaseIfSingletonFactory(const boost::shared_ptr<HbaseIf>& iface) : iface_(iface) {}
|
HbaseIfSingletonFactory(const std::shared_ptr<HbaseIf>& iface) : iface_(iface) {}
|
||||||
virtual ~HbaseIfSingletonFactory() {}
|
virtual ~HbaseIfSingletonFactory() {}
|
||||||
|
|
||||||
virtual HbaseIf* getHandler(const ::apache::thrift::TConnectionInfo&) {
|
virtual HbaseIf* getHandler(const ::apache::thrift::TConnectionInfo&) {
|
||||||
@ -81,7 +81,7 @@ class HbaseIfSingletonFactory : virtual public HbaseIfFactory {
|
|||||||
virtual void releaseHandler(HbaseIf* /* handler */) {}
|
virtual void releaseHandler(HbaseIf* /* handler */) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
boost::shared_ptr<HbaseIf> iface_;
|
std::shared_ptr<HbaseIf> iface_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HbaseNull : virtual public HbaseIf {
|
class HbaseNull : virtual public HbaseIf {
|
||||||
@ -6010,22 +6010,22 @@ class Hbase_getRegionInfo_presult {
|
|||||||
|
|
||||||
class HbaseClient : virtual public HbaseIf {
|
class HbaseClient : virtual public HbaseIf {
|
||||||
public:
|
public:
|
||||||
HbaseClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) :
|
HbaseClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) :
|
||||||
piprot_(prot),
|
piprot_(prot),
|
||||||
poprot_(prot) {
|
poprot_(prot) {
|
||||||
iprot_ = prot.get();
|
iprot_ = prot.get();
|
||||||
oprot_ = prot.get();
|
oprot_ = prot.get();
|
||||||
}
|
}
|
||||||
HbaseClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, boost::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) :
|
HbaseClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) :
|
||||||
piprot_(iprot),
|
piprot_(iprot),
|
||||||
poprot_(oprot) {
|
poprot_(oprot) {
|
||||||
iprot_ = iprot.get();
|
iprot_ = iprot.get();
|
||||||
oprot_ = oprot.get();
|
oprot_ = oprot.get();
|
||||||
}
|
}
|
||||||
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() {
|
std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() {
|
||||||
return piprot_;
|
return piprot_;
|
||||||
}
|
}
|
||||||
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() {
|
std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() {
|
||||||
return poprot_;
|
return poprot_;
|
||||||
}
|
}
|
||||||
void enableTable(const Bytes& tableName);
|
void enableTable(const Bytes& tableName);
|
||||||
@ -6158,15 +6158,15 @@ class HbaseClient : virtual public HbaseIf {
|
|||||||
void send_getRegionInfo(const Text& row);
|
void send_getRegionInfo(const Text& row);
|
||||||
void recv_getRegionInfo(TRegionInfo& _return);
|
void recv_getRegionInfo(TRegionInfo& _return);
|
||||||
protected:
|
protected:
|
||||||
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_;
|
std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_;
|
||||||
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_;
|
std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_;
|
||||||
::apache::thrift::protocol::TProtocol* iprot_;
|
::apache::thrift::protocol::TProtocol* iprot_;
|
||||||
::apache::thrift::protocol::TProtocol* oprot_;
|
::apache::thrift::protocol::TProtocol* oprot_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HbaseProcessor : public ::apache::thrift::TDispatchProcessor {
|
class HbaseProcessor : public ::apache::thrift::TDispatchProcessor {
|
||||||
protected:
|
protected:
|
||||||
boost::shared_ptr<HbaseIf> iface_;
|
std::shared_ptr<HbaseIf> iface_;
|
||||||
virtual bool dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext);
|
virtual bool dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext);
|
||||||
private:
|
private:
|
||||||
typedef void (HbaseProcessor::*ProcessFunction)(int32_t, ::apache::thrift::protocol::TProtocol*, ::apache::thrift::protocol::TProtocol*, void*);
|
typedef void (HbaseProcessor::*ProcessFunction)(int32_t, ::apache::thrift::protocol::TProtocol*, ::apache::thrift::protocol::TProtocol*, void*);
|
||||||
@ -6216,7 +6216,7 @@ class HbaseProcessor : public ::apache::thrift::TDispatchProcessor {
|
|||||||
void process_getRowOrBefore(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
|
void process_getRowOrBefore(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
|
||||||
void process_getRegionInfo(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
|
void process_getRegionInfo(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
|
||||||
public:
|
public:
|
||||||
HbaseProcessor(boost::shared_ptr<HbaseIf> iface) :
|
HbaseProcessor(std::shared_ptr<HbaseIf> iface) :
|
||||||
iface_(iface) {
|
iface_(iface) {
|
||||||
processMap_["enableTable"] = &HbaseProcessor::process_enableTable;
|
processMap_["enableTable"] = &HbaseProcessor::process_enableTable;
|
||||||
processMap_["disableTable"] = &HbaseProcessor::process_disableTable;
|
processMap_["disableTable"] = &HbaseProcessor::process_disableTable;
|
||||||
@ -6268,24 +6268,24 @@ class HbaseProcessor : public ::apache::thrift::TDispatchProcessor {
|
|||||||
|
|
||||||
class HbaseProcessorFactory : public ::apache::thrift::TProcessorFactory {
|
class HbaseProcessorFactory : public ::apache::thrift::TProcessorFactory {
|
||||||
public:
|
public:
|
||||||
HbaseProcessorFactory(const ::boost::shared_ptr< HbaseIfFactory >& handlerFactory) :
|
HbaseProcessorFactory(const std::shared_ptr< HbaseIfFactory >& handlerFactory) :
|
||||||
handlerFactory_(handlerFactory) {}
|
handlerFactory_(handlerFactory) {}
|
||||||
|
|
||||||
::boost::shared_ptr< ::apache::thrift::TProcessor > getProcessor(const ::apache::thrift::TConnectionInfo& connInfo);
|
std::shared_ptr< ::apache::thrift::TProcessor > getProcessor(const ::apache::thrift::TConnectionInfo& connInfo);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
::boost::shared_ptr< HbaseIfFactory > handlerFactory_;
|
std::shared_ptr< HbaseIfFactory > handlerFactory_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HbaseMultiface : virtual public HbaseIf {
|
class HbaseMultiface : virtual public HbaseIf {
|
||||||
public:
|
public:
|
||||||
HbaseMultiface(std::vector<boost::shared_ptr<HbaseIf> >& ifaces) : ifaces_(ifaces) {
|
HbaseMultiface(std::vector<std::shared_ptr<HbaseIf> >& ifaces) : ifaces_(ifaces) {
|
||||||
}
|
}
|
||||||
virtual ~HbaseMultiface() {}
|
virtual ~HbaseMultiface() {}
|
||||||
protected:
|
protected:
|
||||||
std::vector<boost::shared_ptr<HbaseIf> > ifaces_;
|
std::vector<std::shared_ptr<HbaseIf> > ifaces_;
|
||||||
HbaseMultiface() {}
|
HbaseMultiface() {}
|
||||||
void add(boost::shared_ptr<HbaseIf> iface) {
|
void add(std::shared_ptr<HbaseIf> iface) {
|
||||||
ifaces_.push_back(iface);
|
ifaces_.push_back(iface);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
@ -12,8 +12,6 @@ using namespace ::apache::thrift::protocol;
|
|||||||
using namespace ::apache::thrift::transport;
|
using namespace ::apache::thrift::transport;
|
||||||
using namespace ::apache::thrift::server;
|
using namespace ::apache::thrift::server;
|
||||||
|
|
||||||
using boost::shared_ptr;
|
|
||||||
|
|
||||||
using namespace ::apache::hadoop::hbase::thrift;
|
using namespace ::apache::hadoop::hbase::thrift;
|
||||||
|
|
||||||
class HbaseHandler : virtual public HbaseIf {
|
class HbaseHandler : virtual public HbaseIf {
|
||||||
@ -241,11 +239,11 @@ class HbaseHandler : virtual public HbaseIf {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int port = 9090;
|
int port = 9090;
|
||||||
shared_ptr<HbaseHandler> handler(new HbaseHandler());
|
std::shared_ptr<HbaseHandler> handler(new HbaseHandler());
|
||||||
shared_ptr<TProcessor> processor(new HbaseProcessor(handler));
|
std::shared_ptr<TProcessor> processor(new HbaseProcessor(handler));
|
||||||
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
|
std::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
|
||||||
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
|
std::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
|
||||||
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
|
std::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
|
||||||
|
|
||||||
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
|
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
|
||||||
server.serve();
|
server.serve();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user