提交 9dd6b395 编写于 作者: G groot

refine code


Former-commit-id: 67d36b9a87addf76364175af90d4f05ab85bc7e5
上级 397d1cfc
......@@ -13,6 +13,7 @@
#include "thrift/gen-cpp/VectorService_constants.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TJSONProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/server/TThreadPoolServer.h>
#include <thrift/transport/TServerSocket.h>
......@@ -112,18 +113,20 @@ void ServiceWrapper::StartService() {
::apache::thrift::stdcxx::shared_ptr<VecServiceHandler> handler(new VecServiceHandler());
::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new VecServiceProcessor(handler));
::apache::thrift::stdcxx::shared_ptr<TServerTransport> serverTransport(new TServerSocket(address, port));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory;
if(protocol == "binary") {
protocolFactory.reset(new TBinaryProtocolFactory());
} else if(protocol == "json") {
protocolFactory.reset(new TJSONProtocolFactory());
}
if(mode == "simple") {
::apache::thrift::stdcxx::shared_ptr<TServerTransport> serverTransport(new TServerSocket(address, port));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
s_server.reset(new TSimpleServer(processor, serverTransport, transportFactory, protocolFactory));
s_server->serve();
} else if(mode == "thread_pool") {
::apache::thrift::stdcxx::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
::apache::thrift::stdcxx::shared_ptr<ThreadManager> threadManager(ThreadManager::newSimpleThreadManager(1));
::apache::thrift::stdcxx::shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory());
threadManager->threadFactory(threadFactory);
......
......@@ -21,6 +21,7 @@ set(service_files
add_executable(test_client
./main.cpp
../src/server/ServerConfig.cpp
${client_src}
${service_files}
${config_files}
......
......@@ -4,13 +4,57 @@
* Proprietary and confidential.
******************************************************************************/
#include "ClientApp.h"
#include "server/ServerConfig.h"
#include "utils/CommonUtil.h"
#include <iostream>
#include <yaml-cpp/yaml.h>
#include "thrift/gen-cpp/VecService.h"
#include "thrift/gen-cpp/VectorService_types.h"
#include "thrift/gen-cpp/VectorService_constants.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TJSONProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/server/TThreadPoolServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/concurrency/PosixThreadFactory.h>
namespace zilliz {
namespace vecwise {
namespace client {
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::concurrency;
void ClientApp::Run(const std::string &config_file) {
server::ServerConfig& config = server::ServerConfig::GetInstance();
config.LoadConfigFile(config_file);
server::ConfigNode server_config = config.GetConfig(server::CONFIG_SERVER);
std::string address = server_config.GetValue(server::CONFIG_SERVER_ADDRESS, "127.0.0.1");
int32_t port = server_config.GetInt32Value(server::CONFIG_SERVER_PORT, 33001);
std::string protocol = server_config.GetValue(server::CONFIG_SERVER_PROTOCOL, "binary");
std::string mode = server_config.GetValue(server::CONFIG_SERVER_MODE, "thread_pool");
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory;
if(protocol == "binary") {
protocolFactory.reset(new TBinaryProtocolFactory());
} else if(protocol == "json") {
protocolFactory.reset(new TJSONProtocolFactory());
}
if(mode == "simple") {
} else if(mode == "thread_pool") {
} else {
server::CommonUtil::PrintError("Server mode: " + mode + " is not supported currently");
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册