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:
Alexander Myasnikov 2020-05-27 14:02:30 -07:00 committed by Bharath Vissapragada
parent 1e86ff09d7
commit 60c125367b
5 changed files with 34 additions and 38 deletions

View File

@ -57,11 +57,10 @@ Example code.
3. Execute {perl DemoClient.pl}.
* CPP: hbase-examples/src/main/cpp/DemoClient.cpp
1. Make sure you have boost and 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/.
Boost can be found at http://www.boost.org/users/download/.
1. Make sure you have Thrift C++ libraries; modify Makefile if necessary.
The recent (0.13.0 as of this writing) version of Thrift can be downloaded from http://thrift.apache.org/download/.
2. Execute {make}.
3. Execute {./DemoClient}.
3. Execute {./DemoClient <host> <port>}.
ON PROTOBUFS
This maven module has core protobuf definition files ('.protos') used by hbase

View File

@ -23,7 +23,6 @@
#include <iostream>
#include <boost/lexical_cast.hpp>
#include <protocol/TBinaryProtocol.h>
#include <transport/TSocket.h>
#include <transport/TTransportUtils.h>
@ -79,15 +78,15 @@ main(int argc, char** argv)
return -1;
}
bool isFramed = false;
boost::shared_ptr<TTransport> socket(new TSocket(argv[1], boost::lexical_cast<int>(argv[2])));
boost::shared_ptr<TTransport> transport;
std::shared_ptr<TTransport> socket = std::make_shared<TSocket>(argv[1], std::stoi(argv[2]));
std::shared_ptr<TTransport> transport;
if (isFramed) {
transport.reset(new TFramedTransport(socket));
transport = std::make_shared<TFramedTransport>(socket);
} 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
HbaseClient client(protocol);
@ -240,10 +239,10 @@ main(int argc, char** argv)
mutations.clear();
mutations.push_back(Mutation());
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.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.getRow(rowResult, t, row, dummyAttributes);
printRow(rowResult);

View File

@ -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_);
::boost::shared_ptr< HbaseIf > handler(handlerFactory_->getHandler(connInfo), cleanup);
::boost::shared_ptr< ::apache::thrift::TProcessor > processor(new HbaseProcessor(handler));
std::shared_ptr< HbaseIf > handler(handlerFactory_->getHandler(connInfo), cleanup);
std::shared_ptr< ::apache::thrift::TProcessor > processor(new HbaseProcessor(handler));
return processor;
}
}}}} // namespace

View File

@ -72,7 +72,7 @@ class HbaseIfFactory {
class HbaseIfSingletonFactory : virtual public HbaseIfFactory {
public:
HbaseIfSingletonFactory(const boost::shared_ptr<HbaseIf>& iface) : iface_(iface) {}
HbaseIfSingletonFactory(const std::shared_ptr<HbaseIf>& iface) : iface_(iface) {}
virtual ~HbaseIfSingletonFactory() {}
virtual HbaseIf* getHandler(const ::apache::thrift::TConnectionInfo&) {
@ -81,7 +81,7 @@ class HbaseIfSingletonFactory : virtual public HbaseIfFactory {
virtual void releaseHandler(HbaseIf* /* handler */) {}
protected:
boost::shared_ptr<HbaseIf> iface_;
std::shared_ptr<HbaseIf> iface_;
};
class HbaseNull : virtual public HbaseIf {
@ -6010,22 +6010,22 @@ class Hbase_getRegionInfo_presult {
class HbaseClient : virtual public HbaseIf {
public:
HbaseClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) :
HbaseClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) :
piprot_(prot),
poprot_(prot) {
iprot_ = 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),
poprot_(oprot) {
iprot_ = iprot.get();
oprot_ = oprot.get();
}
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() {
std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() {
return piprot_;
}
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() {
std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() {
return poprot_;
}
void enableTable(const Bytes& tableName);
@ -6158,15 +6158,15 @@ class HbaseClient : virtual public HbaseIf {
void send_getRegionInfo(const Text& row);
void recv_getRegionInfo(TRegionInfo& _return);
protected:
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_;
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_;
std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_;
std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_;
::apache::thrift::protocol::TProtocol* iprot_;
::apache::thrift::protocol::TProtocol* oprot_;
};
class HbaseProcessor : public ::apache::thrift::TDispatchProcessor {
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);
private:
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_getRegionInfo(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext);
public:
HbaseProcessor(boost::shared_ptr<HbaseIf> iface) :
HbaseProcessor(std::shared_ptr<HbaseIf> iface) :
iface_(iface) {
processMap_["enableTable"] = &HbaseProcessor::process_enableTable;
processMap_["disableTable"] = &HbaseProcessor::process_disableTable;
@ -6268,24 +6268,24 @@ class HbaseProcessor : public ::apache::thrift::TDispatchProcessor {
class HbaseProcessorFactory : public ::apache::thrift::TProcessorFactory {
public:
HbaseProcessorFactory(const ::boost::shared_ptr< HbaseIfFactory >& handlerFactory) :
HbaseProcessorFactory(const std::shared_ptr< HbaseIfFactory >& 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:
::boost::shared_ptr< HbaseIfFactory > handlerFactory_;
std::shared_ptr< HbaseIfFactory > handlerFactory_;
};
class HbaseMultiface : virtual public HbaseIf {
public:
HbaseMultiface(std::vector<boost::shared_ptr<HbaseIf> >& ifaces) : ifaces_(ifaces) {
HbaseMultiface(std::vector<std::shared_ptr<HbaseIf> >& ifaces) : ifaces_(ifaces) {
}
virtual ~HbaseMultiface() {}
protected:
std::vector<boost::shared_ptr<HbaseIf> > ifaces_;
std::vector<std::shared_ptr<HbaseIf> > ifaces_;
HbaseMultiface() {}
void add(boost::shared_ptr<HbaseIf> iface) {
void add(std::shared_ptr<HbaseIf> iface) {
ifaces_.push_back(iface);
}
public:

View File

@ -12,8 +12,6 @@ using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using boost::shared_ptr;
using namespace ::apache::hadoop::hbase::thrift;
class HbaseHandler : virtual public HbaseIf {
@ -241,11 +239,11 @@ class HbaseHandler : virtual public HbaseIf {
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<HbaseHandler> handler(new HbaseHandler());
shared_ptr<TProcessor> processor(new HbaseProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
std::shared_ptr<HbaseHandler> handler(new HbaseHandler());
std::shared_ptr<TProcessor> processor(new HbaseProcessor(handler));
std::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
std::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
std::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();