support http1, change file name same to taf

pull/53/head
ruanshudong 2020-04-01 20:29:29 +08:00
parent 0703a8f644
commit 6d5f517be7
120 changed files with 3120 additions and 5421 deletions

View File

@ -18,6 +18,10 @@ if("${TARS_CPP_COMMON}" STREQUAL "")
endif()
set(CLEAR_INCLUDE "clear-install.cmake")
FILE(WRITE ${CLEAR_INCLUDE} "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_INSTALL_PREFIX}/include)\n")
install(SCRIPT ${CLEAR_INCLUDE})
#-------------------------------------------------------------------
include_directories(${PROJECT_SOURCE_DIR}/util/include)

View File

@ -21,11 +21,18 @@ foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/bin)
endforeach()
set(_USE_OPENTRACKING $ENV{_USE_OPENTRACKING})
if(_USE_OPENTRACKING)
set(OPENTRACKING_INC "/usr/local/include")
add_definitions(-D_USE_OPENTRACKING=${_USE_OPENTRACKING})
endif()
option(TARS_OPENTRACKING "option for open tracking" OFF)
if (TARS_OPENTRACKING)
add_definitions(-DTARS_OPENTRACKING=1)
set(OPENTRACKING_INC "/usr/local/include")
endif ()
# set(TARS_OPENTRACKING $ENV{TARS_OPENTRACKING})
# if(TARS_OPENTRACKING)
# set(OPENTRACKING_INC "/usr/local/include")
# add_definitions(-D_USE_OPENTRACKING=${TARS_OPENTRACKING})
# endif()
#-------------------------------------------------------------
@ -88,5 +95,7 @@ message("PLATFORM: ${PLATFORM}")
message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message("BIN: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message("TARS2CPP: ${TARS2CPP}")
message("TARS_OPENTRACKING: ${TARS_OPENTRACKING}")
#-------------------------------------------------------------

View File

@ -153,7 +153,7 @@ int main(int argc, char *argv[])
conf.parseFile(option.getValue("config"));
_comm->setProperty(conf);
// TarsRollLogger::getInstance()->logger()->setLogLevel(6);
// LocalRollLogger::getInstance()->logger()->setLogLevel(6);
_comm->setProperty("sendqueuelimit", "1000000");
_comm->setProperty("asyncqueuecap", "1000000");

View File

@ -14,7 +14,7 @@ add_subdirectory(QuickStartDemo)
add_subdirectory(StressDemo)
add_subdirectory(UdpDemo)
set(WORKING_DIRECTORY ${tars-cpp_SOURCE_DIR})
set(WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
if(WIN32)
@ -22,28 +22,28 @@ if(WIN32)
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS QuickStartDemo QuickStartDemoClient
USES_TERMINAL
COMMAND examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call quick start")
add_custom_target(run-http
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS HttpServer HttpClient
USES_TERMINAL
COMMAND examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run http")
add_custom_target(run-auth
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS AuthServer AuthClient
USES_TERMINAL
COMMAND examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run auth")
add_custom_target(run-udp
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS UdpServer UdpClient
USES_TERMINAL
COMMAND examples/scripts/run-udp.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-udp.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run udp")
if(TARS_HTTP2)
@ -51,7 +51,7 @@ if(WIN32)
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS Http2Server Http2Client
USES_TERMINAL
COMMAND examples/scripts/run-http2.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-http2.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run http2")
endif()
@ -60,7 +60,7 @@ if(WIN32)
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS SSLServer SSLClient
USES_TERMINAL
COMMAND examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run ssl")
endif()
@ -68,21 +68,21 @@ if(WIN32)
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro
USES_TERMINAL
COMMAND examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run co")
add_custom_target(run-custom
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS CustomServer CustomClient
USES_TERMINAL
COMMAND examples/scripts/run-custom.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-custom.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run custom")
add_custom_target(run-push
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS PushServer PushClient
USES_TERMINAL
COMMAND examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run push")
if(TARS_SSL)
@ -90,23 +90,23 @@ if(WIN32)
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient SSLServer SSLClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
USES_TERMINAL
COMMAND examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-ssl.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run all")
else()
add_custom_target(run-all
WORKING_DIRECTORY ${WORKING_DIRECTORY}
USES_TERMINAL
DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
COMMAND examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-quick-start.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-http.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-co.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-push.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-auth.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run all")
endif()
@ -114,39 +114,39 @@ if(WIN32)
add_custom_target(run-kill
WORKING_DIRECTORY ${WORKING_DIRECTORY}
USES_TERMINAL
COMMAND examples/scripts/run-kill.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND ../examples/scripts/run-kill.bat ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run kill")
else(WIN32)
add_custom_target(run-quick-start
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS QuickStartDemo QuickStartDemoClient
COMMAND sh examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call quick start")
add_custom_target(run-http
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS HttpServer HttpClient
COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run http")
add_custom_target(run-udp
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS UdpServer UdpClient
COMMAND sh examples/scripts/run-udp.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-udp.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run udp")
add_custom_target(run-auth
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS AuthServer AuthClient
COMMAND sh examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run auth")
if(TARS_HTTP2)
add_custom_target(run-http2
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS Http2Server Http2Client
COMMAND sh examples/scripts/run-http2.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-http2.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run http2")
endif()
@ -154,53 +154,53 @@ else(WIN32)
add_custom_target(run-ssl
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS SSLServer SSLClient
COMMAND sh examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run ssl")
endif()
add_custom_target(run-co
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro
COMMAND sh examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run co")
add_custom_target(run-custom
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS CustomServer CustomClient
COMMAND sh examples/scripts/run-custom.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-custom.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run custom")
add_custom_target(run-push
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS PushServer PushClient
COMMAND sh examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run push")
if(TARS_SSL)
add_custom_target(run-all
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient SSLServer SSLClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
COMMAND sh examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-ssl.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run all")
else()
add_custom_target(run-all
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS QuickStartDemo QuickStartDemoClient HttpServer HttpClient AuthServer AuthClient CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro PushServer PushClient
COMMAND sh examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-quick-start.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-http.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-co.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-push.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-auth.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run all")
endif()
add_custom_target(run-kill
WORKING_DIRECTORY ${WORKING_DIRECTORY}
COMMAND sh examples/scripts/run-kill.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMAND sh ../examples/scripts/run-kill.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${WORKING_DIRECTORY}
COMMENT "call run kill")
endif(WIN32)

View File

@ -188,7 +188,7 @@ int main(int argc, char *argv[])
param.pPrx = _comm->stringToProxy<BServantPrx>(coroObj);
// TarsRollLogger::getInstance()->logger()->setLogLevel(6);
// LocalRollLogger::getInstance()->logger()->setLogLevel(6);
_comm->setProperty("sendqueuelimit", "1000000");
_comm->setProperty("asyncqueuecap", "1000000");

View File

@ -198,7 +198,7 @@ int main(int argc, char *argv[])
param.servantPrx = _comm->stringToProxy<ServantPrx>(sObjName);
// TarsRollLogger::getInstance()->logger()->setLogLevel(6);
// LocalRollLogger::getInstance()->logger()->setLogLevel(6);
ProxyProtocol prot;
prot.requestFunc = customRequest;
prot.responseFunc = customResponse;

View File

@ -45,25 +45,26 @@ void syncRpc2(int c)
{
int64_t t = TC_Common::now2us();
std::map<std::string, std::string> header;
header[":authority"] = "domain.com";
header[":scheme"] = "http";
// header[":method"] = "POST";
std::map<std::string, std::string> rheader;
//发起远程调用
for (int i = 0; i < c; ++i)
{
string rbody;
shared_ptr<TC_HttpResponse> rsp;
shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
req->setPostRequest("http://domain.com/hello", string("helloworld-") + TC_Common::tostr(i), true);
try
{
param.servant2Prx->http_call("hello", req, rsp);
}
catch (exception & e)
{
cout << "exception:" << e.what() << endl;
}
assert(req->getContent() == rsp->getContent());
assert(req.use_count() == 1);
assert(rsp.use_count() == 1);
try
{
param.servant2Prx->http_call("POST", "/", header, "helloworld", rheader, rbody);
}
catch(exception& e)
{
cout << "exception:" << e.what() << endl;
}
++callback_count;
}
@ -71,30 +72,22 @@ void syncRpc2(int c)
cout << "syncRpc2 total:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
}
struct TestHttpCallback : public HttpCallback
{
TestHttpCallback(int64_t t, int i, int c) : start(t), cur(i), count(c)
TestHttpCallback(const string &buff) : _buff(buff)
{
}
virtual int onHttpResponse(const std::map<std::string, std::string>& requestHeaders ,
const std::map<std::string, std::string>& responseHeaders ,
const std::vector<char>& rspBody)
virtual int onHttpResponse(const shared_ptr<TC_HttpResponse> &rsp)
{
callback_count++;
if(cur == count-1)
{
int64_t cost = TC_Common::now2us() - start;
cout << "onHttpResponse count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl;
}
assert(_buff == rsp->getContent());
return 0;
}
virtual int onHttpResponseException(const std::map<std::string, std::string>& requestHeaders,
int expCode)
virtual int onHttpResponseException(int expCode)
{
cout << "onHttpResponseException expCode:" << expCode << endl;
@ -103,27 +96,26 @@ struct TestHttpCallback : public HttpCallback
return 0;
}
int64_t start;
int cur;
int count;
string _buff;
};
void asyncRpc2(int c)
{
int64_t t = TC_Common::now2us();
std::map<std::string, std::string> header;
header[":authority"] = "domain.com";
header[":scheme"] = "http";
//发起远程调用
for (int i = 0; i < c; ++i)
{
HttpCallbackPtr p = new TestHttpCallback(t, i, c);
shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
string buff = string("helloworld-") + TC_Common::tostr(i);
req->setPostRequest("http://domain.com/hello", buff, true);
HttpCallbackPtr p = new TestHttpCallback(buff);
try
{
param.servant2Prx->http_call_async("POST", "/", header, "helloworld", p);
param.servant2Prx->http_call_async("hello", req, p);
}
catch(exception& e)
{
@ -140,6 +132,7 @@ void asyncRpc2(int c)
cout << "asyncRpc2 send:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
}
int main(int argc, char *argv[])
{
try
@ -173,11 +166,7 @@ int main(int argc, char *argv[])
param.servant2Prx->tars_connect_timeout(5000);
param.servant2Prx->tars_async_timeout(60*1000);
ProxyProtocol proto;
proto.requestFunc = ProxyProtocol::http2Request;
proto.responseFunc = ProxyProtocol::http2Response;
param.servant2Prx->tars_set_protocol(proto);
param.servant2Prx->tars_set_protocol(ServantProxy::PROTOCOL_HTTP2);
int64_t start = TC_Common::now2us();

View File

@ -57,6 +57,8 @@ int Http2Imp::doRequest(TarsCurrentPtr current, vector<char> &buffer)
{
cout << "encodeResponse error:" << session->getErrMsg() << endl;
}
// cout << context->request.getContent() << endl;
buffer.insert(buffer.end(), data.begin(), data.end());
}

View File

@ -1,38 +1,23 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

#include <iostream>
#include "util/tc_http.h"
#include "util/tc_option.h"
#include "util/tc_common.h"
#include "util/tc_clientsocket.h"
#include "util/tc_thread_pool.h"
#include "tup/Tars.h"
#include "tup/tup.h"
// #include "tup/tup.h"
#include "util/tc_timeprovider.h"
#include "servant/Application.h"
using namespace std;
using namespace tars;
using namespace tup;
// using namespace wup;
Communicator* _comm;
//static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 127.0.0.1 -p 8081";
static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 134.175.105.92 -p 8081";
//static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 127.0.0.1 -p 8081:tcp -h 127.0.0.1 -p 8082:tcp -h 127.0.0.1 -p 8083";
static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 127.0.0.1 -p 8081";
//static string httpObj = "TestApp.HttpServer.httpObj@tcp -h 134.175.105.92 -p 8081";
struct Param
{
@ -46,198 +31,272 @@ struct Param
Param param;
std::atomic<int> callback_count(0);
void httpCall(int excut_num)
{
int64_t _iTime = TC_TimeProvider::getInstance()->getNowMs();
int64_t _iTime = TC_TimeProvider::getInstance()->getNowMs();
// string sServer1("http://134.175.105.92:8081/");
string sServer1("http://127.0.0.1:8081/");
// string sServer1("http://134.175.105.92:8081/");
string sServer1("http://127.0.0.1:8081/");
TC_HttpRequest stHttpReq;
stHttpReq.setCacheControl("no-cache");
TC_HttpRequest stHttpReq;
stHttpReq.setCacheControl("no-cache");
// stHttpReq.setGetRequest(sServer1);
TC_TCPClient client ;
// client.init("127.0.0.1", 8081, 3000);
client.init("127.0.0.1", 8082, 3000);
TC_TCPClient client ;
// client.init("127.0.0.1", 8081, 3000);
client.init("127.0.0.1", 8082, 3000);
int iRet = 0;
int iRet = 0;
for (int i = 0; i<excut_num; i++)
{
TC_HttpResponse stHttpRsp;
for (int i = 0; i<excut_num; i++)
{
TC_HttpResponse stHttpRsp;
stHttpReq.setPostRequest(sServer1, TC_Common::tostr(i), true);
iRet = stHttpReq.doRequest(stHttpRsp, 3000);
// iRet = stHttpReq.doRequest(client,stHttpRsp);
if (iRet != 0)
{
cout <<"pthread id: " << TC_Thread::CURRENT_THREADID() << ", iRet:" << iRet <<endl;
}
++callback_count;
}
cout << "httpCall, succ:" << param.count << "/" << excut_num << ", " << TC_TimeProvider::getInstance()->getNowMs() - _iTime <<"(ms)"<<endl;
stHttpReq.setPostRequest(sServer1, TC_Common::tostr(i), true);
iRet = stHttpReq.doRequest(stHttpRsp, 3000);
// iRet = stHttpReq.doRequest(client,stHttpRsp);
if (iRet != 0)
{
cout <<"pthread id: " << TC_Thread::CURRENT_THREADID() << ", iRet:" << iRet <<endl;
}
++callback_count;
}
cout << "httpCall, succ:" << param.count << "/" << excut_num << ", " << TC_TimeProvider::getInstance()->getNowMs() - _iTime <<"(ms)"<<endl;
}
struct TestHttpCallback : public HttpCallback
{
TestHttpCallback(int64_t t, int i, int c) : start(t), cur(i), count(c)
{
}
virtual int onHttpResponse(const std::map<std::string, std::string>& requestHeaders ,
const std::map<std::string, std::string>& responseHeaders ,
const std::vector<char>& rspBody)
{
callback_count++;
if(cur == count-1)
{
int64_t cost = TC_Common::now2us() - start;
cout << "onHttpResponse count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl;
}
return 0;
}
virtual int onHttpResponseException(const std::map<std::string, std::string>& requestHeaders,
int expCode)
{
cout << "onHttpResponseException expCode:" << expCode << endl;
callback_count++;
return 0;
}
int64_t start;
int cur;
int count;
};
void syncRpc(int c)
{
int64_t t = TC_Common::now2us();
std::map<std::string, std::string> header;
//发起远程调用
for (int i = 0; i < c; ++i)
{
string buff = string("helloworld-") + TC_Common::tostr(i);
shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
req->setPostRequest("http://tars.com/hello", buff, true);
// req->setHeader("Connection", "keep-alive");
std::map<std::string, std::string> rheader;
//发起远程调用
for (int i = 0; i < c; ++i)
{
string rbody;
shared_ptr<TC_HttpResponse> rsp;
try
{
param.servantPrx->http_call("GET", "/", header, "helloworld", rheader, rbody);
}
catch(exception& e)
{
cout << "exception:" << e.what() << endl;
}
++callback_count;
}
try
{
param.servantPrx->tars_hash(i)->http_call("hello", req, rsp);
assert(req->getContent() == rsp->getContent());
}
catch(exception& e)
{
cout << "exception:" << e.what() << endl;
}
int64_t cost = TC_Common::now2us() - t;
cout << "syncCall total:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
// sleep(1);
// assert(req.use_count() == 1);
// assert(rsp.use_count() == 1);
++callback_count;
}
int64_t cost = TC_Common::now2us() - t;
cout << "syncCall total:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
}
struct TestHttpCallback : public HttpCallback
{
TestHttpCallback(const string &buff) : _buff(buff)
{
}
virtual int onHttpResponse(const shared_ptr<TC_HttpResponse> &rsp)
{
callback_count++;
assert(_buff == rsp->getContent());
return 0;
}
virtual int onHttpResponseException(int expCode)
{
cout << "onHttpResponseException expCode:" << expCode << endl;
callback_count++;
return 0;
}
string _buff;
};
void asyncRpc(int c)
{
int64_t t = TC_Common::now2us();
//发起远程调用
for (int i = 0; i < c; ++i)
{
shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
string buff = string("helloworld-") + TC_Common::tostr(i);
req->setPostRequest("http://tars.com/hello", buff, true);
// req->setHeader("Connection", "keep-alive");
HttpCallbackPtr p = new TestHttpCallback(buff);
try
{
param.servantPrx->http_call_async("hello", req, p);
}
catch(exception& e)
{
cout << "exception:" << e.what() << endl;
}
if(i % 500 == 0)
{
TC_Common::msleep(100);
}
}
int64_t cost = TC_Common::now2us() - t;
cout << "asyncRpc2 send:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
}
void asyncRpcCallback(int c)
{
int64_t t = TC_Common::now2us();
_comm->setServantCustomCallback(param.servantPrx->tars_name(), [](ReqMessagePtr msg) {
msg->callback->dispatch(msg);
});
//发起远程调用
for (int i = 0; i < c; ++i)
{
shared_ptr<TC_HttpRequest> req = std::make_shared<TC_HttpRequest>();
string buff = string("helloworld-") + TC_Common::tostr(i);
req->setPostRequest("http://tars.com/hello", buff, true);
// req->setHeader("Connection", "keep-alive");
HttpCallbackPtr p = new TestHttpCallback(buff);
try
{
param.servantPrx->http_call_async("hello", req, p);
}
catch(exception& e)
{
cout << "exception:" << e.what() << endl;
}
if(i % 500 == 0)
{
TC_Common::msleep(100);
}
}
int64_t cost = TC_Common::now2us() - t;
cout << "asyncRpc2 send:" << cost << "us, avg:" << 1.*cost/c << "us" << endl;
}
int main(int argc, char *argv[])
{
try
{
if (argc < 4)
{
cout << "Usage:" << argv[0] << "--count=1000 --call=[basehttp|synchttp] --thread=1" << endl;
try
{
if (argc < 4)
{
cout << "Usage:" << argv[0] << "--count=1000 --call=[base|sync|async|callback] --thread=1" << endl;
return 0;
}
return 0;
}
TC_Option option;
option.decode(argc, argv);
TC_Option option;
option.decode(argc, argv);
param.count = TC_Common::strto<int>(option.getValue("count"));
if(param.count <= 0) param.count = 1000;
param.call = option.getValue("call");
if(param.call.empty()) param.call = "sync";
param.thread = TC_Common::strto<int>(option.getValue("thread"));
if(param.thread <= 0) param.thread = 1;
/*
if(param.count <= 0) param.count = 1000;
param.call = option.getValue("call");
if(param.call.empty()) param.call = "sync";
param.thread = TC_Common::strto<int>(option.getValue("thread"));
if(param.thread <= 0) param.thread = 1;
_comm = new Communicator();
// TarsRollLogger::getInstance()->logger()->setLogLevel(6);
// LocalRollLogger::getInstance()->logger()->setLogLevel(6);
_comm->setProperty("sendqueuelimit", "1000000");
_comm->setProperty("asyncqueuecap", "1000000");
param.servantPrx = _comm->stringToProxy<ServantPrx>(httpObj);
param.servantPrx = _comm->stringToProxy<ServantPrx>(httpObj);
param.servantPrx->tars_connect_timeout(5000);
param.servantPrx->tars_async_timeout(60*1000);
int64_t start = TC_Common::now2us();
ProxyProtocol proto;
proto.requestFunc = ProxyProtocol::http1Request;
proto.responseFunc = ProxyProtocol::http1Response;
param.servantPrx->tars_set_protocol(proto);
*/
int64_t start = TC_Common::now2us();
std::function<void(int)> func;
std::function<void(int)> func;
if (param.call == "base")
{
func = httpCall;
}
else if (param.call == "sync")
{
func = syncRpc;
}
else if(param.call == "async")
{
func = asyncRpc;
}
else if(param.call == "callback")
{
func = asyncRpcCallback;
}
else
{
cout << "no func, exits" << endl;
exit(0);
}
if (param.call == "basehttp")
{
func = httpCall;
}
else if (param.call == "synchttp")
{
func = syncRpc;
}
// else if(param.call == "asynchttp")
// {
// func = asyncRpc;
// }
else
{
cout << "no func, exits" << endl;
exit(0);
}
param.servantPrx->tars_connect_timeout(5000);
param.servantPrx->tars_async_timeout(60*1000);
vector<std::thread*> vt;
for(int i = 0 ; i< param.thread; i++)
{
vt.push_back(new std::thread(func, param.count));
}
param.servantPrx->tars_set_protocol(ServantProxy::PROTOCOL_HTTP1, 3);
std::thread print([&]{while(callback_count != param.count * param.thread) {
cout << "Http:" << param.call << ": ----------finish count:" << callback_count << endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
};});
vector<std::thread*> vt;
for(int i = 0 ; i< param.thread; i++)
{
vt.push_back(new std::thread(func, param.count));
}
for(size_t i = 0 ; i< vt.size(); i++)
{
vt[i]->join();
delete vt[i];
}
std::thread print([&]{while(callback_count != param.count * param.thread) {
cout << "Http:" << param.call << ": ----------finish count:" << callback_count << endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
};});
cout << "(pid:" << std::this_thread::get_id() << ")"
<< "(count:" << param.count << ")"
<< "(use ms:" << (TC_Common::now2us() - start)/1000 << ")"
<< endl;
for(size_t i = 0 ; i< vt.size(); i++)
{
vt[i]->join();
delete vt[i];
}
while(callback_count != param.count * param.thread) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
print.join();
cout << "----------finish count:" << callback_count << endl;
}
catch(exception &ex)
{
cout << ex.what() << endl;
}
cout << "main return." << endl;
cout << "(pid:" << std::this_thread::get_id() << ")"
<< "(count:" << param.count << ")"
<< "(use ms:" << (TC_Common::now2us() - start)/1000 << ")"
<< endl;
return 0;
while(callback_count != param.count * param.thread) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
print.join();
cout << "----------finish count:" << callback_count << endl;
delete _comm;
_comm = NULL;
}
catch(exception &ex)
{
cout << ex.what() << endl;
}
cout << "main return." << endl;
return 0;
}

View File

@ -35,17 +35,17 @@ void HttpImp::destroy()
int HttpImp::doRequest(TarsCurrentPtr current, vector<char> &buffer)
{
TC_HttpRequest request;
vector<char> v = current->getRequestBuffer();
string sBuf;
sBuf.assign(v.data(),v.size());
TC_HttpRequest request;
vector<char> v = current->getRequestBuffer();
request.decode(current->getRequestBuffer());
request.decode(sBuf);
// cout << request.getContent() << endl;
TC_HttpResponse rsp;
string s="hello";
string s=request.getContent();
rsp.setResponse(s.c_str(),s.size());
rsp.setHeader("Connection", request.getHeader("Connection"));
rsp.encode(buffer);
return 0;
}

View File

@ -300,7 +300,7 @@ int main(int argc, char *argv[])
_comm->setProperty("netthread", TC_Common::tostr(param.netthread));
// TarsRollLogger::getInstance()->logger()->setLogLevel(6);
// LocalRollLogger::getInstance()->logger()->setLogLevel(6);
param.pPrx = _comm->stringToProxy<HelloPrx>(helloObj);

View File

@ -23,28 +23,28 @@
#module name
modulename = TestApp.SSLClient
#server crt
ca = ./examples/SSLDemo/certs/server.crt
ca = ../examples/SSLDemo/certs/server.crt
#can be empty
cert = ./examples/SSLDemo/certs/client.crt
cert = ../examples/SSLDemo/certs/client.crt
#can be empty
key = ./examples/SSLDemo/certs/client.key
key = ../examples/SSLDemo/certs/client.key
<TestApp.SSLServer.SSL1Obj>
#server crt
ca = ./examples/SSLDemo/certs/server1.crt
ca = ../examples/SSLDemo/certs/server1.crt
#can be empty
# cert = ./examples/SSLDemo/certs/client1.crt
# cert = ../examples/SSLDemo/certs/client1.crt
#can be empty
# key = ./examples/SSLDemo/certs/client1.key
# key = ../examples/SSLDemo/certs/client1.key
</TestApp.SSLServer.SSL1Obj>
<TestApp.SSLServer.SSL2Obj>
#server crt
ca = ./examples/SSLDemo/certs/server1.crt
ca = ../examples/SSLDemo/certs/server1.crt
#can be empty
cert = ./examples/SSLDemo/certs/client1.crt
cert = ../examples/SSLDemo/certs/client1.crt
#can be empty
key = ./examples/SSLDemo/certs/client1.key
key = ../examples/SSLDemo/certs/client1.key
</TestApp.SSLServer.SSL2Obj>
<TestApp.SSLServer.SSL3Obj>
@ -53,11 +53,11 @@
#auth secret key
secretkey = 123456
#server crt
ca = ./examples/SSLDemo/certs/server1.crt
ca = ../examples/SSLDemo/certs/server1.crt
#can be empty
cert = ./examples/SSLDemo/certs/client1.crt
cert = ../examples/SSLDemo/certs/client1.crt
#can be empty
key = ./examples/SSLDemo/certs/client1.key
key = ../examples/SSLDemo/certs/client1.key
</TestApp.SSLServer.SSL3Obj>
</client>
</application>

View File

@ -162,7 +162,7 @@ int main(int argc, char *argv[])
conf.parseFile(option.getValue("config"));
_comm->setProperty(conf);
// TarsRollLogger::getInstance()->logger()->setLogLevel(6);
// LocalRollLogger::getInstance()->logger()->setLogLevel(6);
_comm->setProperty("sendqueuelimit", "1000000");
_comm->setProperty("asyncqueuecap", "1000000");

View File

@ -52,9 +52,9 @@
# log = tars.tarslog.LogObj
#client crt, it can be empty when verifyclient is 0
ca = ./examples/SSLDemo/certs/client.crt
cert = ./examples/SSLDemo/certs/server.crt
key = ./examples/SSLDemo/certs/server.key
ca = ../examples/SSLDemo/certs/client.crt
cert = ../examples/SSLDemo/certs/server.crt
key = ../examples/SSLDemo/certs/server.key
#default is 0
verifyclient = 1
@ -90,9 +90,9 @@
queuecap = 1000000
#tars protocol
protocol = tars
# ca = ./examples/SSLDemo/certs/client1.crt
cert = ./examples/SSLDemo/certs/server1.crt
key = ./examples/SSLDemo/certs/server1.key
# ca = ../examples/SSLDemo/certs/client1.crt
cert = ../examples/SSLDemo/certs/server1.crt
key = ../examples/SSLDemo/certs/server1.key
#default is 0
verifyclient = 0
</Hello1Adapter>
@ -112,9 +112,9 @@
queuecap = 1000000
#tars protocol
protocol = tars
ca = ./examples/SSLDemo/certs/client1.crt
cert = ./examples/SSLDemo/certs/server1.crt
key = ./examples/SSLDemo/certs/server1.key
ca = ../examples/SSLDemo/certs/client1.crt
cert = ../examples/SSLDemo/certs/server1.crt
key = ../examples/SSLDemo/certs/server1.key
#default is 0
verifyclient = 1
</Hello2Adapter>
@ -138,9 +138,9 @@
accesskey = tars-test-user
#auth secret key
secretkey = 123456
ca = ./examples/SSLDemo/certs/client1.crt
cert = ./examples/SSLDemo/certs/server1.crt
key = ./examples/SSLDemo/certs/server1.key
ca = ../examples/SSLDemo/certs/client1.crt
cert = ../examples/SSLDemo/certs/server1.crt
key = ../examples/SSLDemo/certs/server1.key
#default is 0
verifyclient = 1
</Hello3Adapter>

View File

@ -2,7 +2,7 @@
echo "run-auth.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -3,7 +3,7 @@
echo "run-auth.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@
echo "run-co.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -3,7 +3,7 @@
echo "run-co.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@
echo "run-push.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -3,7 +3,7 @@
echo "run-custom.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@
echo "run-http.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -3,7 +3,7 @@
echo "run-http.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}
@ -18,7 +18,9 @@ sleep 1
echo "client: ${EXE_PATH}/HttpClient"
${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=basehttp
${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=base
${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=sync
${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=async
#${EXE_PATH}/HttpClient --count=10000 --thread=2 --call=synchttp
sleep 1

View File

@ -2,7 +2,7 @@
echo "run-http2.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -2,7 +2,7 @@
echo "run-http2.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@
echo "run-push.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -2,7 +2,7 @@
echo "run-co.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@
echo "run-quick-start.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -2,7 +2,7 @@
echo "run-quick-start.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@
echo "run-ssl.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -2,7 +2,7 @@
echo "run-ssl.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@
echo "run-auth.bat"
set EXE_PATH=%1
set SRC_PATH=%2
set SRC_PATH=%2\\..
echo %EXE_PATH% %SRC_PATH%

View File

@ -3,7 +3,7 @@
echo "run-auth.sh"
EXE_PATH=$1
SRC_PATH=$2
SRC_PATH=$2/..
echo ${EXE_PATH} ${SRC_PATH}

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.2)
project(servant)
if(_USE_OPENTRACKING)
if(TARS_OPENTRACKING)
include_directories(${util_SOURCE_DIR}/include ${OPENTRACKING_INC})
else()
include_directories(${util_SOURCE_DIR}/include)

View File

@ -20,13 +20,13 @@
#include "servant/Application.h"
#include "servant/AdminF.h"
#include "servant/AppCache.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "tup/tup.h"
#include "servant/StatF.h"
#include "servant/StatReport.h"
#include "util/tc_http2.h"
// #include "util/tc_http2clientmgr.h"
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
#include "servant/text_map_carrier.h"
#endif
@ -50,11 +50,11 @@ AdapterProxy::AdapterProxy(ObjectProxy * pObjectProxy,const EndpointInfo &ep,Com
, _connTimeout(false)
, _connExc(false)
, _connExcCnt(0)
, _staticWeight(0)
//, _staticWeight(0)
, _timeoutLogFlag(false)
, _noSendQueueLimit(1000)
, _maxSampleCount(1000)
, _sampleRate(0)
//, _maxSampleCount(1000)
//, _sampleRate(0)
, _id((++_idGen))
{
_timeoutQueue.reset(new TC_TimeoutQueueNew<ReqMessage*>());
@ -64,10 +64,10 @@ AdapterProxy::AdapterProxy(ObjectProxy * pObjectProxy,const EndpointInfo &ep,Com
_noSendQueueLimit = pObjectProxy->getCommunicatorEpoll()->getNoSendQueueLimit();
}
if(_communicator)
{
_timeoutLogFlag = _communicator->getTimeoutLogFlag();
}
// if(_communicator)
// {
// _timeoutLogFlag = pObjectProxy->getCommunicatorEpoll()->getTimeoutLogFlag();
// }
if (ep.isTcp())
{
@ -92,7 +92,6 @@ AdapterProxy::~AdapterProxy()
// adapterProxy->checkActive(true);
// return adapterProxy;
//}
string AdapterProxy::getSlaveName(const string& sSlaveName)
{
string::size_type pos = sSlaveName.find(".");
@ -110,66 +109,113 @@ string AdapterProxy::getSlaveName(const string& sSlaveName)
void AdapterProxy::initStatHead()
{
vector <string> v;
if(!ClientConfig::SetDivision.empty() &&
StatReport::divison2SetInfo(ClientConfig::SetDivision, v)) //主调(client)启用set
{
_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "." + v[0] + v[1] + v[2] + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
}
else
{
_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
}
const string sSlaveName = getSlaveName(_objectProxy->name());
string sSlaveSet = _endpoint.setDivision();
if(!sSlaveSet.empty() &&
StatReport::divison2SetInfo(sSlaveSet, v)) //被调启用set
{
_statHead.slaveSetName = v[0];
_statHead.slaveSetArea = v[1];
_statHead.slaveSetID = v[2];
_statHead.slaveName = StatReport::trimAndLimitStr(sSlaveName + "." + v[0] + v[1] + v[2], StatReport::MAX_MASTER_NAME_LEN);
}
else
{
_statHead.slaveName = StatReport::trimAndLimitStr(sSlaveName, StatReport::MAX_MASTER_NAME_LEN);
}
vector <string> v;
if(!ClientConfig::SetDivision.empty() &&
StatReport::divison2SetInfo(ClientConfig::SetDivision, v)) //主调(client)启用set
{
_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "." + v[0] + v[1] + v[2] + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
}
else
{
_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
}
_statHead.slaveIp = StatReport::trimAndLimitStr(_endpoint.host(), StatReport::MAX_MASTER_IP_LEN);
_statHead.slavePort = _endpoint.port();
_statHead.returnValue = 0;
const string sSlaveName = getSlaveName(_objectProxy->name());
string sSlaveSet = _endpoint.setDivision();
if(!sSlaveSet.empty() &&
StatReport::divison2SetInfo(sSlaveSet, v)) //被调启用set
{
_statHead.slaveSetName = v[0];
_statHead.slaveSetArea = v[1];
_statHead.slaveSetID = v[2];
_statHead.slaveName = StatReport::trimAndLimitStr(sSlaveName + "." + v[0] + v[1] + v[2], StatReport::MAX_MASTER_NAME_LEN);
}
else
{
_statHead.slaveName = StatReport::trimAndLimitStr(sSlaveName, StatReport::MAX_MASTER_NAME_LEN);
}
_statHead.slaveIp = StatReport::trimAndLimitStr(_endpoint.host(), StatReport::MAX_MASTER_IP_LEN);
_statHead.slavePort = _endpoint.port();
_statHead.returnValue = 0;
}
int AdapterProxy::invoke(ReqMessage * msg)
//bool AdapterProxy::invoke_sync(ReqMessage * msg)
//{
// if(!_trans->hasConnected()) {
// TLOGTARS("[TARS][AdapterProxy::invoke_sync " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
// return false;
// }
//
// //生成requestid
// //taf调用 而且 不是单向调用
// if (!msg->bFromRpc)
// {
// // msg->request.iRequestId = _objectProxy->generateId();
// msg->request.iRequestId = _timeoutQueue->generateId();
// }
//
// msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans));
//
// msg->response = std::make_shared<ResponsePacket>();
//
// //这里得加锁
// std::lock_guard<std::mutex> lock(_mutex);
//
// _trans->sendRecv(msg);
//
// return true;
//}
void AdapterProxy::onConnect()
{
assert(_trans != NULL);
_objectProxy->onConnect(this);
}
TLOGTARS("[TARS][AdapterProxy::invoke objname:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << endl);
int AdapterProxy::invoke_connection_serial(ReqMessage * msg)
{
assert(msg->eType != ReqMessage::ONE_WAY);
//未发链表有长度限制
if(_timeoutQueue->getSendListSize() >= _noSendQueueLimit)
{
TLOGERROR("[TARS][AdapterProxy::invoke fail,ReqInfoQueue.size > " << _noSendQueueLimit << ",objname:" << _objectProxy->name() <<",desc:"<< _endpoint.desc() << endl);
msg->eStatus = ReqMessage::REQ_EXC;
msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
finishInvoke(msg);
msg->request.iRequestId = _timeoutQueue->generateId();
return 0;
}
if(!_requestMsg && _timeoutQueue->sendListEmpty() && _trans->sendRequest(msg->sReqData) != Transceiver::eRetError)
{
TLOGTARS("[TARS][AdapterProxy::invoke push (send) obj: " << _objectProxy->name() << ", desc:" << _endpoint.desc() << ", id: " << msg->request.iRequestId << endl);
//生成requestid
//tars调用 而且 不是单向调用
if(!msg->bFromRpc)
{
msg->request.iRequestId = _timeoutQueue->generateId();
}
_requestMsg = msg;
#ifdef _USE_OPENTRACKING
startTrack(msg);
#endif
bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime);
if (!bFlag)
{
TLOGERROR("[TARS][AdapterProxy::invoke fail1 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ",id: " << msg->request.iRequestId << "," << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
msg->eStatus = ReqMessage::REQ_EXC;
msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
finishInvoke(msg);
}
}
else
{
TLOGTARS("[TARS][AdapterProxy::invoke push (no send) " << _objectProxy->name() << ", " << _endpoint.desc() << ",id " << msg->request.iRequestId << endl);
//之前还没有数据没发送 或者 请求发送失败了, 进队列
bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime, false);
if (!bFlag)
{
TLOGERROR("[TARS][AdapterProxy::invoke fail2 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ", id: " << msg->request.iRequestId << ", " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
msg->eStatus = ReqMessage::REQ_EXC;
finishInvoke(msg);
}
}
return 0;
}
int AdapterProxy::invoke_connection_parallel(ReqMessage * msg)
{
msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
// TLOGERROR("[TARS][AdapterProxy::invoke insert timeout queue fail, queue size:" << _timeoutQueue->size() << ", id:" << msg->request.iRequestId << ", obj:" <<_objectProxy->name() << ", desc:" << _endpoint.desc() <<endl);
@ -181,7 +227,7 @@ int AdapterProxy::invoke(ReqMessage * msg)
//请求发送成功了,单向调用直接返回
if(msg->eType == ReqMessage::ONE_WAY)
{
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
finishTrack(msg);
#endif
@ -218,24 +264,121 @@ int AdapterProxy::invoke(ReqMessage * msg)
}
}
#ifdef _USE_OPENTRACKING
if(msg->eType == ReqMessage::ONE_WAY)
{
finishTrack(msg);
}
#endif
return 0;
return 0;
}
void AdapterProxy::doInvoke()
int AdapterProxy::invoke(ReqMessage * msg)
{
while(!_timeoutQueue->sendListEmpty())
assert(_trans != NULL);
TLOGTARS("[TARS][AdapterProxy::invoke " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
//未发链表有长度限制
if (_timeoutQueue->getSendListSize() >= _noSendQueueLimit)
{
ReqMessage * msg = NULL;
TLOGERROR("[TARS][AdapterProxy::invoke fail,ReqInfoQueue.size>" << _noSendQueueLimit << "," << _objectProxy->name() << "," << _endpoint.desc() << "]" << endl);
msg->eStatus = ReqMessage::REQ_EXC;
_timeoutQueue->getSend(msg);
finishInvoke(msg);
return 0;
}
int iRet = _trans->sendRequest(msg->sReqData);
//生成requestid
//taf调用 而且 不是单向调用
if (!msg->bFromRpc)
{
msg->request.iRequestId = _timeoutQueue->generateId();
}
if(_objectProxy->getServantProxy()->tars_connection_serial() > 0)
{
invoke_connection_serial(msg);
}
else
{
invoke_connection_parallel(msg);
}
//
// msg->sReqData->setBuffer(_objectProxy->getProxyProtocol().requestFunc(msg->request, _trans.get()));
//
// //当前队列是空的, 且是连接复用模式, 交给连接发送数据
// //连接连上 buffer不为空 发送数据成功
// if (_timeoutQueue->sendListEmpty() && _trans->sendRequest(msg->sReqData) != Transceiver::eRetError)
// {
// TLOGTARS("[TARS][AdapterProxy::invoke push (send) obj: " << _objectProxy->name() << ", desc:" << _endpoint.desc() << ", id: " << msg->request.iRequestId << endl);
//
// //请求发送成功了 处理采样
// //这个请求发送成功了。单向调用直接返回
// if (msg->eType == ReqMessage::ONE_WAY)
// {
// delete msg;
// msg = NULL;
//
// return 0;
// }
//
// bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime);
// if (!bFlag)
// {
// TLOGERROR("[TARS][AdapterProxy::invoke fail1 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ",id: " << msg->request.iRequestId << "," << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
// msg->eStatus = ReqMessage::REQ_EXC;
//
// finishInvoke(msg);
// }
// }
// else
// {
// TLOGTARS("[TARS][AdapterProxy::invoke push (no send) " << _objectProxy->name() << ", " << _endpoint.desc() << ",id " << msg->request.iRequestId << endl);
//
// //之前还没有数据没发送 或者 请求发送失败了, 进队列
// bool bFlag = _timeoutQueue->push(msg, msg->request.iRequestId, msg->request.iTimeout + msg->iBeginTime, false);
// if (!bFlag)
// {
// TLOGERROR("[TARS][AdapterProxy::invoke fail2 : insert timeout queue fail,queue size:" << _timeoutQueue->size() << ", id: " << msg->request.iRequestId << ", " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
// msg->eStatus = ReqMessage::REQ_EXC;
//
// finishInvoke(msg);
// }
// }
return 0;
}
void AdapterProxy::doInvoke_serial()
{
assert(_requestMsg == NULL);
if(!_timeoutQueue->sendListEmpty())
{
ReqMessage * msg = NULL;
_timeoutQueue->getSend(msg);
int iRet = _trans->sendRequest(msg->sReqData);
//发送失败 返回
if (iRet == Transceiver::eRetError)
{
TLOGTARS("[TARS][AdapterProxy::doInvoke sendRequest failed, obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id:" << msg->request.iRequestId << ", ret:" << iRet << endl);
return;
}
//送send 队列中清掉, 但是保留在定时队列中
_timeoutQueue->popSend(false);
_requestMsg = msg;
}
}
void AdapterProxy::doInvoke_parallel()
{
while(!_timeoutQueue->sendListEmpty())
{
ReqMessage * msg = NULL;
_timeoutQueue->getSend(msg);
int iRet = _trans->sendRequest(msg->sReqData);
//发送失败 返回
if(iRet == Transceiver::eRetError)
@ -243,7 +386,6 @@ void AdapterProxy::doInvoke()
TLOGTARS("[TARS][AdapterProxy::doInvoke sendRequest failed, obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id:" << msg->request.iRequestId << ", ret:" << iRet << endl);
return;
}
TLOGTARS("[TARS][AdapterProxy::doInvoke sendRequest obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id:" << msg->request.iRequestId << ",ret:" << iRet << endl);
//请求发送成功了 处理采样
//...
@ -264,6 +406,20 @@ void AdapterProxy::doInvoke()
}
}
void AdapterProxy::doInvoke(bool initInvoke)
{
if(_objectProxy->getServantProxy()->tars_connection_serial() > 0)
{
if(initInvoke)
{
doInvoke_serial();
}
}
else
{
doInvoke_parallel();
}
}
void AdapterProxy::finishInvoke(bool bFail)
{
@ -375,7 +531,13 @@ int AdapterProxy::getConTimeout()
bool AdapterProxy::checkActive(bool bForceConnect, bool onlyCheck)
{
time_t now = TNOW;
if(onlyCheck)
{
return _trans->hasConnected();
}
else
{
time_t now = TNOW;
TLOGTARS("[TARS][AdapterProxy::checkActive objname:" << _objectProxy->name()
<< ",desc:" << _endpoint.desc()
@ -452,10 +614,11 @@ bool AdapterProxy::checkActive(bool bForceConnect, bool onlyCheck)
}
}
return _trans->hasConnected();
//已经建立连接了才返回
return _trans->hasConnected();
}
}
void AdapterProxy::setConTimeout(bool bConTimeout)
{
if(bConTimeout != _connTimeout)
@ -469,24 +632,70 @@ void AdapterProxy::setConTimeout(bool bConTimeout)
}
}
void AdapterProxy::onSetInactive()
{
_activeStatus = false;
_nextRetryTime = TNOW + _objectProxy->checkTimeoutInfo().tryTimeInterval;
//需要关闭连接
_trans->close();
}
//屏蔽结点
void AdapterProxy::setInactive()
{
_activeStatus = false;
onSetInactive();
_nextRetryTime = TNOW + _objectProxy->checkTimeoutInfo().tryTimeInterval;
_objectProxy->getServantProxy()->onSetInactive(_endpoint);
_trans->close();
TLOGTARS("[TARS][AdapterProxy::setInactive objname:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",inactive" << endl);
TLOGTARS("[TARS][AdapterProxy::setInactive, " << _objectProxy->name() << ", " << _endpoint.desc() << ", inactive]" << endl);
}
void AdapterProxy::finishInvoke(shared_ptr<ResponsePacket> & rsp)
void AdapterProxy::finishInvoke_serial(shared_ptr<ResponsePacket> & rsp)
{
// TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket) obj:" << _objectProxy->name() << ", desc:" << _endpoint.desc()
// << ", id:" << rsp->iRequestId << endl);
TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket), " << _objectProxy->name() << ", " << _endpoint.desc() << ", id:" << rsp->iRequestId << "]" << endl);
ReqMessage * msg = NULL;
if (!_requestMsg)
{
if(_timeoutLogFlag)
{
TLOGERROR("[TARS][AdapterProxy::finishInvoke(ResponsePacket),"
<< _objectProxy->name()
<< ",get req-ptr NULL,may be timeout,id:"
<< rsp->iRequestId << ",desc:" << _endpoint.desc() << "]" << endl);
}
return;
}
ReqMessage * msg = _requestMsg;
//这里的队列中的发送链表中的数据可能已经在timeout的时候删除了因此可能会core在erase中要加判断
//获取请求信息
bool retErase = _timeoutQueue->erase(_requestMsg->request.iRequestId, msg);
assert(retErase);
assert(_requestMsg == msg);
assert(msg->eType != ReqMessage::ONE_WAY);
assert(msg->eStatus == ReqMessage::REQ_REQ);
_requestMsg = NULL;
msg->eStatus = ReqMessage::REQ_RSP;
msg->response = rsp;
finishInvoke(msg);
//检查连接状态
checkActive();
}
void AdapterProxy::finishInvoke_parallel(shared_ptr<ResponsePacket> & rsp)
{
TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket), " << _objectProxy->name() << ", " << _endpoint.desc() << ", id:" << rsp->iRequestId << "]" << endl);
ReqMessage * msg = NULL;
//requestid 为0 是push消息
if(rsp->iRequestId == 0)
@ -534,6 +743,70 @@ void AdapterProxy::finishInvoke(shared_ptr<ResponsePacket> & rsp)
finishInvoke(msg);
}
void AdapterProxy::finishInvoke(shared_ptr<ResponsePacket> & rsp)
{
TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket), " << _objectProxy->name() << ", " << _endpoint.desc() << ", id:" << rsp->iRequestId << "]" << endl);
if(_objectProxy->getServantProxy()->tars_connection_serial() > 0)
{
finishInvoke_serial(rsp);
}
else
{
finishInvoke_parallel(rsp);
}
//
// ReqMessage * msg = NULL;
//
// if (rsp->iRequestId == 0)
// {
// //requestid 为0 是push消息
// //
// //push callback is null
// if (!_objectProxy->getPushCallback())
// {
// TLOGERROR("[TARS][AdapterProxy::finishInvoke(ResponsePacket) request id is 0, pushcallback is null, " << _objectProxy->name() << ", " << _endpoint.desc() << "]" << endl);
// return;
// }
// msg = new ReqMessage();
// msg->eStatus = ReqMessage::REQ_RSP;
// msg->eType = ReqMessage::ASYNC_CALL;
// msg->bFromRpc = true;
// msg->bPush = true;
// msg->proxy = _objectProxy->getServantProxy();
// msg->pObjectProxy = _objectProxy;
// msg->adapter = this;
// msg->callback = _objectProxy->getPushCallback();
// }
// else
// {
// //这里的队列中的发送链表中的数据可能已经在timeout的时候删除了因此可能会core在erase中要加判断
// //获取请求信息
// bool retErase = _timeoutQueue->erase(rsp->iRequestId, msg);
//
// //找不到此id信息
// if (!retErase)
// {
// if (_timeoutLogFlag)
// {
// TLOGERROR("[TARS][AdapterProxy::finishInvoke(ResponsePacket),"
// << _objectProxy->name()
// << ",get req-ptr NULL,may be timeout,id:"
// << rsp->iRequestId << ",desc:" << _endpoint.desc() << "]" << endl);
// }
// return ;
// }
//
// assert(msg->eStatus == ReqMessage::REQ_REQ);
//
// msg->eStatus = ReqMessage::REQ_RSP;
// }
//
// msg->response = rsp;
//
// finishInvoke(msg);
}
void AdapterProxy::finishInvoke(ReqMessage * msg)
{
assert(msg->eStatus != ReqMessage::REQ_REQ);
@ -543,7 +816,7 @@ void AdapterProxy::finishInvoke(ReqMessage * msg)
<< ", status:" << msg->eStatus
<< ", ret: " << msg->response->iRet << endl);
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
finishTrack(msg);
#endif
@ -595,16 +868,14 @@ void AdapterProxy::finishInvoke(ReqMessage * msg)
ReqMessagePtr msgPtr = msg;
try
{
msg->callback->onDispatch(msgPtr);
msg->callback->dispatch(msgPtr);
}
catch (exception & e)
{
//FDLOG("taferror")<<"[TAF]AdapterProxy::finishInvoke(ReqMessage) exp:"<<e.what()<<" ,line:"<<__LINE__<<endl;
TLOGERROR("[TAF]AdapterProxy::finishInvoke(ReqMessage) exp:" << e.what() << " ,line:" << __LINE__ << endl);
TLOGERROR("[TARS]AdapterProxy::finishInvoke(ReqMessage) exp:" << e.what() << " ,line:" << __LINE__ << endl);
}
catch (...)
{
//FDLOG("taferror")<<"[TAF]AdapterProxy::finishInvoke(ReqMessage) exp:unknown line:"<<__LINE__<<endl;
TLOGERROR("[TARS]AdapterProxy::finishInvoke(ReqMessage) exp:unknown line:|" << __LINE__ << endl);
}
}
@ -641,11 +912,6 @@ void AdapterProxy::finishInvoke(ReqMessage * msg)
return;
}
//ObjectProxy * AdapterProxy::getObjProxy()
//{
// return _objectProxy;
//}
void AdapterProxy::doTimeout()
{
ReqMessage * msg;
@ -653,7 +919,14 @@ void AdapterProxy::doTimeout()
{
TLOGTARS("[TARS][AdapterProxy::doTimeout obj:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id " << msg->request.iRequestId << endl);
assert(msg->eStatus == ReqMessage::REQ_REQ);
// assert(msg->eStatus == ReqMessage::REQ_REQ);
if(msg == _requestMsg)
{
_requestMsg = NULL;
//timeout, close
_trans->close();
}
msg->eStatus = ReqMessage::REQ_TIME;
@ -677,7 +950,7 @@ void AdapterProxy::doTimeout()
}
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
void AdapterProxy::startTrack(ReqMessage * msg)
{
if(!_communicator->_traceManager)
@ -784,7 +1057,7 @@ void AdapterProxy::stat(ReqMessage * msg)
_statBody[msg->request.sFuncName] = body;
}
if(LOG->isNeedLog(TarsRollLogger::INFO_LOG))
if(LOG->isNeedLog(LocalRollLogger::INFO_LOG))
{
ostringstream os;
os.str("");
@ -849,10 +1122,9 @@ void AdapterProxy::addConnExc(bool bExc)
{
if(!_connExc && _connExcCnt++ >= _objectProxy->checkTimeoutInfo().maxConnectExc)
{
if(!_connExc)
{
TLOGERROR("[TARS][AdapterProxy::addConnExc desc:"<< _endpoint.desc() << ",connect exception status is true! (connect error)"<<endl);
}
TLOGERROR("[TARS][AdapterProxy::addConnExc desc:"<< _endpoint.desc() << ",connect exception status is true! (connect error)"<<endl);
setInactive();
_connExc = true;
}

View File

@ -58,7 +58,7 @@ void AdminServant::shutdown(TarsCurrentPtr current)
string AdminServant::notify(const string &command, TarsCurrentPtr current)
{
TarsRemoteNotify::getInstance()->report("AdminServant::notify:" + command);
RemoteNotify::getInstance()->report("AdminServant::notify:" + command);
return NotifyObserver::getInstance()->notify(command, current);
}

View File

@ -19,7 +19,7 @@
#include "servant/AppProtocol.h"
#include "servant/Transceiver.h"
#include "servant/AdapterProxy.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "tup/Tars.h"
#include <iostream>
@ -60,64 +60,136 @@ vector<char> ProxyProtocol::tarsRequest(RequestPacket& request, Transceiver *)
vector<char> ProxyProtocol::http1Request(tars::RequestPacket& request, Transceiver *trans)
{
request.iRequestId = trans->getAdapterProxy()->getId();
// assert(trans->getAdapterProxy()->getObjProxy()->getServantProxy()->taf_connection_serial() > 0);
TC_HttpRequest httpRequest;
// request.iRequestId = trans->getAdapterProxy()->getId();
httpRequest.setRequest(request.sFuncName, request.sServantName, string(request.sBuffer.data(), request.sBuffer.size()), true);
shared_ptr<TC_HttpRequest> &data = *(shared_ptr<TC_HttpRequest>*)request.sBuffer.data();
vector<char> buffer;
vector<char> buffer;
httpRequest.encode(buffer);
data->encode(buffer);
return buffer;
data.reset();
return buffer;
}
struct Http1Context
{
// string buff;
TC_HttpResponse httpRsp;
};
TC_NetWorkBuffer::PACKET_TYPE ProxyProtocol::http1Response(TC_NetWorkBuffer &in, ResponsePacket& rsp)
{
Http1Context *context = (Http1Context*)(in.getContextData());
shared_ptr<TC_HttpResponse> *context = (shared_ptr<TC_HttpResponse>*)(in.getContextData());
if(context == NULL)
if(!context)
{
context = new Http1Context();
context = new shared_ptr<TC_HttpResponse>();
*context = std::make_shared<TC_HttpResponse>();
in.setContextData(context, [=]{ delete context; });
}
// context->buff.append(in.getBuffersString());
// in.clearBuffers();
if(context->httpRsp.incrementDecode(in))
if((*context)->incrementDecode(in))
{
rsp.iRequestId = ((Transceiver*)(in.getConnection()))->getAdapterProxy()->getId();
rsp.sBuffer.resize(sizeof(shared_ptr<TC_HttpResponse>));
rsp.status["status"] = context->httpRsp.getResponseHeaderLine();
for (const auto& kv : context->httpRsp.getHeaders())
{
rsp.status[kv.first] = kv.second;
}
shared_ptr<TC_HttpResponse> &data = *(shared_ptr<TC_HttpResponse>*)rsp.sBuffer.data();
rsp.sBuffer.assign(context->httpRsp.getContent().begin(), context->httpRsp.getContent().end());
data = *context;
delete context;
if(!data->checkHeader("Connection", "keep-alive"))
{
Transceiver* session = (Transceiver*)(in.getConnection());
context = NULL;
session->close();
}
in.setContextData(NULL);
(*context) = NULL;
delete context;
in.setContextData(NULL);
return TC_NetWorkBuffer::PACKET_FULL;
return TC_NetWorkBuffer::PACKET_FULL;
}
return TC_NetWorkBuffer::PACKET_LESS;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// vector<char> ProxyProtocol::httpJceRequest(taf::BasePacket& request, Transceiver *trans)
// {
// TC_HttpRequest httpRequest;
// string uri;
// if(trans->isSSL())
// uri = "https://";
// else
// uri = "http://";
// uri += trans->getEndpointInfo().getEndpoint().getHost();
// vector<char> buff = tafRequest(request, trans);
// for(auto it = request.context.begin(); it != request.context.end(); ++it)
// {
// if(it->second == ":path")
// {
// uri += "/" + it->second;
// }
// else
// {
// httpRequest.setHeader(it->first, it->second);
// }
// }
// httpRequest.setPostRequest(uri, buff.data(), buff.size(), true);
// vector<char> buffer;
// httpRequest.encode(buffer);
// return buffer;
// }
// TC_NetWorkBuffer::PACKET_TYPE ProxyProtocol::httpJceResponse(TC_NetWorkBuffer &in, BasePacket& rsp)
// {
// TC_HttpResponse *context = (TC_HttpResponse*)(in.getContextData());
// if(!context)
// {
// context = new TC_HttpResponse();
// in.setContextData(context, [=]{ delete context; });
// }
// if(context->incrementDecode(in))
// {
// if(context->getStatus() != 200)
// {
// rsp.iRet = taf::JCESERVERUNKNOWNERR;
// rsp.sResultDesc = context->getContent();
// return TC_NetWorkBuffer::PACKET_FULL;
// }
// JceInputStream<> is;
// is.setBuffer(context->getContent().c_str() + 4, context->getContent().size() - 4);
// rsp.readFrom(is);
// if(!context->checkHeader("Connection", "keep-alive"))
// {
// Transceiver* session = (Transceiver*)(in.getConnection());
// session->close();
// }
// context = NULL;
// delete context;
// in.setContextData(NULL);
// return TC_NetWorkBuffer::PACKET_FULL;
// }
// return TC_NetWorkBuffer::PACKET_LESS;
// }
#if TARS_HTTP2
// ENCODE function, called by network thread
@ -133,7 +205,13 @@ vector<char> ProxyProtocol::http2Request(RequestPacket& request, Transceiver *tr
session->settings(3000);
}
request.iRequestId = session->submit(request.sFuncName, request.sServantName, request.context, request.sBuffer);
shared_ptr<TC_HttpRequest> *data = (shared_ptr<TC_HttpRequest>*)request.sBuffer.data();
request.iRequestId = session->submit(*(*data).get());
//这里把智能指针释放一次
(*data).reset();
if (request.iRequestId < 0)
{
TLOGERROR("[TARS]http2Request::Fatal submit error: " << session->getErrMsg() << endl);
@ -156,8 +234,11 @@ TC_NetWorkBuffer::PACKET_TYPE ProxyProtocol::http2Response(TC_NetWorkBuffer &in,
if(flag == TC_NetWorkBuffer::PACKET_FULL)
{
rsp.iRequestId = out.first;
out.second->getHeaders(rsp.status);
rsp.sBuffer.assign(out.second->getContent().begin(), out.second->getContent().end());
rsp.sBuffer.resize(sizeof(shared_ptr<TC_HttpResponse>));
//这里智能指针有一次+1, 后面要自己reset掉
*(shared_ptr<TC_HttpResponse>*)rsp.sBuffer.data() = out.second;
}
return flag;

View File

@ -16,7 +16,7 @@
#include "util/tc_option.h"
#include "util/tc_common.h"
#include "servant/TarsNodeF.h"
#include "servant/KeepAliveNodeF.h"
#include "servant/Application.h"
#include "servant/AppProtocol.h"
#include "servant/AdminServant.h"
@ -95,6 +95,7 @@ std::string ServerConfig::CA;
std::string ServerConfig::Cert;
std::string ServerConfig::Key;
bool ServerConfig::VerifyClient = false;
std::string ServerConfig::Ciphers;
#endif
map<string, string> ServerConfig::Context;
@ -198,7 +199,7 @@ void Application::waitForShutdown()
destroyApp();
TarsRemoteNotify::getInstance()->report("stop");
RemoteNotify::getInstance()->report("stop");
std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
@ -302,7 +303,7 @@ bool Application::cmdSetLogLevel(const string& command, const string& params, st
string level = TC_Common::trim(params);
int ret = TarsRollLogger::getInstance()->logger()->setLogLevel(level);
int ret = LocalRollLogger::getInstance()->logger()->setLogLevel(level);
if(ret == 0)
{
@ -372,13 +373,13 @@ bool Application::cmdEnableDayLog(const string& command, const string& params, s
if(vParams[0] == "local")
{
TarsTimeLogger::getInstance()->enableLocal(sFile,bEnable);
RemoteTimeLogger::getInstance()->enableLocal(sFile,bEnable);
return true;
}
if(vParams[0] == "remote")
{
TarsTimeLogger::getInstance()->enableRemote(sFile,bEnable);
RemoteTimeLogger::getInstance()->enableRemote(sFile,bEnable);
return true;
}
@ -393,14 +394,14 @@ bool Application::cmdLoadConfig(const string& command, const string& params, str
string filename = TC_Common::trim(params);
if (TarsRemoteConfig::getInstance()->addConfig(filename, result,false))
if (RemoteConfig::getInstance()->addConfig(filename, result,false))
{
TarsRemoteNotify::getInstance()->report(result);
RemoteNotify::getInstance()->report(result);
return true;
}
TarsRemoteNotify::getInstance()->report(result);
RemoteNotify::getInstance()->report(result);
return true;
}
@ -453,6 +454,33 @@ bool Application::cmdViewVersion(const string& command, const string& params, st
return true;
}
bool Application::cmdViewBuildID(const string& command, const string& params, string& result)
{
#define YEARSUF ((__DATE__ [9] - '0') * 10 + (__DATE__ [10] - '0'))
#define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 0 : 5) \
: __DATE__ [2] == 'b' ? 1 \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \
: __DATE__ [2] == 'y' ? 4 \
: __DATE__ [2] == 'l' ? 6 \
: __DATE__ [2] == 'g' ? 7 \
: __DATE__ [2] == 'p' ? 8 \
: __DATE__ [2] == 't' ? 9 \
: __DATE__ [2] == 'v' ? 10 : 11)
#define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
+ (__DATE__ [5] - '0'))
#define TIMEINT ((((((__TIME__[0] - '0') * 10 + (__TIME__[1] - '0')) * 10 \
+ (__TIME__[3] - '0')) * 10 + (__TIME__[4] - '0')) * 10 \
+ (__TIME__[6] - '0')) * 10 + (__TIME__[7] - '0'))
char buildTime[50] = {0};
sprintf(buildTime, "%d.%02d%02d.%06d", YEARSUF, MONTH + 1, DAY, TIMEINT);
result = "$" + ServerConfig::Application + "." + ServerConfig::ServerName + "-" + string(buildTime) + "$";
return true;
}
bool Application::cmdLoadProperty(const string& command, const string& params, string& result)
{
try
@ -472,15 +500,15 @@ bool Application::cmdLoadProperty(const string& command, const string& params, s
//加载远程对象
ServerConfig::Log = _conf.get("/tars/application/server<log>");
TarsTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath,setDivision());
RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath,setDivision());
ServerConfig::Config = _conf.get("/tars/application/server<config>");
TarsRemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision(), 5);
RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision(), 5);
ServerConfig::Notify = _conf.get("/tars/application/server<notify>");
TarsRemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LocalIp, setDivision());
RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision());
result = "loaded config items:\r\n" + sResult +
"log=" + ServerConfig::Log + "\r\n" +
@ -591,7 +619,7 @@ bool Application::cmdViewResource(const string& command, const string& params, s
ostringstream os;
os << _communicator->getResouresInfo() << endl;
os << _communicator->getResourcesInfo() << endl;
os << OUT_LINE << endl;
@ -626,13 +654,13 @@ bool Application::addConfig(const string &filename)
{
string result;
if (TarsRemoteConfig::getInstance()->addConfig(filename, result, false))
if (RemoteConfig::getInstance()->addConfig(filename, result, false))
{
TarsRemoteNotify::getInstance()->report(result);
RemoteNotify::getInstance()->report(result);
return true;
}
TarsRemoteNotify::getInstance()->report(result);
RemoteNotify::getInstance()->report(result);
return true;
}
@ -642,15 +670,15 @@ bool Application::addAppConfig(const string &filename)
string result = "";
// true-只获取应用级别配置
if (TarsRemoteConfig::getInstance()->addConfig(filename, result, true))
if (RemoteConfig::getInstance()->addConfig(filename, result, true))
{
TarsRemoteNotify::getInstance()->report(result);
RemoteNotify::getInstance()->report(result);
return true;
}
TarsRemoteNotify::getInstance()->report(result);
RemoteNotify::getInstance()->report(result);
return true;
}
@ -723,7 +751,7 @@ void Application::main(const TC_Option &option)
catch (exception & ex)
{
keepActiving.detach();
TarsRemoteNotify::getInstance()->report("exit: " + string(ex.what()));
RemoteNotify::getInstance()->report("exit: " + string(ex.what()));
std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
cout << "[init exception]:" << ex.what() << endl;
@ -749,6 +777,9 @@ void Application::main(const TC_Option &option)
//查看编译的TARS版本
TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_VIEW_VERSION, Application::cmdViewVersion);
//查看服务buildid(编译时间)
TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_VIEW_BID, Application::cmdViewBuildID);
//加载配置文件中的属性信息
TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_LOAD_PROPERTY, Application::cmdLoadProperty);
@ -777,7 +808,7 @@ void Application::main(const TC_Option &option)
TARS_KEEPALIVE("");
//发送给notify表示服务启动了
TarsRemoteNotify::getInstance()->report("restart");
RemoteNotify::getInstance()->report("restart");
//ctrl + c能够完美结束服务
#if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS
@ -811,7 +842,7 @@ void Application::main(const TC_Option &option)
{
cout << "[main exception]:" << ex.what() << endl;
TarsRemoteNotify::getInstance()->report("exit: " + string(ex.what()));
RemoteNotify::getInstance()->report("exit: " + string(ex.what()));
std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
@ -819,7 +850,7 @@ void Application::main(const TC_Option &option)
}
//初始化完毕后, 日志再修改为异步
TarsRollLogger::getInstance()->sync(false);
LocalRollLogger::getInstance()->sync(false);
}
void Application::parseConfig(const TC_Option &op)
@ -971,12 +1002,12 @@ void Application::outServer(ostream &os)
os << TC_Common::outfill("BackPacketLimit(backpacketlimit)") << ServerConfig::BackPacketLimit<< endl;
os << TC_Common::outfill("BackPacketMin(backpacketmin)") << ServerConfig::BackPacketMin<< endl;
#if TAF_SSL
#if TARS_SSL
cout << TC_Common::outfill("Ca(ca)") << ServerConfig::CA << endl;
cout << TC_Common::outfill("Cert(cert)") << ServerConfig::Cert << endl;
cout << TC_Common::outfill("Key(key)") << ServerConfig::Key << endl;
cout << TC_Common::outfill("VerifyClient(verifyclient)") << ServerConfig::VerifyClient << endl;
// cout << TC_Common::outfill("Ciphers(ciphers)") << ServerConfig::Ciphers << endl;
cout << TC_Common::outfill("Ciphers(ciphers)") << ServerConfig::Ciphers << endl;
#endif
}
@ -1056,9 +1087,10 @@ void Application::initializeServer()
ServerConfig::Cert = _conf.get("/tars/application/server<cert>");
ServerConfig::Key = _conf.get("/tars/application/server<key>");
ServerConfig::VerifyClient = _conf.get("/tars/application/server<verifyclient>","0")=="0"?false:true;
ServerConfig::Ciphers = _conf.get("/tars/application/server<ciphers>");
if(!ServerConfig::Cert.empty()) {
_ctx = TC_OpenSSL::newCtx(ServerConfig::CA, ServerConfig::Cert, ServerConfig::Key, ServerConfig::VerifyClient);
_ctx = TC_OpenSSL::newCtx(ServerConfig::CA, ServerConfig::Cert, ServerConfig::Key, ServerConfig::VerifyClient, ServerConfig::Ciphers);
if (!_ctx) {
TLOGERROR("[TARS]load server ssl error, ca:" << ServerConfig::CA << endl);
@ -1120,11 +1152,11 @@ void Application::initializeServer()
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化本地Log
cout << OUT_LINE << "\n" << TC_Common::outfill("[set roll logger] ") << "OK" << endl;
TarsRollLogger::getInstance()->setLogInfo(ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, ServerConfig::LogSize, ServerConfig::LogNum, _communicator, ServerConfig::Log);
_epollServer->setLocalLogger(TarsRollLogger::getInstance()->logger());
LocalRollLogger::getInstance()->setLogInfo(ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, ServerConfig::LogSize, ServerConfig::LogNum, _communicator, ServerConfig::Log);
_epollServer->setLocalLogger(LocalRollLogger::getInstance()->logger());
//初始化是日志为同步
TarsRollLogger::getInstance()->sync(true);
LocalRollLogger::getInstance()->sync(true);
//设置日志级别
string level = AppCache::getInstance()->get("logLevel");
@ -1135,28 +1167,28 @@ void Application::initializeServer()
ServerConfig::LogLevel = TC_Common::upper(level);
TarsRollLogger::getInstance()->logger()->setLogLevel(ServerConfig::LogLevel);
LocalRollLogger::getInstance()->logger()->setLogLevel(ServerConfig::LogLevel);
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化到LogServer代理
cout << OUT_LINE << "\n" << TC_Common::outfill("[set time logger] ") << "OK" << endl;
bool bLogStatReport = (_conf.get("/tars/application/server<logstatreport>", "0") == "1") ? true : false;
TarsTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, setDivision(), bLogStatReport);
RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, setDivision(), bLogStatReport);
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化到配置中心代理
cout << OUT_LINE << "\n" << TC_Common::outfill("[set remote config] ") << "OK" << endl;
TarsRemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision());
RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision());
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化到信息中心代理
cout << OUT_LINE << "\n" << TC_Common::outfill("[set remote notify] ") << "OK" << endl;
TarsRemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision(), ServerConfig::LocalIp);
RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision());
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化到Node的代理
cout << OUT_LINE << "\n" << TC_Common::outfill("[set node proxy]") << "OK" << endl;
TarsNodeFHelper::getInstance()->setNodeInfo(_communicator, ServerConfig::Node, ServerConfig::Application, ServerConfig::ServerName);
KeepAliveNodeFHelper::getInstance()->setNodeInfo(_communicator, ServerConfig::Node, ServerConfig::Application, ServerConfig::ServerName);
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化管理对象
@ -1227,8 +1259,9 @@ void Application::setAdapter(TC_EpollServer::BindAdapterPtr& adapter, const stri
string key = _conf.get("/tars/application/server/" + name + "<key>");
bool verifyClient =
_conf.get("/tars/application/server/" + name + "<verifyclient>", "0") == "0" ? false : true;
string ciphers = _conf.get("/tars/application/server/" + name + "<ciphers>");
shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx(ca, cert, key, verifyClient);
shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx(ca, cert, key, verifyClient, ciphers);
if (!ctx) {
TLOGERROR("[TARS]load server ssl error, cert:" << cert << endl);
@ -1340,7 +1373,7 @@ void Application::checkServantNameValid(const string& servant, const string& sPr
os << "Servant '" << servant << "' error: must be start with '" << sPrefix << "'";
TarsRemoteNotify::getInstance()->report("exit:" + os.str());
RemoteNotify::getInstance()->report("exit:" + os.str());
std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复

View File

@ -17,7 +17,7 @@
#include "servant/AsyncProcThread.h"
#include "servant/Communicator.h"
#include "servant/StatReport.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
namespace tars
{
@ -119,7 +119,7 @@ void AsyncProcThread::callback(ReqMessage * msg)
try
{
ReqMessagePtr msgPtr = msg;
msg->callback->onDispatch(msgPtr);
msg->callback->dispatch(msgPtr);
}
catch (exception& e)
{

View File

@ -1,4 +1,4 @@
if(_USE_OPENTRACKING)
if(TARS_OPENTRACKING)
include_directories(${PROJECT_SOURCE_DIR} ${OPENTRACKING_INC})
else()
include_directories(${PROJECT_SOURCE_DIR})

View File

@ -18,7 +18,7 @@
#include "servant/Communicator.h"
#include "servant/Application.h"
#include "servant/StatReport.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
namespace tars
{
@ -46,7 +46,7 @@ Communicator::Communicator()
, _statReport(NULL)
, _timeoutLogFlag(true)
, _minTimeout(100)
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
, _traceManager(NULL)
#endif
{
@ -61,7 +61,7 @@ Communicator::Communicator(TC_Config& conf, const string& domain/* = CONFIG_ROOT
: _initialized(false)
, _terminating(false)
, _timeoutLogFlag(true)
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
, _traceManager(NULL)
#endif
{
@ -120,6 +120,13 @@ string Communicator::getServantProperty(const string &sObj, const string& name)
return "";
}
void Communicator::setServantCustomCallback(const string &sObj, Communicator::custom_callback callback)
{
TC_LockT<TC_SpinLock> lock(_callbackLock);
_callback[sObj] = callback;
}
#if TARS_SSL
shared_ptr<TC_OpenSSL> Communicator::newClientSSL(const string & objName)
{
@ -131,6 +138,10 @@ shared_ptr<TC_OpenSSL> Communicator::newClientSSL(const string & objName)
return TC_OpenSSL::newSSL(it->second);
}
if(!_ctx) {
_ctx = TC_OpenSSL::newCtx("", "", "", false, "");
}
return TC_OpenSSL::newSSL(_ctx);
}
@ -161,11 +172,13 @@ void Communicator::setProperty(TC_Config& conf, const string& domain/* = CONFIG_
data["ca"] = conf.get("/tars/application/client/" + auths[i] + "<ca>");
data["cert"] = conf.get("/tars/application/client/" + auths[i] + "<cert>");
data["key"] = conf.get("/tars/application/client/" + auths[i] + "<key>");
data["ciphers"] = conf.get("/tars/application/client/" + auths[i] + "<ciphers>");
#if TARS_SSL
if(!data["ca"].empty())
{
shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx( data["ca"], data["cert"], data["key"], false);
shared_ptr<TC_OpenSSL::CTX> ctx = TC_OpenSSL::newCtx( data["ca"], data["cert"], data["key"], false, data["ciphers"]);
if(!ctx)
{
TLOGERROR("[TARS]load obj:" << auths[i] << ", ssl error, ca:" << data["ca"] << endl);
@ -244,9 +257,10 @@ void Communicator::initialize()
string ca = getProperty("ca");
string cert = getProperty("cert");
string key = getProperty("key");
string ciphers = getProperty("ciphers");
if(!ca.empty()) {
_ctx = TC_OpenSSL::newCtx(ca, cert, key, false);
_ctx = TC_OpenSSL::newCtx(ca, cert, key, false, ciphers);
if(!_ctx)
{
@ -317,9 +331,9 @@ void Communicator::initialize()
int iReportTimeout = TC_Common::strto<int>(getProperty("report-timeout", "5000"));
int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
// int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
// int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
int iMaxReportSize = TC_Common::strto<int>(getProperty("max-report-size", "1400"));
@ -343,9 +357,9 @@ void Communicator::initialize()
}
string sSetDivision = ClientConfig::SetOpen?ClientConfig::SetDivision:"";
_statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, iSampleRate, iMaxSampleCount, iMaxReportSize, iReportTimeout);
_statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
#if _USE_OPENTRACKING
#if TARS_OPENTRACKING
string collector_host = getProperty("collector_host", "");
string collector_port = getProperty("collector_port", "");
if(!collector_host.empty() && !collector_port.empty())
@ -412,9 +426,9 @@ int Communicator::reloadProperty(string & sResult)
int iReportTimeout = TC_Common::strto<int>(getProperty("report-timeout", "5000"));
int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
// int iSampleRate = TC_Common::strto<int>(getProperty("sample-rate", "1000"));
int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
// int iMaxSampleCount = TC_Common::strto<int>(getProperty("max-sample-count", "100"));
int iMaxReportSize = TC_Common::strto<int>(getProperty("max-report-size", "1400"));
@ -437,15 +451,15 @@ int Communicator::reloadProperty(string & sResult)
}
string sSetDivision = ClientConfig::SetOpen?ClientConfig::SetDivision:"";
_statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, iSampleRate, iMaxSampleCount, iMaxReportSize, iReportTimeout);
_statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
sResult = "locator=" + getProperty("locator", "") + "\r\n" +
"stat=" + statObj + "\r\n" + "property=" + propertyObj + "\r\n" +
"SetDivision=" + sSetDivision + "\r\n" +
"report-interval=" + TC_Common::tostr(iReportInterval) + "\r\n" +
"report-timeout=" + TC_Common::tostr(iReportTimeout) + "\r\n" +
"sample-rate=" + TC_Common::tostr(iSampleRate) + "\r\n" +
"max-sample-count=" + TC_Common::tostr(iMaxSampleCount) + "\r\n";
"report-timeout=" + TC_Common::tostr(iReportTimeout) + "\r\n";
// "sample-rate=" + TC_Common::tostr(iSampleRate) + "\r\n" +
// "max-sample-count=" + TC_Common::tostr(iMaxSampleCount) + "\r\n";
return 0;
}
@ -462,13 +476,13 @@ vector<TC_Endpoint> Communicator::getEndpoint4All(const string & objName)
return pServantProxy->getEndpoint4All();
}
string Communicator::getResouresInfo()
string Communicator::getResourcesInfo()
{
ostringstream os;
for (size_t i = 0; i < _clientThreadNum; ++i)
{
os << OUT_LINE << endl;
os << _communicatorEpoll[i]->getResouresInfo();
os << _communicatorEpoll[i]->getResourcesInfo();
}
return os.str();
}
@ -542,8 +556,19 @@ void Communicator::terminate()
void Communicator::pushAsyncThreadQueue(ReqMessage * msg)
{
//先不考虑每个线程队列数目不一致的情况
_asyncThread[(_asyncSeq++)%_asyncThreadNum]->push_back(msg);
{
TC_LockT<TC_SpinLock> lock(_callbackLock);
auto it = _callback.find(msg->request.sServantName);
if (it != _callback.end()) {
ReqMessagePtr msgPtr = msg;
it->second(msgPtr);
return;
}
}
//先不考虑每个线程队列数目不一致的情况
_asyncThread[(_asyncSeq++) % _asyncThreadNum]->push_back(msg);
}
void Communicator::doStat()

View File

@ -17,7 +17,7 @@
#include "servant/CommunicatorEpoll.h"
#include "servant/Communicator.h"
#include "servant/Application.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "servant/StatReport.h"
using namespace std;
@ -388,7 +388,7 @@ void CommunicatorEpoll::reConnect(int64_t ms, Transceiver*p)
_reconnect[ms] = p;
}
string CommunicatorEpoll::getResouresInfo()
string CommunicatorEpoll::getResourcesInfo()
{
ostringstream desc;
desc << TC_Common::outfill("index") << _netThreadSeq << endl;

View File

@ -33,7 +33,7 @@
#include <assert.h>
#include "util/tc_timeprovider.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "servant/ServantHandle.h"
namespace tars

View File

@ -15,7 +15,7 @@
*/
#include "servant/EndpointInfo.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "servant/NetworkUtil.h"
#include "util/tc_socket.h"

View File

@ -16,7 +16,7 @@
#include "util/tc_port.h"
#include "servant/EndpointManager.h"
#include "servant/ObjectProxy.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "servant/AppCache.h"
#include "servant/Application.h"
#include "servant/StatReport.h"
@ -34,6 +34,7 @@ QueryEpBase::QueryEpBase(Communicator * pComm, bool bFirstNetThread,bool bInterf
, _locator("")
, _valid(false)
, _weightType(E_LOOP)
, _rootServant(true)
, _requestRegistry(false)
, _requestTimeout(0)
, _timeoutInterval(5*1000)
@ -158,12 +159,19 @@ void QueryEpBase::setObjName(const string & sObjName)
if (pos != string::npos)
{
//[直接连接]指定服务的IP和端口列表
_objName = sObjName.substr(0,pos);
sEndpoints = sObjName.substr(pos + 1);
_direct = true;
pos = _objName.find_first_of("#");
if(pos != string::npos)
{
_rootServant = false;
_objName = _objName.substr(0, pos);
}
_direct = true;
_valid = true;
}
@ -182,6 +190,13 @@ void QueryEpBase::setObjName(const string & sObjName)
throw TarsRegistryException("locator is not valid,_locator:" + _locator);
}
pos = _objName.find_first_of("#");
if(pos != string::npos)
{
_objName = _objName.substr(0, pos);
}
_queryFPrx = _communicator->stringToProxy<QueryFPrx>(_locator);
string sLocatorKey = _locator;
@ -378,6 +393,9 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
//内部请求主控都是异步请求
//接口请求主控第一次是同步请求
bool bSync = (!_valid && _interfaceReq);
//如果是异步且不是根servant(通过#1创建的servant, 不主动更新主控信息)
if(!bSync && !_rootServant)
return;
try
{
if(bSync)
@ -704,7 +722,7 @@ EndpointManager::~EndpointManager()
}
}
void EndpointManager::notifyEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive, bool bSync)
void EndpointManager::updateEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive)
{
set<EndpointInfo>::const_iterator iter;
map<string,AdapterProxy*>::iterator iterAdapter;
@ -788,6 +806,13 @@ void EndpointManager::notifyEndpoints(const set<EndpointInfo> & active, const se
_update = true;
}
void EndpointManager::notifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive,bool bNotify)
{
updateEndpoints(active, inactive);
_objectProxy->onNotifyEndpoints(active, inactive);
}
void EndpointManager::doNotify()
{
_objectProxy->doInvoke();

View File

@ -42,6 +42,7 @@ int NetworkUtil::createSocket(bool udp, bool isLocal, bool isIpv6)
{
s.setTcpNoDelay();
s.setKeepAlive();
s.setNoCloseWait();
}
else
{
@ -58,25 +59,6 @@ void NetworkUtil::closeSocketNoThrow(int fd)
TC_Port::closeSocket(fd);
}
//bool NetworkUtil::doConnect(int fd, const struct sockaddr& addr)
//{
// bool bConnected = false;
//
// int iRet = ::connect(fd, (struct sockaddr*)(&addr), int(sizeof(addr)));
//
// if (iRet == 0)
// {
// bConnected = true;
// }
// else if (!TC_Socket::isInProgress())
// {
// closeSocketNoThrow(fd);
// TARS_THROW_EXCEPTION_SYSCODE(TafNetConnectException, "NetworkUtil::doConnect error");
// }
//
// return bConnected;
//}
bool NetworkUtil::doConnect(int fd, const struct sockaddr *addr, socklen_t len)
{
bool bConnected = false;
@ -90,7 +72,7 @@ bool NetworkUtil::doConnect(int fd, const struct sockaddr *addr, socklen_t len)
else if (!TC_Socket::isInProgress())
{
closeSocketNoThrow(fd);
TARS_THROW_EXCEPTION_SYSCODE(TarsNetConnectException, "NetworkUtil::doConnect error");
THROW_EXCEPTION_SYSCODE(TarsNetConnectException, "NetworkUtil::doConnect error");
}
return bConnected;

View File

@ -21,7 +21,7 @@
#include "servant/AppCache.h"
#include "util/tc_common.h"
#include "util/tc_clientsocket.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
namespace tars
{
@ -39,7 +39,8 @@ ObjectProxy::ObjectProxy(CommunicatorEpoll * pCommunicatorEpoll, const string &
if(pos != string::npos)
{
_name = sObjectProxyName.substr(0,pos);
_name = sObjectProxyName.substr(0,pos);
_address = sObjectProxyName.substr(pos+1);
}
else
{
@ -53,9 +54,18 @@ ObjectProxy::ObjectProxy(CommunicatorEpoll * pCommunicatorEpoll, const string &
}
}
_proxyProtocol.requestFunc = ProxyProtocol::tarsRequest;
pos = _name.find_first_of('#');
if(pos != string::npos)
{
_hash = _name.substr(pos+1);
_name = _name.substr(0,pos);
}
_proxyProtocol.requestFunc = ProxyProtocol::tarsRequest;
_proxyProtocol.responseFunc = ProxyProtocol::tarsResponse;
_endpointManger.reset(new EndpointManager(this, _communicatorEpoll->getCommunicator(), sObjectProxyName, pCommunicatorEpoll->isFirstNetThread(), setName));
}
@ -107,12 +117,6 @@ ServantProxyCallbackPtr ObjectProxy::getPushCallback()
return _pushCallback;
}
//
//const string& ObjectProxy::name() const
//{
// return _name;
//}
void ObjectProxy::setProxyProtocol(const ProxyProtocol& protocol)
{
if(_hasSetProtocol)
@ -149,7 +153,7 @@ vector<SocketOpt>& ObjectProxy::getSocketOpt()
//
//bool ObjectProxy::invoke_sync(ReqMessage * msg)
//{
// TLOGTAF("[TAF][ObjectProxy::invoke_sync, " << _name << ", begin]" << endl);
// TLOGTARS("[TARS][ObjectProxy::invoke_sync, " << _name << ", begin]" << endl);
//
// //选择一个远程服务的Adapter来调用
// AdapterProxy * pAdapterProxy = NULL;
@ -198,42 +202,106 @@ void ObjectProxy::invoke(ReqMessage * msg)
}
msg->adapter = pAdapterProxy;
//连接还没有建立, 暂时先放队列里面
if(!msg->adapter->getTransceiver()->hasConnected())
{
bool bRet = _reqTimeoutQueue.push(msg,msg->request.iTimeout+msg->iBeginTime);
assert(bRet);
//把数据缓存在obj里面
TLOGTARS("[TARS][ObjectProxy::invoke, " << _name << ", select adapter proxy not connected (have not inovoke reg)]" << endl);
return;
}
pAdapterProxy->invoke(msg);
}
void ObjectProxy::onConnect(AdapterProxy *adapterProxy)
{
while(!_reqTimeoutQueue.empty())
{
TLOGTARS("[TARS][ObjectProxy::doInvoke, " << _name << ", pop...]" << endl);
ReqMessage * msg = NULL;
_reqTimeoutQueue.pop(msg);
assert(msg != NULL);
if(msg->adapter != NULL && msg->adapter != adapterProxy)
{
//选择一个远程服务的Adapter来调用
_endpointManger->selectAdapterProxy(msg, adapterProxy, false);
if (!adapterProxy)
{
//这里肯定是请求过主控
TLOGERROR("[TARS][ObjectProxy::doInvoke, " << _name << ", selectAdapterProxy is null]" << endl);
msg->response->iRet = TARSADAPTERNULL;
doInvokeException(msg);
return;
}
msg->adapter = adapterProxy;
}
else
{
msg->adapter = adapterProxy;
}
adapterProxy->invoke(msg);
}
}
void ObjectProxy::onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive)
{
if(_servantProxy) {
_servantProxy->onNotifyEndpoints(active, inactive);
}
}
void ObjectProxy::doInvoke()
{
TLOGTARS("[TARS][ObjectProxy::doInvoke, objname:" << _name << ", begin...]" << endl);
while(!_reqTimeoutQueue.empty())
{
TLOGTARS("[TARS][ObjectProxy::doInvoke, objname:" << _name << ", pop...]" << endl);
for(auto it = _reqTimeoutQueue.begin(); it != _reqTimeoutQueue.end(); ++it)
{
ReqMessage * msg = (*it).ptr;
ReqMessage * msg = NULL;
_reqTimeoutQueue.pop(msg);
AdapterProxy* adapterProxy;
assert(msg != NULL);
//选择一个远程服务的Adapter来调用
AdapterProxy * pAdapterProxy = NULL;
_endpointManger->selectAdapterProxy(msg,pAdapterProxy, false);
if(!pAdapterProxy)
{
//这里肯定是请求过主控
TLOGERROR("[TARS][ObjectProxy::doInvoke, objname:" << _name << ", selectAdapterProxy is null]" << endl);
msg->response->iRet = TARSADAPTERNULL;
doInvokeException(msg);
return;
}
msg->adapter = pAdapterProxy;
pAdapterProxy->invoke(msg);
}
//选择一个远程服务的Adapter来调用, selectAdapterProxy会发起连接
_endpointManger->selectAdapterProxy(msg, adapterProxy, false);
}
//
// while(!_reqTimeoutQueue.empty())
// {
// TLOGTARS("[TARS][ObjectProxy::doInvoke, " << _name << ", pop...]" << endl);
//
// ReqMessage * msg = NULL;
// _reqTimeoutQueue.pop(msg);
//
// assert(msg != NULL);
//
// AdapterProxy* adapterProxy;
//
// //选择一个远程服务的Adapter来调用
// _endpointManger->selectAdapterProxy(msg, adapterProxy, false);
//
// if (!adapterProxy) {
// //这里肯定是请求过主控
// TLOGERROR("[TARS][ObjectProxy::doInvoke, " << _name << ", selectAdapterProxy is null]" << endl);
// msg->response->iRet = JCEADAPTERNULL;
// doInvokeException(msg);
// return;
// }
//
// msg->adapter = adapterProxy;
//
// adapterProxy->invoke(msg);
// }
}
void ObjectProxy::doInvokeException(ReqMessage * msg)
@ -280,7 +348,7 @@ void ObjectProxy::doInvokeException(ReqMessage * msg)
//比如获取endpoint
try
{
msg->callback->onDispatch(msgPtr);
msg->callback->dispatch(msgPtr);
}
catch(exception & e)
{
@ -346,5 +414,16 @@ void ObjectProxy::mergeStat(map<StatMicMsgHead, StatMicMsgBody> & mStatMicMsg)
}
}
void ObjectProxy::onSetInactive(const EndpointInfo& ep)
{
const vector<AdapterProxy*> & vAdapterProxy = _endpointManger->getAdapters();
for(size_t iAdapter=0; iAdapter< vAdapterProxy.size();++iAdapter)
{
if(vAdapterProxy[iAdapter]->endpoint() == ep)
{
vAdapterProxy[iAdapter]->onSetInactive();
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
}

View File

@ -18,7 +18,7 @@
#include "servant/BaseF.h"
#include "servant/Application.h"
#include "servant/AppCache.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include <cerrno>

View File

@ -21,9 +21,9 @@
#include "servant/ServantHelper.h"
#include "servant/AppProtocol.h"
#include "servant/BaseF.h"
#include "servant/TarsNodeF.h"
#include "servant/TarsCookie.h"
#ifdef _USE_OPENTRACKING
#include "servant/KeepAliveNodeF.h"
#include "servant/Cookie.h"
#ifdef TARS_OPENTRACKING
#include "servant/text_map_carrier.h"
#endif
@ -352,7 +352,7 @@ void ServantHandle::initialize()
TLOGERROR("[TARS]ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`" << endl);
cerr << "[TARS]ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`" << endl;
TarsRemoteNotify::getInstance()->report("initialize createServant error: no adapter:" + _bindAdapter->getName());
RemoteNotify::getInstance()->report("initialize createServant error: no adapter:" + _bindAdapter->getName());
TC_Common::msleep(100);
@ -365,7 +365,7 @@ void ServantHandle::initialize()
{
TLOGERROR("[TARS]initialize error: no servant exists." << endl);
TarsRemoteNotify::getInstance()->report("initialize error: no servant exists.");
RemoteNotify::getInstance()->report("initialize error: no servant exists.");
TC_Common::msleep(100);
@ -386,7 +386,7 @@ void ServantHandle::initialize()
{
TLOGERROR("[TARS]initialize error:" << ex.what() << endl);
TarsRemoteNotify::getInstance()->report("initialize error:" + string(ex.what()));
RemoteNotify::getInstance()->report("initialize error:" + string(ex.what()));
TC_Common::msleep(100);
@ -396,7 +396,7 @@ void ServantHandle::initialize()
{
TLOGERROR("[TARS]initialize unknown exception error" << endl);
TarsRemoteNotify::getInstance()->report("initialize unknown exception error");
RemoteNotify::getInstance()->report("initialize unknown exception error");
TC_Common::msleep(100);
@ -434,7 +434,7 @@ void ServantHandle::heartbeat()
TarsCurrentPtr ServantHandle::createCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data)
{
TarsCurrentPtr current = new TarsCurrent(this);
TarsCurrentPtr current = new Current(this);
try
{
@ -478,7 +478,7 @@ TarsCurrentPtr ServantHandle::createCurrent(const shared_ptr<TC_EpollServer::Rec
TarsCurrentPtr ServantHandle::createCloseCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data)
{
TarsCurrentPtr current = new TarsCurrent(this);
TarsCurrentPtr current = new Current(this);
current->initializeClose(data);
current->setReportStat(false);
@ -580,7 +580,7 @@ void ServantHandle::handle(const shared_ptr<TC_EpollServer::RecvContext> &data)
}
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
void ServantHandle::processTracking(const TarsCurrentPtr &current)
{
if(!(Application::getCommunicator()->_traceManager))
@ -686,21 +686,7 @@ bool ServantHandle::processDye(const TarsCurrentPtr &current, string& dyeingKey)
return true;
}
// //servant已经被染色, 开启染色日志
// if (ServantHelperManager::getInstance()->isDyeing())
// {
// map<string, string>::const_iterator dyeingKeyIt = current->getRequestStatus().find(ServantProxy::STATUS_GRID_KEY);
//
// if (dyeingKeyIt != current->getRequestStatus().end() &&
// ServantHelperManager::getInstance()->isDyeingReq(dyeingKeyIt->second, current->getServantName(), current->getFuncName()))
// {
// TLOGTARS("[TARS] dyeing servant got a dyeing req, key:" << dyeingKeyIt->second << endl);
//
// dyeingKey = dyeingKeyIt->second;
//
// return true;
// }
// }
return false;
}
@ -845,14 +831,14 @@ void ServantHandle::handleTarsProtocol(const TarsCurrentPtr &current)
//处理cookie
map<string, string> cookie;
TarsCookieOp cookieOp;
CookieOp cookieOp;
if (processCookie(current, cookie))
{
cookieOp.setCookie(cookie);
current->setCookie(cookie);
}
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
//处理tracking信息
processTracking(current);
#endif
@ -861,7 +847,7 @@ void ServantHandle::handleTarsProtocol(const TarsCurrentPtr &current)
if (sit == _servants.end())
{
current->sendResponse(TARSSERVERNOSERVANTERR);
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
finishTracking(TARSSERVERNOSERVANTERR, current);
#endif
return;
@ -913,9 +899,9 @@ void ServantHandle::handleTarsProtocol(const TarsCurrentPtr &current)
//单向调用或者业务不需要同步返回
if (current->isResponse())
{
current->sendResponse(ret, buffer, TarsCurrent::TARS_STATUS(), sResultDesc);
current->sendResponse(ret, buffer, Current::TARS_STATUS(), sResultDesc);
}
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
finishTracking(ret, current);
#endif
}
@ -947,7 +933,7 @@ void ServantHandle::handleNoTarsProtocol(const TarsCurrentPtr &current)
TLOGERROR("[TARS]ServantHandle::handleNoTarsProtocol unknown error" << endl);
}
if (current->isResponse())
if (current->isResponse() && !buffer.empty())
{
current->sendResponse((const char*)buffer.data(), buffer.size());
}

View File

@ -19,7 +19,7 @@
#include "servant/StatReport.h"
#include "servant/Application.h"
#include "servant/BaseF.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "servant/Message.h"
#include "servant/EndpointManager.h"
@ -49,7 +49,7 @@ SeqManager::SeqManager(uint16_t iNum)
for(uint16_t i=0;i<(uint16_t)iNum;i++)
{
_p[i].free = true;
_p[i].next = i+1;
_p[i].next = i + 1;
}
_p[iNum-1].next = MAX_UNSIGN_SHORT;
_num = iNum;
@ -155,12 +155,20 @@ ServantProxyThreadData * ServantProxyThreadData::getData()
return g_sp.get();
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
ServantProxyCallback::ServantProxyCallback()
: _bNetThreadProcess(false)
{
}
int ServantProxyCallback::dispatch(ReqMessagePtr msg)
{
return onDispatch(msg);
}
///////////////////////////////////////////////////////////////////////////////////////////
int HttpServantProxyCallback::onDispatch(ReqMessagePtr msg)
{
if (msg->response->iRet != TARSSERVERSUCCESS)
@ -178,12 +186,23 @@ HttpServantProxyCallback::HttpServantProxyCallback(const HttpCallbackPtr& cb) :
int HttpServantProxyCallback::onDispatchException(const RequestPacket &request, const ResponsePacket &response)
{
return _httpCb->onHttpResponseException(request.context, response.iRet);
if(_httpCb)
return _httpCb->onHttpResponseException(response.iRet);
return 0;
}
int HttpServantProxyCallback::onDispatchResponse(const RequestPacket &request, const ResponsePacket &response)
{
return _httpCb->onHttpResponse(request.context, response.status, response.sBuffer);
assert(response.sBuffer.size() == sizeof(shared_ptr<TC_HttpResponse>));
shared_ptr<TC_HttpResponse> rsp = *(shared_ptr<TC_HttpResponse>*)(response.sBuffer.data());
if(_httpCb)
return _httpCb->onHttpResponse(rsp);
return 0;
}
///////////////////////////////////////////////////////////////
@ -212,7 +231,7 @@ void coroWhenAll(const CoroParallelBasePtr &ptr)
for(size_t i = 0; i < vMsg.size(); ++i)
{
ReqMessagePtr msgPtr = vMsg[i];
vMsg[i]->callback->onDispatch(msgPtr);
vMsg[i]->callback->dispatch(msgPtr);
}
}
@ -233,7 +252,7 @@ string ServantProxy::STATUS_SETNAME_VALUE = "STATUS_SETNAME_VALUE";
string ServantProxy::STATUS_TRACK_KEY = "STATUS_TRACK_KEY";
string ServantProxy::STATUS_COOKIE = "STATUS_COOKIE";
// string ServantProxy::STATUS_COOKIE = "STATUS_COOKIE";
////////////////////////////////////
@ -291,6 +310,16 @@ string ServantProxy::tars_name() const
return "NULL";
}
string ServantProxy::tars_full_name() const
{
if (_objectProxyNum >= 1 && (*_objectProxy != NULL))
{
return (*_objectProxy)->name() +"#" + (*_objectProxy)->hash() + "@" + (*_objectProxy)->address();
}
return "NULL";
}
void ServantProxy::tars_reconnect(int second)
{
if (_objectProxyNum >= 1 && (*_objectProxy != NULL))
@ -356,17 +385,68 @@ int ServantProxy::tars_async_timeout() const
return _asyncTimeout;
}
void ServantProxy::tars_connection_serial(int connectionSerial)
{
assert(!_rootPrx);
_connectionSerial = connectionSerial;
}
void ServantProxy::tars_set_protocol(const ProxyProtocol& protocol)
int ServantProxy::tars_connection_serial() const
{
if(_rootPrx) {
return _rootPrx->tars_connection_serial();
}
return _connectionSerial;
}
void ServantProxy::tars_set_protocol(SERVANT_PROTOCOL protocol, int connectionSerial)
{
ProxyProtocol proto;
switch(protocol)
{
case PROTOCOL_HTTP1:
proto.requestFunc = ProxyProtocol::http1Request;
proto.responseFunc = ProxyProtocol::http1Response;
if(connectionSerial <= 0)
connectionSerial = DEFAULT_CONNECTION_SERIAL;
break;
#if TARS_HTTP2
case PROTOCOL_HTTP2:
proto.requestFunc = ProxyProtocol::http2Request;
proto.responseFunc = ProxyProtocol::http2Response;
connectionSerial = 0;
break;
#endif
case PROTOCOL_TARS:
default:
proto.requestFunc = ProxyProtocol::tarsRequest;
proto.responseFunc = ProxyProtocol::tarsResponse;
break;
}
tars_set_protocol(proto, connectionSerial);
}
void ServantProxy::tars_set_protocol(const ProxyProtocol& protocol, int connectionSerial)
{
TC_LockT<TC_ThreadMutex> lock(*this);
for(size_t i = 0;i < _objectProxyNum; ++i)
for (size_t i = 0; i < _objectProxyNum; ++i)
{
(*(_objectProxy + i))->setProxyProtocol(protocol);
}
_connectionSerial = connectionSerial;
}
ProxyProtocol ServantProxy::tars_get_protocol()
{
TC_LockT<TC_ThreadMutex> lock(*this);
return (*(_objectProxy + 0))->getProxyProtocol();
}
void ServantProxy::tars_set_sockopt(int level, int optname, const void * optval, SOCKET_LEN_TYPE optlen)
{
@ -518,7 +598,7 @@ void ServantProxy::tars_set_push_callback(const ServantProxyCallbackPtr & cb)
// }
// else
// {
// TLOGERROR("[TAF][ServantProxy::invoke_async use coroutine's callback not set CoroParallelBasePtr]" << endl);
// TLOGERROR("[TARS][ServantProxy::invoke_async use coroutine's callback not set CoroParallelBasePtr]" << endl);
// delete msg;
// msg = NULL;
// throw TarsUseCoroException("ServantProxy::invoke_async use coroutine's callback not set CoroParallelBasePtr");
@ -526,7 +606,7 @@ void ServantProxy::tars_set_push_callback(const ServantProxyCallbackPtr & cb)
// }
// else
// {
// TLOGERROR("[TAF][ServantProxy::invoke coroutine mode invoke not open]" << endl);
// TLOGERROR("[TARS][ServantProxy::invoke coroutine mode invoke not open]" << endl);
// delete msg;
// msg = NULL;
// throw TarsUseCoroException("coroutine mode invoke not open");
@ -537,7 +617,7 @@ void ServantProxy::tars_set_push_callback(const ServantProxyCallbackPtr & cb)
// bool bEmpty;
// if (!pReqQ->push_back(msg, bEmpty))
// {
// TLOGERROR("[TAF][ServantProxy::invoke_async msgQueue push_back error num:" << pSptd->_netSeq << "]" << endl);
// TLOGERROR("[TARS][ServantProxy::invoke_async msgQueue push_back error num:" << pSptd->_netSeq << "]" << endl);
// msg->pObjectProxy->getCommunicatorEpoll()->notify(pSptd->_reqQNo, pReqQ);
// delete msg;
// throw TarsClientQueueException("client queue full");
@ -575,7 +655,7 @@ void ServantProxy::invoke(ReqMessage * msg, bool bCoroAsync)
msg->cookie = pSptd->_cookie;
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
msg->trackInfoMap = pSptd->_trackInfoMap;
#endif
@ -784,8 +864,7 @@ void ServantProxy::tars_invoke_async(char cPacketType,
checkDye(msg->request);
checkCookie(msg->request);
invoke(msg, bCoro);
servant_invoke(msg, bCoro);
}
shared_ptr<ResponsePacket> ServantProxy::tars_invoke(char cPacketType,
@ -842,13 +921,13 @@ void ServantProxy::rpc_call(uint32_t iRequestId,
msg->init(ReqMessage::SYNC_CALL);
msg->bFromRpc = true;
msg->request.sFuncName = sFuncName;
msg->request.sServantName = (*_objectProxy)->name();
msg->request.sFuncName = sFuncName;
msg->request.iRequestId = iRequestId;
msg->request.sBuffer.assign(buff, buff + len);
invoke(msg);
servant_invoke(msg, false);
rsp = *msg->response.get();
@ -866,66 +945,183 @@ void ServantProxy::rpc_call_async(uint32_t iRequestId,
ReqMessage * msg = new ReqMessage();
msg->init(callback?ReqMessage::ASYNC_CALL:ReqMessage::ONE_WAY);
msg->request.sFuncName = sFuncName;
msg->bFromRpc = true;
msg->callback = callback;
msg->request.sServantName = (*_objectProxy)->name();
msg->request.sFuncName = sFuncName;
msg->request.iRequestId = iRequestId;
msg->request.sBuffer.assign(buff, buff + len);
invoke(msg, bCoro);
servant_invoke(msg, bCoro);
}
void ServantProxy::http_call(const std::string& method,
const std::string& uri,
const std::map<std::string, std::string>& headers,
const std::string& body,
std::map<std::string, std::string>& rheaders,
std::string& rbody)
ServantPrx ServantProxy::getServantPrx(ReqMessage *msg)
{
ReqMessage* msg = new ReqMessage();
if(_connectionSerial <= 0)
return this;
msg->init(ReqMessage::SYNC_CALL);
if(_servantId == 0)
{
std::lock_guard<std::mutex> m(_servantMutex);
msg->bFromRpc = true;
msg->request.sServantName = uri;
msg->request.sFuncName = method;
// 使用下面两个字段保存头部和包体
msg->request.context = headers;
if(_servantId == 0)
{
if(_servantList.empty())
{
for(int i = 0; i < _connectionSerial; ++i)
{
string obj = tars_name() + "#" + TC_Common::tostr(i);
if (!(*_objectProxy)->address().empty())
{
obj += "@" + (*_objectProxy)->address();
}
msg->request.sBuffer.assign(body.begin(), body.end());
ServantPrx prx = _communicator->stringToProxy<ServantPrx>(obj);
prx->tars_set_protocol(tars_get_protocol());
prx->_rootPrx = this;
invoke(msg);
_servantList.push_back(prx);
}
}
++_servantId;
}
}
rheaders.swap(msg->response->status);
rbody.assign(msg->response->sBuffer.begin(), msg->response->sBuffer.end());
delete msg;
msg = NULL;
return _servantList[(_servantId++) % _servantList.size()];
}
void ServantProxy::http_call_async(const std::string& method,
const std::string& uri,
const std::map<std::string, std::string>& headers,
const std::string& body,
const HttpCallbackPtr &cb)
void ServantProxy::onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive)
{
ReqMessage * msg = new ReqMessage();
if(_rootPrx)
{
for (size_t i = 0; i < _rootPrx->_servantList.size(); i++)
{
_rootPrx->_servantList[i]->onNotifyEndpoints(active, inactive);
}
}
else
{
for (size_t i = 0; i < _objectProxyNum; ++i)
{
_objectProxy[i]->getEndpointManager()->updateEndpoints(active, inactive);
}
}
}
msg->init(ReqMessage::ASYNC_CALL);
void ServantProxy::onSetInactive(const EndpointInfo& ep)
{
if(!_rootPrx)
return;
msg->bFromRpc = true;
msg->request.sServantName = uri;
msg->request.sFuncName = method;
// 使用下面两个字段保存头部和包体
msg->request.context = headers;
msg->request.sBuffer.assign(body.begin(), body.end());
for (size_t i = 0; i < _rootPrx->_servantList.size(); i++)
{
ServantPrx &prx = _rootPrx->_servantList[i];
ServantProxyCallbackPtr callback = new HttpServantProxyCallback(cb);
msg->callback = callback;
for (size_t i = 0; i < prx->_objectProxyNum; ++i)
{
prx->_objectProxy[i]->onSetInactive(ep);
}
}
}
invoke(msg);
int ServantProxy::servant_invoke(ReqMessage *msg, bool bCoroAsync)
{
ServantPrx prx = getServantPrx(msg);
if(msg->callback)
{
msg->callback->setServantPrx(prx);
}
prx->invoke(msg, bCoroAsync);
return 0;
}
void ServantProxy::http_call(const string &funcName, shared_ptr<TC_HttpRequest> &request, shared_ptr<TC_HttpResponse> &response)
{
// if(_connectionSerial <= 0) {
// _connectionSerial = DEFAULT_CONNECTION_SERIAL;
// }
ReqMessage* msg = new ReqMessage();
msg->init(ReqMessage::SYNC_CALL);
msg->bFromRpc = true;
msg->request.sServantName = (*_objectProxy)->name();
msg->request.sFuncName = funcName;
msg->request.sBuffer.resize(sizeof(shared_ptr<TC_HttpRequest>));
msg->deconstructor = [msg] {
shared_ptr<TC_HttpRequest> & data = *(shared_ptr<TC_HttpRequest> *) (msg->request.sBuffer.data());
data.reset();
if(!msg->response->sBuffer.empty())
{
shared_ptr<TC_HttpResponse> & rsp = *(shared_ptr<TC_HttpResponse> *) (msg->response->sBuffer.data());
//主动reset一次
rsp.reset();
msg->response->sBuffer.clear();
}
};
shared_ptr<TC_HttpRequest> & data = *(shared_ptr<TC_HttpRequest> *) (msg->request.sBuffer.data());
data = request;
servant_invoke(msg, false);
response = *(shared_ptr<TC_HttpResponse>*)(msg->response->sBuffer.data());
delete msg;
msg = NULL;
}
void ServantProxy::http_call_async(const string &funcName, shared_ptr<TC_HttpRequest> &request, const HttpCallbackPtr &cb, bool bCoro)
{
// if(_connectionSerial <= 0) {
// _connectionSerial = DEFAULT_CONNECTION_SERIAL;
// }
ReqMessage* msg = new ReqMessage();
msg->init(ReqMessage::ASYNC_CALL);
msg->bFromRpc = true;
msg->request.sServantName = (*_objectProxy)->name();
msg->request.sFuncName = funcName;
msg->request.sBuffer.resize(sizeof(shared_ptr<TC_HttpRequest>));
msg->deconstructor = [msg] {
shared_ptr<TC_HttpRequest> & data = *(shared_ptr<TC_HttpRequest> *) (msg->request.sBuffer.data());
data.reset();
if(!msg->response->sBuffer.empty())
{
shared_ptr<TC_HttpResponse> & rsp = *(shared_ptr<TC_HttpResponse> *) (msg->response->sBuffer.data());
//主动reset一次
rsp.reset();
msg->response->sBuffer.clear();
}
};
*(shared_ptr<TC_HttpRequest>*)(msg->request.sBuffer.data()) = request;
ServantProxyCallbackPtr callback = new HttpServantProxyCallback(cb);
msg->callback = callback;
servant_invoke(msg, bCoro);
}
//选取一个网络线程对应的信息

View File

@ -15,7 +15,7 @@
*/
#include "servant/ServantProxyFactory.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
namespace tars
{

View File

@ -17,7 +17,7 @@
#include "servant/StatReport.h"
#include "util/tc_common.h"
#include "util/tc_timeprovider.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "servant/Communicator.h"
#include "servant/Application.h"
#include <iostream>
@ -485,7 +485,7 @@ int StatReport::reportMicMsg(MapStatMicMsg& msg,bool bFromClient)
}
mTemp[head] = it->second;
if(LOG->isNeedLog(TarsRollLogger::INFO_LOG))
if(LOG->isNeedLog(LocalRollLogger::INFO_LOG))
{
ostringstream os;
os.str("");
@ -607,7 +607,7 @@ int StatReport::reportPropMsg()
}
}
mStatMsg[head] = body;
if(LOG->isNeedLog(TarsRollLogger::INFO_LOG))
if(LOG->isNeedLog(LocalRollLogger::INFO_LOG))
{
ostringstream os;
os.str("");

View File

@ -1,213 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#include "servant/TarsConfig.h"
#include "util/tc_file.h"
#include "servant/Communicator.h"
#include "servant/TarsNotify.h"
#include "servant/Application.h"
#include <fstream>
namespace tars
{
int TarsRemoteConfig::setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision, int maxBakNum)
{
_comm = comm;
if(!obj.empty())
{
_configPrx = _comm->stringToProxy<ConfigPrx>(obj);
}
_app = app;
_serverName = serverName;
_basePath = basePath;
_maxBakNum = maxBakNum;
_setdivision = setdivision;
return 0;
}
bool TarsRemoteConfig::addConfig(const string & sFileName, string &buffer, bool bAppConfigOnly)
{
TC_LockT<TC_ThreadMutex> lock(_mutex);
try
{
string sFullFileName = _basePath + FILE_SEP + sFileName;
string newFile = getRemoteFile(sFileName, bAppConfigOnly);
if (newFile.empty() || !TC_File::isFileExist(newFile))//拉取不到配置中心的配置文件
{
if(!TC_File::isFileExist(newFile)) //获取本地配置成功,返回成功,但需要告警一下。
{
buffer = "[fail] get remote config:" + sFileName + "fail,use the local config.";
return true;
}
throw runtime_error("access file error:" + newFile);
}
if (TC_File::load2str(newFile) != TC_File::load2str(sFullFileName))
{
for (int i = _maxBakNum - 1; i >= 1; --i)
{
if (TC_File::isFileExist(index2file(sFullFileName, i)))
{
localRename(index2file(sFullFileName, i), index2file(sFullFileName, i+1));
}
}
if (TC_File::isFileExist(sFullFileName))
{
localRename(sFullFileName, index2file(sFullFileName, 1));
}
}
localRename(newFile, sFullFileName);
assert(TC_File::isFileExist(sFullFileName));
//assert(!access(sFullFileName.c_str(), R_OK));
buffer = "[succ] get remote config:" + sFileName;
return true;
}
catch (std::exception& e)
{
buffer = "[fail] get remote config '" + sFileName + "' error:" + string(e.what());
}
catch (...)
{
buffer = "[fail] get remote config '" + sFileName + "' unknown error";
}
return false;
}
string TarsRemoteConfig::getRemoteFile(const string &sFileName, bool bAppConfigOnly)
{
if (_configPrx)
{
string stream;
int ret = -1;
for(int i = 0; i < 2;i++)
{
try
{
if(_setdivision.empty())
{
ret = _configPrx->loadConfig(_app, (bAppConfigOnly ? "" : _serverName), sFileName, stream, ServerConfig::Context);
}
else
{
struct ConfigInfo confInfo;
confInfo.appname = _app;
confInfo.servername = (bAppConfigOnly ? "" : _serverName);
confInfo.filename = sFileName;
confInfo.bAppOnly = bAppConfigOnly;
confInfo.setdivision = _setdivision;
ret = _configPrx->loadConfigByInfo(confInfo,stream, ServerConfig::Context);
}
break;
}catch(std::exception& e){
//
}catch (...){
//
}
}
if (ret != 0 || stream.empty())
{
throw runtime_error("remote config file is empty:" + sFileName);
}
string newFile = _basePath + "/" + sFileName + "." + TC_Common::tostr(time(NULL));
std::ofstream out(newFile.c_str());
string result;
if (out)
{
out << stream;//如果硬盘满了,是否能写入成功需要进行判断。
out.flush();
if(out.bad())
{
out.close();
result = "[fail] copy stream to disk error." ;
TarsRemoteNotify::getInstance()->report(result);
return "";
}
else
{
out.close();
return newFile;
}
}
}
return "";
}
string TarsRemoteConfig::index2file(const string & sFullFileName, int index)
{
return sFullFileName + "." + TC_Common::tostr(index) + ".bak";
}
void TarsRemoteConfig::localRename(const string& oldFile, const string& newFile)
{
#if TARGET_PLATFORM_WINDOWS
//by goodenpeiwindows下面先remove后rename否则rename会失败
if (TC_File::isFileExist(oldFile) && TC_File::isFileExist(newFile))
{
::remove(newFile.c_str());
}
#endif
if (::rename(oldFile.c_str(), newFile.c_str()) != 0)
{
throw runtime_error("rename file error:" + oldFile + "->" + newFile);
}
}
string TarsRemoteConfig::recoverSysConfig(const string & sFullFileName)
{
try
{
for (int i = 1; i <= _maxBakNum; ++i)
{
if (TC_File::isFileExist(index2file(sFullFileName, i)))
{
localRename(index2file(sFullFileName, i), sFullFileName);
return "[succ] recover file:" + index2file(sFullFileName, i);
}
}
}
catch (std::exception& e)
{
return "[fail] recover config error:" + string(e.what());
}
catch (...)
{
return "[fail] recover config error";
}
return "[fail] no backup file.";
}
}

View File

@ -1,437 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#include "servant/TarsCurrent.h"
#include "servant/ServantHandle.h"
#include "servant/BaseF.h"
#include "servant/Application.h"
#include "tup/tup.h"
#include <cerrno>
namespace tars
{
//////////////////////////////////////////////////////////////////
TarsCurrent::TarsCurrent(ServantHandle *pServantHandle)
: _servantHandle(pServantHandle)
// , _bindAdapter(NULL)
// , _uid(0)
// , _ip("NULL")
// , _port(0)
// , _fd(-1)
, _response(true)
// , _begintime(0)
, _ret(0)
, _reportStat(true)
// , _closeType(-1)
{
}
TarsCurrent::~TarsCurrent()
{
//TUP调用或单向调用从服务端上报调用信息
if(_reportStat)
{
if(_request.iVersion == TUPVERSION )
{
reportToStat("tup_client");
}
else if(_request.cPacketType == TARSONEWAY)
{
reportToStat("one_way_client");
}
else if(!_data->adapter()->isTarsProtocol() && ServerConfig::ReportFlow)
{
//非tars客户端 从服务端上报调用信息
reportToStat("not_tars_client");
}
}
}
const string &TarsCurrent::getHostName() const
{
auto it = _request.context.find("node_name");
if(it != _request.context.end())
{
return it->second;
}
return _data->ip();
}
const string &TarsCurrent::getIp() const
{
return _data->ip();
}
int TarsCurrent::getPort() const
{
return _data->port();
// return _port;
}
uint32_t TarsCurrent::getUId() const
{
return _data->uid();
// return _uid;
}
string TarsCurrent::getServantName() const
{
return _request.sServantName;
}
short TarsCurrent::getRequestVersion() const
{
return _request.iVersion;
}
map<string, string>& TarsCurrent::getContext()
{
return _request.context;
}
const map<string, string>& TarsCurrent::getRequestStatus() const
{
return _request.status;
}
string TarsCurrent::getFuncName() const
{
return _request.sFuncName;
}
uint32_t TarsCurrent::getRequestId() const
{
return _request.iRequestId;
}
char TarsCurrent::getPacketType() const
{
return _request.cPacketType;
}
tars::Int32 TarsCurrent::getMessageType() const
{
return _request.iMessageType;
}
struct timeval TarsCurrent::getRecvTime() const
{
timeval tm;
tm.tv_sec = _data->recvTimeStamp()/1000;
tm.tv_usec = (_data->recvTimeStamp()%1000)*1000;
return tm;
}
void TarsCurrent::setReportStat(bool bReport)
{
_reportStat = bReport;
}
const vector<char>& TarsCurrent::getRequestBuffer() const
{
if (_data->adapter()->isTarsProtocol())
{
return _request.sBuffer;
}
else
{
return _data->buffer();
}
// return _request.sBuffer;
}
bool TarsCurrent::isResponse() const
{
return _response;
}
void TarsCurrent::setCloseType(int type)
{
_data->setCloseType(type);
}
int TarsCurrent::getCloseType() const
{
return _data->closeType();
}
void TarsCurrent::initialize(const shared_ptr<TC_EpollServer::RecvContext> &data)
// void TarsCurrent::initialize(const TC_EpollServer::tagRecvData &stRecvData)
{
_data = data;
_request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(_data->adapter()->getName());
if (_data->adapter()->isTarsProtocol())
{
initialize(_data->buffer());
}
// initialize(stRecvData, begintime);
}
void TarsCurrent::initializeClose(const shared_ptr<TC_EpollServer::RecvContext> &data)
{
_data = data;
_request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(_data->adapter()->getName());
}
void TarsCurrent::initialize(const vector<char>& sRecvBuffer)
{
TarsInputStream<BufferReader> is;
is.setBuffer(sRecvBuffer.data(), sRecvBuffer.size());
_request.readFrom(is);
}
// void TarsCurrent::initialize(const TC_EpollServer::tagRecvData &stRecvData, int64_t beginTime)
// {
// _ip = stRecvData.ip;
// _port = stRecvData.port;
// _uid = stRecvData.uid;
// _fd = stRecvData.fd;
// _bindAdapter = stRecvData.adapter.get();
// _begintime = beginTime;
// _request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(stRecvData.adapter->getName());
// if (_bindAdapter->isTarsProtocol())
// {
// initialize(stRecvData.buffer);
// }
// else
// {
// _request.sBuffer.reserve(stRecvData.buffer.length());
// _request.sBuffer.resize(stRecvData.buffer.length());
// ::memcpy(&_request.sBuffer[0], stRecvData.buffer.c_str(), stRecvData.buffer.length());
// }
// }
// void TarsCurrent::initializeClose(const TC_EpollServer::tagRecvData &stRecvData)
// {
// _ip = stRecvData.ip;
// _port = stRecvData.port;
// _uid = stRecvData.uid;
// _fd = stRecvData.fd;
// _bindAdapter = stRecvData.adapter.get();
// _request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(stRecvData.adapter->getName());
// _begintime = TNOWMS;
// }
// void TarsCurrent::initialize(const string &sRecvBuffer)
// {
// TarsInputStream<BufferReader> is;
// is.setBuffer(sRecvBuffer.c_str(), sRecvBuffer.length());
// _request.readFrom(is);
// }
void TarsCurrent::sendResponse(const char* buff, uint32_t len)
{
// _servantHandle->sendResponse(_uid, string(buff, len), _ip, _port, _fd);
shared_ptr<TC_EpollServer::SendContext> send = _data->createSendContext();
send->buffer()->assign(buff, len);
_servantHandle->sendResponse(send);
}
void TarsCurrent::sendResponse(int iRet, const vector<char> &buff)
{
//单向调用不需要返回
if (_request.cPacketType == TARSONEWAY)
{
return;
}
// ResponsePacket response;
// response.sBuffer = buff;
sendResponse(iRet, buff, TARS_STATUS(), "");
}
void TarsCurrent::sendResponse(int iRet)
{
// ResponsePacket response;
sendResponse(iRet, vector<char>(), TARS_STATUS(), "");
}
void TarsCurrent::sendResponse(int iRet, tars::TarsOutputStream<tars::BufferWriterVector>& os)
{
// ResponsePacket response;
// os.swap(response.sBuffer);
sendResponse(iRet, os.getByteBuffer(), TARS_STATUS(), "");
}
void TarsCurrent::sendResponse(int iRet, tup::UniAttribute<tars::BufferWriterVector, tars::BufferReader>& attr)
{
ResponsePacket response;
attr.encode(response.sBuffer);
sendResponse(iRet, response.sBuffer, TARS_STATUS(), "");
}
void TarsCurrent::sendResponse(int iRet, const vector<char> &buffer, const map<string, string>& status, const string & sResultDesc)
{
_ret = iRet;
//单向调用不需要返回
if (_request.cPacketType == TARSONEWAY)
{
return;
}
shared_ptr<TC_EpollServer::SendContext> send = _data->createSendContext();
tars::Int32 iHeaderLen = 0;
TarsOutputStream<BufferWriterVector> os;
//先预留4个字节长度
os.writeBuf((const char *)&iHeaderLen, sizeof(iHeaderLen));
if (_request.iVersion != TUPVERSION)
{
ResponsePacket response;
response.iRequestId = _request.iRequestId;
response.iMessageType = _request.iMessageType;
response.cPacketType = TARSNORMAL;
response.iVersion = _request.iVersion;
response.status = status;
response.sBuffer = std::move(buffer);
response.sResultDesc = sResultDesc;
response.context = _responseContext;
response.iRet = iRet;
TLOGTARS("[TARS]TarsCurrent::sendResponse :"
<< response.iMessageType << "|"
<< _request.sServantName << "|"
<< _request.sFuncName << "|"
<< response.iRequestId << endl);
response.writeTo(os);
}
else
{
//tup回应包用请求包的结构(这里和新版本TAF是有区别的)
RequestPacket response;
response.iRequestId = _request.iRequestId;
response.iMessageType = _request.iMessageType;
response.cPacketType = TARSNORMAL;
response.iVersion = _request.iVersion;
response.status = status;
response.context = _responseContext;
response.sBuffer = std::move(buffer);
response.sServantName = _request.sServantName;
response.sFuncName = _request.sFuncName;
//异常的情况下buffer可能为空要保证有一个空UniAttribute的编码内容
if(response.sBuffer.size() == 0)
{
tup::UniAttribute<> tarsAttr;
tarsAttr.setVersion(_request.iVersion);
tarsAttr.encode(response.sBuffer);
}
//iRet为0时,不记录在status里面,节省空间
if(iRet != 0)
{
response.status[ServantProxy::STATUS_RESULT_CODE] = TC_Common::tostr(iRet);
}
//sResultDesc为空时,不记录在status里面,节省空间
if(!sResultDesc.empty())
{
response.status[ServantProxy::STATUS_RESULT_DESC] = sResultDesc;
}
TLOGTARS("[TARS]TarsCurrent::sendResponse :"
<< response.iMessageType << "|"
<< _request.sServantName << "|"
<< _request.sFuncName << "|"
<< response.iRequestId << endl);
response.writeTo(os);
}
assert(os.getLength() >= 4);
iHeaderLen = htonl((int)(os.getLength()));
memcpy(os.getByteBuffer().data(), (const char *)&iHeaderLen, sizeof(iHeaderLen));
send->buffer()->swap(os.getByteBuffer());
_servantHandle->sendResponse(send);
}
void TarsCurrent::close()
{
if (_servantHandle)
{
_servantHandle->close(_data);
}
}
ServantHandle* TarsCurrent::getServantHandle()
{
return _servantHandle;
}
TC_EpollServer::BindAdapter* TarsCurrent::getBindAdapter()
{
return _data->adapter().get();
}
void TarsCurrent::reportToStat(const string& sObj)
{
StatReport* stat = Application::getCommunicator()->getStatReport();
if(stat && stat->getStatPrx())
{
// int64_t endtime = TNOWMS;
// int sptime = endtime - _begintime;
//被调上报自己的set信息set信息在setReportInfo设置
// stat->report(sObj, "" , _request.sServantName, _data->ip(), 0, _request.sFuncName, (StatReport::StatResult)_ret, TNOWMS - _data->recvTimeStamp(), 0);
stat->report(sObj, "", _request.sFuncName, _data->ip(), 0, (StatReport::StatResult)_ret, TNOWMS - _data->recvTimeStamp(), 0, false);
}
}
////////////////////////////////////////////////////////////////////////////
}

View File

@ -1,723 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#include "servant/TarsLogger.h"
#include "servant/Communicator.h"
#include "servant/Application.h"
namespace tars
{
int RollWriteT::_dyeingThread = 0;
int TimeWriteT::_dyeing = 0;
/////////////////////////////////////////////////////////////////////////////////////
RollWriteT::RollWriteT():_dyeingRollLogger(NULL), _maxSize(10000), _maxNum(1), _logPrx(NULL)
{
}
RollWriteT::~RollWriteT()
{
if(_dyeingRollLogger)
{
delete _dyeingRollLogger;
}
}
void RollWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &ds)
{
vector<string> vRemoteDyeing;
deque<pair<size_t, string> >::const_iterator it = ds.begin();
while(it != ds.end())
{
of << it->second;
//染色线程id不存在
if(it->first != 0)
{
if(!_dyeingRollLogger)
{
string sDyeingDir = _logPath;
sDyeingDir += "/";
sDyeingDir += DYEING_DIR;
sDyeingDir += "/";
string sDyeingFile = sDyeingDir;
sDyeingFile += DYEING_FILE;
TC_File::makeDirRecursive(sDyeingDir);
//初始化染色循环日志
_dyeingRollLogger = new TC_RollLogger();
_dyeingRollLogger->init(sDyeingFile, _maxSize, _maxNum);
_dyeingRollLogger->modFlag(TC_DayLogger::HAS_TIME, false);
_dyeingRollLogger->modFlag(TC_DayLogger::HAS_TIME|TC_DayLogger::HAS_LEVEL|TC_DayLogger::HAS_PID, true);
_dyeingRollLogger->setLogLevel("DEBUG");
}
_dyeingRollLogger->roll(make_pair(it->first, _app + "." + _server + "|" + it->second ));
vRemoteDyeing.push_back(_app + "." + _server + "|" + it->second);
}
++it;
}
of.flush();
if(_logPrx && vRemoteDyeing.size() > 0)
{
try
{
_logPrx->logger(DYEING_DIR, DYEING_FILE, "roll", "%Y%m%d", vRemoteDyeing, ServerConfig::Context);
}
catch(exception &ex)
{
TLOGERROR("[TARS] dyeing log write to remote log server error:" << ex.what() << endl);
}
}
}
void RollWriteT::setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath, int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string &sLogObj)
{
_app = sApp;
_server = sServer;
_logPath = sLogPath;
_maxSize = iMaxSize;
_maxNum = iMaxNum;
if(comm && !sLogObj.empty())
{
_logPrx = comm->stringToProxy<LogPrx>(sLogObj);
//单独设置超时时间
_logPrx->tars_timeout(3000);
}
}
/////////////////////////////////////////////////////////////////////////////////////
void TarsRollLogger::setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string &sLogObj)
{
_app = sApp;
_server = sServer;
_logpath = sLogpath;
//生成目录
TC_File::makeDirRecursive(_logpath + "/" + _app + "/" + _server);
_local.start(1);
//初始化本地循环日志
_logger.init(_logpath + "/" + _app + "/" + _server + "/" + _app + "." + _server, iMaxSize, iMaxNum);
_logger.modFlag(TC_DayLogger::HAS_TIME, false);
_logger.modFlag(TC_DayLogger::HAS_TIME|TC_DayLogger::HAS_LEVEL|TC_DayLogger::HAS_PID, true);
//设置为异步
sync(false);
//设置染色日志信息
_logger.getWriteT().setDyeingLogInfo(sApp, sServer, sLogpath, iMaxSize, iMaxNum, comm, sLogObj);
}
void TarsRollLogger::sync(bool bSync)
{
if(bSync)
{
_logger.unSetupThread();
}
else
{
_logger.setupThread(&_local);
}
}
void TarsRollLogger::enableDyeing(bool bEnable, const string& sDyeingKey/* = ""*/)
{
_logger.getRoll()->enableDyeing(bEnable, sDyeingKey);
}
/////////////////////////////////////////////////////////////////////////////////////
TarsLoggerThread::TarsLoggerThread()
{
_local.start(1);
_remote.start(1);
}
TarsLoggerThread::~TarsLoggerThread()
{
//先刷新本地日志
_local.flush();
//再刷新远程日志, 保证不会丢日志
_remote.flush();
}
TC_LoggerThreadGroup* TarsLoggerThread::local()
{
return &_local;
}
TC_LoggerThreadGroup* TarsLoggerThread::remote()
{
return &_remote;
}
/////////////////////////////////////////////////////////////////////////////////////
RemoteTimeWriteT::RemoteTimeWriteT():_timeWrite(NULL)
{
}
RemoteTimeWriteT::~RemoteTimeWriteT()
{
}
void RemoteTimeWriteT::setTimeWriteT(TimeWriteT *pTimeWrite)
{
_timeWrite = pTimeWrite;
}
void RemoteTimeWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &buffer)
{
const static uint32_t len = 2000;
//写远程日志
if(_timeWrite->_logPrx && !buffer.empty())
{
//大于50w条, 直接抛弃掉,否则容易导致内存泄漏
if(buffer.size() > 500000)
{
_timeWrite->writeError(buffer);
return;
}
vector<string> v;
v.reserve(len);
deque<pair<size_t, string> >::const_iterator it = buffer.begin();
while(it != buffer.end())
{
v.push_back(it->second);
++it;
//每次最多同步len条
if(v.size() >= len)
{
sync2remote(v);
v.clear();
v.reserve(len);
}
}
if(v.size() > 0)
{
sync2remote(v);
}
}
}
void RemoteTimeWriteT::sync2remote(const vector<string> &v)
{
try
{
//此处传递set信息到远程logserver
LogInfo stInfo;
stInfo.appname = _timeWrite->_app;
stInfo.servername = _timeWrite->_server;
stInfo.sFilename = _timeWrite->_file;
stInfo.sFormat = _timeWrite->_format;
stInfo.setdivision = _timeWrite->_setDivision;
stInfo.bHasSufix = _timeWrite->_hasSufix;
stInfo.bHasAppNamePrefix = _timeWrite->_hasAppNamePrefix;
stInfo.sConcatStr = _timeWrite->_concatStr;
stInfo.bHasSquareBracket = _timeWrite->_hasSquareBracket;
stInfo.sSepar = _timeWrite->_separ;
stInfo.sLogType = _timeWrite->_logType;
_timeWrite->_logPrx->loggerbyInfo(stInfo,v, ServerConfig::Context);
if (_timeWrite->_reportSuccPtr)
{
_timeWrite->_reportSuccPtr->report(v.size());
}
}
catch(exception &ex)
{
TLOGERROR("[TARS] write to remote log server error:" << ex.what() << ": buffer size:" << v.size() << endl);
_timeWrite->writeError(v);
if (_timeWrite->_reportFailPtr)
{
_timeWrite->_reportFailPtr->report(v.size());
}
}
}
void RemoteTimeWriteT::sync2remoteDyeing(const vector<string> &v)
{
try
{
_timeWrite->_logPrx->logger(DYEING_DIR, DYEING_FILE, "", _timeWrite->_format, v, ServerConfig::Context);
}
catch(exception &ex)
{
TLOGERROR("[TARS] write dyeing log to remote log server error:" << ex.what() << ": buffer size:" << v.size() << endl);
_timeWrite->writeError(v);
}
}
/////////////////////////////////////////////////////////////////////////////////////
//
TimeWriteT::~TimeWriteT()
{
if(_remoteTimeLogger)
{
delete _remoteTimeLogger;
}
}
TimeWriteT::TimeWriteT() : _remoteTimeLogger(NULL), _local(true), _remote(true), _dyeingTimeLogger(NULL),_setDivision(""),
_hasSufix(true),_hasAppNamePrefix(true),_concatStr("_"),_separ("|"),_hasSquareBracket(false),_logType("")
{
}
void TimeWriteT::setLogInfo(const LogPrx &logPrx, const string &sApp, const string &sServer, const string &sFile, const string &sLogpath, const string &sFormat, const string& setdivision, const string& sLogType, const PropertyReportPtr &reportSuccPtr, const PropertyReportPtr &reportFailPtr)
{
_logPrx = logPrx;
_app = sApp;
_server = sServer;
_format = sFormat;
_file = sFile;
_setDivision = setdivision;
_logType = sLogType;
_reportSuccPtr = reportSuccPtr;
_reportFailPtr = reportFailPtr;
string sAppSrvName = _hasAppNamePrefix?(_app + "." + _server):"";
_filePath = sLogpath + "/" + _app + "/" + _server + "/" + sAppSrvName;
if(!_file.empty())
{
_filePath += (_hasAppNamePrefix?_concatStr:"") + sFile;
}
string sDyeingDir = sLogpath;
sDyeingDir += "/";
sDyeingDir += DYEING_DIR;
sDyeingDir += "/";
_dyeingFilePath = sDyeingDir;
_remoteTimeLogger = new RemoteTimeLogger();
_remoteTimeLogger->init(_filePath, _format,_hasSufix,_concatStr,NULL,true);
_remoteTimeLogger->modFlag(0xffff, false);
_remoteTimeLogger->setSeparator(_separ);
_remoteTimeLogger->enableSqareWrapper(_hasSquareBracket);
_remoteTimeLogger->setupThread(TarsLoggerThread::getInstance()->remote());
_remoteTimeLogger->getWriteT().setTimeWriteT(this);
if(!_local)
{
initError();
}
}
void TimeWriteT::initDyeingLog()
{
TC_File::makeDirRecursive(_dyeingFilePath);
string sDyeingFile = _dyeingFilePath;
sDyeingFile += "/";
sDyeingFile += DYEING_FILE;
_dyeingTimeLogger = new DyeingTimeLogger();
_dyeingTimeLogger->init(sDyeingFile, _format);
_dyeingTimeLogger->modFlag(0xffff, false);
}
void TimeWriteT::setLogPrx(const LogPrx &logPrx)
{
_logPrx = logPrx;
}
void TimeWriteT::initError()
{
//远程错误日志
_logger.init(_filePath + ".remote.error", _format);
_logger.modFlag(0xffff, false);
}
void TimeWriteT::enableLocal(bool bEnable)
{
_local = bEnable;
if(!_local)
{
initError();
}
}
void TimeWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &buffer)
{
if(_local && of && !buffer.empty())
{
try
{
_wt(of, buffer);
}
catch(...)
{
}
}
if(_remote && _remoteTimeLogger && !buffer.empty())
{
deque<pair<size_t, string> >::const_iterator it = buffer.begin();
while(it != buffer.end())
{
_remoteTimeLogger->any() << it->second;
++it;
}
}
vector<string> vDyeingLog;
deque<pair<size_t, string> >::const_iterator it = buffer.begin();
while(it != buffer.end())
{
if(it->first != 0)
{
if(!_dyeingTimeLogger)
{
initDyeingLog();
}
_dyeingTimeLogger->any() << _app << "." << _server << "|" << it->second;
vDyeingLog.push_back(_app + "." + _server + "|" + it->second);
}
++it;
}
if(_logPrx && !vDyeingLog.empty())
{
try
{
_logPrx->logger(DYEING_DIR, DYEING_FILE, "day", "%Y%m%d", vDyeingLog, ServerConfig::Context);
}
catch(exception &ex)
{
TLOGERROR("[TARS] dyeing log write to remote log server error:" << ex.what() << endl);
}
}
}
void TimeWriteT::writeError(const vector<string> &buffer)
{
if(!_local)
{
for(size_t i = 0; i < buffer.size(); i++)
{
_logger.any() << buffer[i];
}
}
//告警
string sInfo = _app + "." + _server + "|";
sInfo += ServerConfig::LocalIp + "|sync log to remote tarslog error";
FDLOG("tarserror") << sInfo <<endl;
//TARS_NOTIFY_ERROR(sInfo);
}
void TimeWriteT::writeError(const deque<pair<size_t, string> > &buffer)
{
if(!_local)
{
deque<pair<size_t, string> >::const_iterator it = buffer.begin();
while(it != buffer.end())
{
_logger.any() << it->second;
++it;
}
}
//告警
string sInfo = _app + "." + _server + "|";
sInfo += ServerConfig::LocalIp + "|sync log to remote tarslog error(buffer.size>500000)";
FDLOG("tarserror") << sInfo <<endl;
//TARS_NOTIFY_ERROR(sInfo);
}
/////////////////////////////////////////////////////////////////////////////////////
TarsTimeLogger::TarsTimeLogger() : _defaultLogger(NULL),_hasSufix(true),_hasAppNamePrefix(true),_concatStr("_"),_separ("|"),_hasSquareBracket(false),_local(true),_remote(true)
{
}
TarsTimeLogger::~TarsTimeLogger()
{
if(_defaultLogger != NULL)
{
delete _defaultLogger;
}
map<string, TimeLogger*>::iterator it = _loggers.begin();
while(it != _loggers.end())
{
delete it->second;
++it;
}
_loggers.clear();
}
void TarsTimeLogger::initTimeLogger(TimeLogger *pTimeLogger, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
{
string sAppSrvName = _hasAppNamePrefix?(_app + "." + _server):"";
string sFilePath = _logpath + "/" + _app + "/" + _server + "/" + sAppSrvName;
if(!sFile.empty())
{
sFilePath += (_hasAppNamePrefix?_concatStr:"") + sFile;
}
//本地日志格式
pTimeLogger->init(sFilePath, sFormat,_hasSufix,_concatStr,logTypePtr,!_local);
pTimeLogger->modFlag(0xffff, false);
pTimeLogger->modFlag(TC_DayLogger::HAS_TIME, true);
pTimeLogger->setSeparator(_separ);
pTimeLogger->enableSqareWrapper(_hasSquareBracket);
pTimeLogger->setupThread(TarsLoggerThread::getInstance()->local());
//远程日志格式
pTimeLogger->getWriteT().enableSufix(_hasSufix);
pTimeLogger->getWriteT().enablePrefix(_hasAppNamePrefix);
pTimeLogger->getWriteT().setFileNameConcatStr(_concatStr);
pTimeLogger->getWriteT().setSeparator(_separ);
pTimeLogger->getWriteT().enableSqareWrapper(_hasSquareBracket);
pTimeLogger->getWriteT().enableLocal(_local);
pTimeLogger->getWriteT().enableRemote(_remote);
string sLogType = "";
if(logTypePtr)
{
sLogType = logTypePtr->toString();
}
PropertyReportPtr reportSuccPtr = NULL;
PropertyReportPtr reportFailPtr = NULL;
if (_remote && _logStatReport)
{
string sKey = _app + "." + _server + "." + sFile;
reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum());
reportFailPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_fail", PropertyReport::sum());
}
pTimeLogger->getWriteT().setLogInfo(_logPrx, _app, _server, sFile, _logpath, sFormat, _setDivision, sLogType, reportSuccPtr, reportFailPtr);
}
void TarsTimeLogger::initTimeLogger(TimeLogger *pTimeLogger,const string &sApp, const string &sServer, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
{
string sAppSrvName = _hasAppNamePrefix?(sApp + "." + sServer):"";
string sFilePath = _logpath + "/" + sApp + "/" + sServer + "/" + sAppSrvName;
if(!sFile.empty())
{
sFilePath += (_hasAppNamePrefix?_concatStr:"") + sFile;
}
//本地日志格式
pTimeLogger->init(sFilePath,sFormat,_hasSufix,_concatStr,logTypePtr,!_local);
pTimeLogger->modFlag(0xffff, false);
pTimeLogger->modFlag(TC_DayLogger::HAS_TIME, true);
pTimeLogger->setSeparator(_separ);
pTimeLogger->enableSqareWrapper(_hasSquareBracket);
pTimeLogger->setupThread(TarsLoggerThread::getInstance()->local());
//远程日志格式
pTimeLogger->getWriteT().enableSufix(_hasSufix);
pTimeLogger->getWriteT().enablePrefix(_hasAppNamePrefix);
pTimeLogger->getWriteT().setFileNameConcatStr(_concatStr);
pTimeLogger->getWriteT().setSeparator(_separ);
pTimeLogger->getWriteT().enableSqareWrapper(_hasSquareBracket);
pTimeLogger->getWriteT().enableLocal(_local);
pTimeLogger->getWriteT().enableRemote(_remote);
string sLogType = "";
if(logTypePtr)
{
sLogType = logTypePtr->toString();
}
PropertyReportPtr reportSuccPtr = NULL;
PropertyReportPtr reportFailPtr = NULL;
if (_remote && _logStatReport)
{
string sKey = _app + "." + _server + "." + sFile;
reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum());
reportFailPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_fail", PropertyReport::sum());
}
pTimeLogger->getWriteT().setLogInfo(_logPrx, sApp, sServer, sFile, _logpath, sFormat, _setDivision, sLogType, reportSuccPtr, reportFailPtr);
}
void TarsTimeLogger::setLogInfo(const CommunicatorPtr &comm, const string &obj, const string &sApp, const string &sServer, const string &sLogpath, const string& setdivision, const bool &bLogStatReport)
{
_app = sApp;
_server = sServer;
_logpath = sLogpath;
_comm = comm;
_setDivision = setdivision;
_logStatReport = bLogStatReport;
if(!obj.empty())
{
_logPrx = _comm->stringToProxy<LogPrx>(obj);
//单独设置超时时间
_logPrx->tars_timeout(3000);
if(_defaultLogger)
{
_defaultLogger->getWriteT().setLogPrx(_logPrx);
}
}
//创建本地目录
TC_File::makeDirRecursive(_logpath + "/" + _app + "/" + _server);
}
void TarsTimeLogger::initFormat(const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
{
if(sFile.empty())
{
if(!_defaultLogger)
{
_defaultLogger = new TimeLogger();
}
initTimeLogger(_defaultLogger, "", sFormat,logTypePtr);
}
else
{
string s = _app + "/" + _server + "/"+ sFile;
Lock lock(*this);
map<string, TimeLogger*>::iterator it = _loggers.find(s);
if( it == _loggers.end())
{
TimeLogger *p = new TimeLogger();
initTimeLogger(p, sFile, sFormat,logTypePtr);
_loggers[s] = p;
return;
}
initTimeLogger(it->second, sFile, sFormat,logTypePtr);
}
}
void TarsTimeLogger::initFormat(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr)
{
string s = sApp + "/" + sServer + "/"+ sFile;
Lock lock(*this);
map<string, TimeLogger*>::iterator it = _loggers.find(s);
if( it == _loggers.end())
{
TimeLogger *p = new TimeLogger();
initTimeLogger(p, sApp, sServer, sFile, sFormat,logTypePtr);
_loggers[s] = p;
return;
}
initTimeLogger(it->second, sApp, sServer, sFile, sFormat,logTypePtr);
}
TarsTimeLogger::TimeLogger* TarsTimeLogger::logger(const string &sFile)
{
if(sFile.empty())
{
if(!_defaultLogger)
{
_defaultLogger = new TimeLogger();
initTimeLogger(_defaultLogger, "", "%Y%m%d");
}
return _defaultLogger;
}
string s = _app + "/" + _server + "/"+ sFile;
Lock lock(*this);
map<string, TimeLogger*>::iterator it = _loggers.find(s);
if( it == _loggers.end())
{
TimeLogger *p = new TimeLogger();
initTimeLogger(p, sFile, "%Y%m%d");
_loggers[s] = p;
return p;
}
return it->second;
}
TarsTimeLogger::TimeLogger* TarsTimeLogger::logger(const string &sApp, const string &sServer,const string &sFile)
{
string s = sApp + "/" + sServer + "/"+ sFile;
Lock lock(*this);
map<string, TimeLogger*>::iterator it = _loggers.find(s);
if( it == _loggers.end())
{
TimeLogger *p = new TimeLogger();
initTimeLogger(p, sApp, sServer, sFile, "%Y%m%d");
_loggers[s] = p;
return p;
}
return it->second;
}
void TarsTimeLogger::sync(const string &sFile, bool bSync)
{
if(bSync)
{
logger(sFile)->unSetupThread();
}
else
{
logger(sFile)->setupThread(TarsLoggerThread::getInstance()->local());
}
}
void TarsTimeLogger::enableRemote(const string &sFile, bool bEnable)
{
logger(sFile)->getWriteT().enableRemote(bEnable);
}
void TarsTimeLogger::enableRemoteEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable)
{
logger(sApp,sServer,sFile)->getWriteT().enableRemote(bEnable);
}
void TarsTimeLogger::enableLocal(const string &sFile, bool bEnable)
{
logger(sFile)->getWriteT().enableLocal(bEnable);
logger(sFile)->setRemote(!bEnable);
}
void TarsTimeLogger::enableLocalEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable)
{
logger(sApp,sServer,sFile)->getWriteT().enableLocal(bEnable);
logger(sApp,sServer,sFile)->setRemote(!bEnable);
}
}

View File

@ -1,116 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#include "util/tc_port.h"
#include "servant/TarsNodeF.h"
#include "servant/TarsLogger.h"
#include "servant/Communicator.h"
namespace tars
{
void TarsNodeFHelper::setNodeInfo(const CommunicatorPtr &comm, const string &obj, const string &app, const string &server)
{
_comm = comm;
if(!obj.empty())
{
_nodePrx = _comm->stringToProxy<ServerFPrx>(obj);
}
_si.application = app;
_si.serverName = server;
_si.pid = TC_Port::getpid();
}
void TarsNodeFHelper::keepAlive(const string &adapter)
{
try
{
if(_nodePrx)
{
set<string> s;
{
TC_LockT<TC_ThreadMutex> lock(*this);
_adapterSet.insert(adapter);
if(adapter != "AdminAdapter")
{
return;
}
s.swap(_adapterSet);
}
ServerInfo si = _si;
set<string>::const_iterator it = s.begin();
while(it != s.end())
{
si.adapter = *it;
_nodePrx->async_keepAlive(NULL,si);
++it;
}
}
}
catch(exception &ex)
{
TLOGERROR("TarsNodeFHelper::keepAlive error:" << ex.what() << endl);
}
catch(...)
{
TLOGERROR("TarsNodeFHelper::keepAlive unknown error" << endl);
}
}
void TarsNodeFHelper::keepActiving()
{
try
{
if(_nodePrx)
{
_nodePrx->async_keepActiving(NULL, _si);
}
}
catch(exception &ex)
{
LOG->error() << "TafNodeFHelper::keepAlive error:" << ex.what() << endl;
}
catch(...)
{
LOG->error() << "TafNodeFHelper::keepAlive unknown error" << endl;
}
}
void TarsNodeFHelper::reportVersion(const string &version)
{
try
{
if(_nodePrx)
{
_nodePrx->async_reportVersion(NULL, _si.application, _si.serverName, version);
}
}
catch(exception &ex)
{
TLOGERROR("TarsNodeFHelper::reportVersion error:" << ex.what() << endl);
}
catch(...)
{
TLOGERROR("TarsNodeFHelper::reportVersion unknown error" << endl);
}
}
}

View File

@ -1,132 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#include "servant/TarsNotify.h"
#include "servant/Communicator.h"
#include "servant/TarsLogger.h"
namespace tars
{
int TarsRemoteNotify::setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &sSetName, const string &nodeName)
{
_comm = comm;
if(!obj.empty())
{
_notifyPrx = _comm->stringToProxy<NotifyPrx>(obj);
_notifyPrx->tars_timeout(500);
}
_setName = sSetName;
_app = app;
_serverName = serverName;
_nodeName = nodeName;
return 0;
}
void TarsRemoteNotify::report(const string &sResult, bool bSync)
{
try
{
if(_notifyPrx)
{
ReportInfo info;
info.sApp = _app;
info.sServer = _serverName;
info.sSet = _setName;
info.sThreadId = TC_Common::tostr(std::this_thread::get_id());
info.sMessage = sResult;
info.sNodeName = _nodeName;
if(!bSync)
{
//_notifyPrx->async_reportServer(NULL, _app + "." + _serverName, TC_Common::tostr(std::this_thread::get_id()), sResult);
_notifyPrx->async_reportNotifyInfo(NULL, info);
}
else
{
//_notifyPrx->reportServer(_app + "." + _serverName, TC_Common::tostr(std::this_thread::get_id()), sResult);
_notifyPrx->reportNotifyInfo(info);
}
}
}
catch(exception &ex)
{
TLOGERROR("TarsRemoteNotify::report error:" << ex.what() << endl);
}
catch(...)
{
TLOGERROR("TarsRemoteNotify::report unknown error" << endl);
}
}
void TarsRemoteNotify::notify(NOTIFYLEVEL level, const string &sMessage)
{
try
{
if(_notifyPrx)
{
ReportInfo info;
// info.eType = 0;
info.sApp = _app;
info.sServer = _serverName;
info.sSet = _setName;
info.sThreadId = TC_Common::tostr(std::this_thread::get_id());
info.sMessage = sMessage;
info.eLevel = level;
info.sNodeName = _nodeName;
//_notifyPrx->async_notifyServer(NULL, _app + "." + _serverName, level, sMessage);
_notifyPrx->async_reportNotifyInfo(NULL, info);
}
}
catch(exception &ex)
{
TLOGERROR("TarsRemoteNotify::notify error:" << ex.what() << endl);
}
catch(...)
{
TLOGERROR("TarsRemoteNotify::notify unknown error" << endl);
}
}
void TarsRemoteNotify::report(const string &sMessage, const string & app, const string &serverName, const string &sNodeName)
{
try
{
if(_notifyPrx)
{
ReportInfo info;
// info.eType = 0;
info.sApp = app;
info.sServer = serverName;
info.sSet = "";
info.sMessage = sMessage;
info.sNodeName = sNodeName;
_notifyPrx->async_reportNotifyInfo(NULL, info);
}
}
catch(exception &ex)
{
TLOGERROR("TarsRemoteNotify::notify error:" << ex.what() << endl);
}
catch(...)
{
TLOGERROR("TarsRemoteNotify::notify unknown error" << endl);
}
}
}

View File

@ -17,7 +17,7 @@
#include "servant/Transceiver.h"
#include "servant/AdapterProxy.h"
#include "servant/Application.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#include "servant/AuthLogic.h"
#if TARS_SSL
@ -160,6 +160,7 @@ void Transceiver::setConnected()
{
_adapterProxy->getObjProxy()->getPushCallback()->onConnect(_ep.getEndpoint());
}
_adapterProxy->onConnect();
}
void Transceiver::onConnect()
@ -181,6 +182,7 @@ void Transceiver::onConnect()
_openssl->setReadBufferSize(1024 * 8);
_openssl->setWriteBufferSize(1024 * 8);
_openssl->recvBuffer()->setConnection(this);
int ret = _openssl->doHandshake(_sendBuffer);
if (ret != 0)
{
@ -212,7 +214,7 @@ void Transceiver::doAuthReq()
if (_adapterProxy->endpoint().authType() == AUTH_TYPENONE)
{
_authState = AUTH_SUCC;
_adapterProxy->doInvoke();
_adapterProxy->doInvoke(true);
}
else
{
@ -284,7 +286,7 @@ void Transceiver::doAuthReq()
//
// if (ret == TC_NetWorkBuffer::PACKET_ERR)
// {
// TLOGERROR("[TAF][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error" << endl);
// TLOGERROR("[TARS][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error" << endl);
// msg->eStatus = ReqMessage::REQ_NET;
// msg->response->sResultDesc = "recv packet decode failed";
//
@ -298,7 +300,7 @@ void Transceiver::doAuthReq()
// }
// catch (exception & ex) {
// TLOGERROR(
// "[TAF][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error:" << ex.what() << endl);
// "[TARS][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error:" << ex.what() << endl);
// msg->eStatus = ReqMessage::REQ_NET;
// msg->response->sResultDesc = "recv packet decode failed";
//
@ -306,7 +308,7 @@ void Transceiver::doAuthReq()
// }
// catch (...) {
// TLOGERROR(
// "[TAF][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error." << endl);
// "[TARS][tcp doResponse," << _pAdapterProxy->getObjProxy()->name() << ",fd:" << _iFd << "," << _ep.desc() << ",tcp recv decode error." << endl);
// msg->eStatus = ReqMessage::REQ_NET;
// msg->response->sResultDesc = "recv packet decode failed";
// }
@ -323,7 +325,7 @@ void Transceiver::doAuthReq()
void Transceiver::finishInvoke(shared_ptr<ResponsePacket> &rsp)
{
if (_authState != AUTH_SUCC)
if (_adapterProxy->endpoint().authType() == AUTH_TYPELOCAL && _authState != AUTH_SUCC)
{
std::string ret(rsp->sBuffer.begin(), rsp->sBuffer.end());
tars::AUTH_STATE tmp = AUTH_SUCC;
@ -336,7 +338,7 @@ void Transceiver::finishInvoke(shared_ptr<ResponsePacket> &rsp)
if (newstate == AUTH_SUCC)
{
// flush old buffered msg when auth is not complete
_adapterProxy->doInvoke();
_adapterProxy->doInvoke(true);
}
else
{
@ -406,7 +408,7 @@ void Transceiver::close()
if(!isValid()) return;
#if TAF_SSL
#if TARS_SSL
if (_openssl)
{
_openssl->release();
@ -437,11 +439,11 @@ void Transceiver::close()
if(second > 0) {
_adapterProxy->getObjProxy()->getCommunicatorEpoll()->reConnect(TNOWMS + second * 1000, this);
TLOGERROR("[TAF][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << ", reconnect:" << second << "]" << endl);
TLOGERROR("[TARS][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << ", reconnect:" << second << "]" << endl);
}
// else
// {
// TLOGERROR("[TAF][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << "]" << endl);
// TLOGERROR("[TARS][trans close:" << _adapterProxy->getObjProxy()->name() << "," << _ep.desc() << "]" << endl);
// }
}
@ -467,7 +469,7 @@ int Transceiver::doRequest()
//取adapter里面积攒的数据
if(_sendBuffer.empty()) {
_adapterProxy->doInvoke();
_adapterProxy->doInvoke(false);
}
//object里面应该是空的
@ -939,7 +941,7 @@ UdpTransceiver::UdpTransceiver(AdapterProxy * pAdapterProxy, const EndpointInfo
_pRecvBuffer = new char[DEFAULT_RECV_BUFFERSIZE];
if(!_pRecvBuffer)
{
throw TC_Exception("objproxy '" + _adapterProxy->getObjProxy()->name() + "' malloc udp receive buffer fail");
throw TC_Exception("obj: '" + _adapterProxy->getObjProxy()->name() + "' malloc udp receive buffer fail");
}
}

View File

@ -42,8 +42,8 @@ MYSQL_LIB_DIR += -L/usr/local/mysql/lib/mysql -L/usr/local/mysql/lib -L/usr/li
LIB_DIR += ${MYSQL_LIB_DIR}
INC_DIR += ${MYSQL_INC}
ifneq ($(_USE_OPENTRACKING), 0)
ifneq ($(_USE_OPENTRACKING), )
ifneq ($(TARS_OPENTRACKING), 0)
ifneq ($(TARS_OPENTRACKING), )
OPENTRACKING_INC += -I/usr/local/include
OPENTRACKING_LIB_DIR += -L/usr/local/lib
LIB_DIR += ${OPENTRACKING_LIB_DIR}
@ -72,8 +72,8 @@ ifneq ($(TARS_HTTP2), )
endif
endif
ifneq ($(_USE_OPENTRACKING), 0)
ifneq ($(_USE_OPENTRACKING), )
ifneq ($(TARS_OPENTRACKING), 0)
ifneq ($(TARS_OPENTRACKING), )
#业务编译
CFLAGS += -D_USE_OPENTRACKING=1
LIB += -lopentracing -lzipkin_opentracing -lzipkin -lcurl

View File

@ -26,7 +26,9 @@
#include "servant/Message.h"
#include "servant/StatReport.h"
#include <queue>
#ifdef _USE_OPENTRACKING
#include <unordered_map>
#ifdef TARS_OPENTRACKING
#include <opentracing/span.h>
#endif
namespace tars
@ -52,14 +54,30 @@ public:
/**
* server
* @param req
* @return int
*/
int invoke(ReqMessage * msg);
int invoke(ReqMessage * msg);
// /**
// * 同步阻塞调用server
// * @param msg
// * @return
// */
// bool invoke_sync(ReqMessage * msg);
/**
*
*/
void onConnect();
/**
*
*
* @param req
* @return
*/
void doInvoke();
void doInvoke(bool initInvoke);
/**
* server
@ -91,9 +109,9 @@ public:
/**
*
*/
void sample(ReqMessage * msg);
// void sample(ReqMessage * msg);
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
/**
* Zipkin
*/
@ -169,6 +187,17 @@ public:
*/
inline int getId() const { return _id; }
/**
*
* @return
*/
inline Transceiver* getTransceiver() const { return _trans.get(); }
/**
*
*/
void onSetInactive();
private:
/**
@ -204,9 +233,31 @@ private:
void merge(const StatMicMsgBody& inBody, StatMicMsgBody& outBody);
/**
*
*
* @param msg
* @return
*/
string getSlaveName(const string& sSlaveName);
int invoke_connection_serial(ReqMessage * msg);
/**
*
* @param msg
* @return
*/
int invoke_connection_parallel(ReqMessage * msg);
void finishInvoke_serial(shared_ptr<ResponsePacket> & rsp);
void finishInvoke_parallel(shared_ptr<ResponsePacket> & rsp);
void doInvoke_serial();
void doInvoke_parallel();
/**
*
*/
string getSlaveName(const string& sSlaveName);
private:
@ -225,6 +276,11 @@ private:
*/
EndpointInfo _endpoint;
/**
* in request
*/
ReqMessage* _requestMsg = NULL;
/*
*
*/
@ -315,20 +371,10 @@ private:
*/
map<string,StatMicMsgBody> _statBody;
/*
*
*/
uint32_t _maxSampleCount;
/*
*
*/
int _sampleRate;
/*
*
*/
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
map<int,std::unique_ptr<opentracing::Span>> _spanMap;
#endif
int _id;

View File

@ -22,7 +22,7 @@
namespace tars
{
class TarsCurrent;
class Current;
class Application;
////////////////////////////////////////////////////////////////////////

View File

@ -26,7 +26,7 @@
#include "util/tc_timeprovider.h"
#include "util/tc_file.h"
#include "util/tc_thread_mutex.h"
#include "servant/TarsLogger.h"
#include "servant/RemoteLogger.h"
#define APPCACHE_ROOT_PATH "/cache"
@ -38,7 +38,7 @@ namespace tars
/**
*
*/
class AppCache : public TC_Singleton<AppCache>, public TC_ThreadMutex
class SVT_DLL_API AppCache : public TC_Singleton<AppCache>, public TC_ThreadMutex
{
public:
AppCache()

View File

@ -143,6 +143,8 @@ public:
static vector<char> http1Request(tars::RequestPacket& request, Transceiver *);
static TC_NetWorkBuffer::PACKET_TYPE http1Response(TC_NetWorkBuffer &in, ResponsePacket& done);
// static vector<char> httpJceRequest(taf::RequestPacket& request, Transceiver *);
// static TC_NetWorkBuffer::PACKET_TYPE httpJceResponse(TC_NetWorkBuffer &in, ResponsePacket& done);
#if TARS_HTTP2
// ENCODE function, called by network thread

View File

@ -30,9 +30,9 @@
#include "servant/ServantHandle.h"
#include "servant/StatReport.h"
#include "servant/CommunicatorFactory.h"
#include "servant/TarsLogger.h"
#include "servant/TarsConfig.h"
#include "servant/TarsNotify.h"
#include "servant/RemoteLogger.h"
#include "servant/RemoteConfig.h"
#include "servant/RemoteNotify.h"
#if TARS_SSL
#include "util/tc_openssl.h"
@ -62,27 +62,28 @@ namespace tars
#define TARS_CMD_CLOSE_CORE "tars.closecore" //设置服务的core limit: tars.setlimit [yes|no]
#define TARS_CMD_RELOAD_LOCATOR "tars.reloadlocator" //重新加载locator的配置信息
#define TARS_CMD_RESOURCE "tars.resource" //get resource
#define TARS_CMD_VIEW_BID "tars.bid" //查看服务编译时间,build id
//////////////////////////////////////////////////////////////////////
/**
* notify,
*/
//上报普通信息
#define TARS_NOTIFY_NORMAL(info) {TarsRemoteNotify::getInstance()->notify(NOTIFYNORMAL, info);}
#define TARS_NOTIFY_NORMAL(info) {RemoteNotify::getInstance()->notify(NOTIFYNORMAL, info);}
//上报警告信息
#define TARS_NOTIFY_WARN(info) {TarsRemoteNotify::getInstance()->notify(NOTIFYWARN, info);}
#define TARS_NOTIFY_WARN(info) {RemoteNotify::getInstance()->notify(NOTIFYWARN, info);}
//上报错误信息
#define TARS_NOTIFY_ERROR(info) {TarsRemoteNotify::getInstance()->notify(NOTIFYERROR, info);}
#define TARS_NOTIFY_ERROR(info) {RemoteNotify::getInstance()->notify(NOTIFYERROR, info);}
//发送心跳给node 多个adapter分别上报
#define TARS_KEEPALIVE(adapter) {TarsNodeFHelper::getInstance()->keepAlive(adapter);}
#define TARS_KEEPALIVE(adapter) {KeepAliveNodeFHelper::getInstance()->keepAlive(adapter);}
//发送激活信息
#define TARS_KEEPACTIVING {TarsNodeFHelper::getInstance()->keepActiving();}
#define TARS_KEEPACTIVING {KeepAliveNodeFHelper::getInstance()->keepActiving();}
//发送TARS版本给node
#define TARS_REPORTVERSION(x) {TarsNodeFHelper::getInstance()->reportVersion(TARS_VERSION);}
#define TARS_REPORTVERSION(x) {KeepAliveNodeFHelper::getInstance()->reportVersion(TARS_VERSION);}
//////////////////////////////////////////////////////////////////////
/**
@ -105,7 +106,7 @@ namespace tars
/**
*
*/
struct ServerConfig
struct SVT_DLL_API ServerConfig
{
static std::string TarsPath;
static std::string Application; //应用名称
@ -139,6 +140,7 @@ struct ServerConfig
static std::string Cert;
static std::string Key;
static bool VerifyClient;
static std::string Ciphers;
#endif
static map<string, string> Context; //框架内部用, 传递节点名称(以域名形式部署时)
};
@ -326,7 +328,17 @@ protected:
*
* @return bool
*/
bool cmdViewVersion(const string& command, const string& params, string& result);
bool cmdViewVersion(const string &command, const string &params, string &result);
/**
* buildid
* @param command
* @param params
* @param result
*
* @return bool
*/
bool cmdViewBuildID(const string &command, const string &params, string &result);
/**
* 使property

View File

@ -26,8 +26,8 @@
#include "servant/ObjectProxyFactory.h"
#include "servant/AsyncProcThread.h"
#include "servant/CommunicatorEpoll.h"
#include "servant/TarsLogger.h"
#ifdef _USE_OPENTRACKING
#include "servant/RemoteLogger.h"
#ifdef TARS_OPENTRACKING
#include "zipkin/opentracing.h"
#include "zipkin/tracer.h"
#include "zipkin/ip_address.h"
@ -77,10 +77,11 @@ struct ClientConfig
/**
* ,proxy
*/
class Communicator : public TC_HandleBase, public TC_ThreadRecMutex
class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex
{
public:
typedef std::function<void(ReqMessagePtr)> custom_callback;
/**
*
*/
@ -195,6 +196,11 @@ public:
*/
string getServantProperty(const string &sObj, const string& name);
/**
*
*/
void setServantCustomCallback(const string &sObj, custom_callback callback);
/**
*
* @return StatReport*
@ -218,12 +224,12 @@ public:
*/
vector<TC_Endpoint> getEndpoint(const string & objName);
/**
* objip port IDC
* @param sObjName
* @return vector<TC_Endpoint>
*/
vector<TC_Endpoint> getEndpoint4All(const string & objName);
/**
* objip port IDC
* @param sObjName
* @return vector<TC_Endpoint>
*/
vector<TC_Endpoint> getEndpoint4All(const string& objName);
/**
*
@ -244,7 +250,7 @@ public:
* get resource info
* @return
*/
string getResouresInfo();
string getResourcesInfo();
protected:
/**
@ -376,6 +382,16 @@ protected:
unordered_map<string, shared_ptr<TC_OpenSSL::CTX>> _objCtx;
#endif
/**
*
*/
TC_SpinLock _callbackLock;
/**
* callback
*/
unordered_map<string, custom_callback> _callback;
/*
* 线
*/
@ -396,7 +412,7 @@ protected:
*/
size_t _asyncSeq = 0;
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
public:
struct TraceManager:public TC_HandleBase{
zipkin::ZipkinOtTracerOptions _zipkin_options;

View File

@ -65,13 +65,9 @@ struct FDInfo
}
size_t iSeq;
int fd;
int iType;
int fd;
int iType;
void * p;
TC_Epoller::NotifyInfo notify;
};
@ -82,6 +78,7 @@ struct FDInfo
class CommunicatorEpoll : public TC_Thread ,public TC_ThreadRecMutex
{
public:
/**
*
*/
@ -190,7 +187,7 @@ public:
* communicator resource desc
* @return
*/
string getResouresInfo();
string getResourcesInfo();
protected:
/**

View File

@ -33,8 +33,8 @@ namespace tars
enum GetEndpointType
{
E_DEFAULT = 0,
E_ALL = 1,
E_SET = 2,
E_ALL = 1,
E_SET = 2,
E_STATION = 3
};
@ -129,9 +129,9 @@ public:
*/
virtual void doNotify() = 0;
/*
*
*/
/*
*
*/
int setLocatorPrx(QueryFPrx prx);
/*
@ -168,7 +168,7 @@ private:
/*
* ,
*/
void doEndpoints(const vector<tars::EndpointF>& activeEp, const vector<tars::EndpointF>& inactiveEp, int iRet, bool bSync = false);
void doEndpoints(const vector<EndpointF>& activeEp, const vector<EndpointF>& inactiveEp, int iRet, bool bSync = false);
/*
* ,
@ -246,6 +246,11 @@ protected:
*/
set<EndpointInfo> _inactiveEndpoints;
/**
* root servant
*/
bool _rootServant;
private:
/////////以下是请求主控的策略信息/////////////////
@ -334,7 +339,14 @@ public:
*/
void notifyEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive, bool bSync = false);
/*
/**
*
* @param active
* @param inactive
*/
void updateEndpoints(const set<EndpointInfo> & active, const set<EndpointInfo> & inactive);
/*
*
*/
void doNotify();

View File

@ -50,7 +50,7 @@ class AdapterProxy;
class ServantProxy;
class ServantProxyCallback;
class ObjectProxy;
class TarsCurrent;
class Current;
class FDReactor;
class Transceiver;
class StatFProxy;
@ -58,19 +58,27 @@ class StatReport;
class ServantProxyFactory;
class ObjectProxyFactory;
class AsyncProcThread;
class LocalRollLogger;
class RemoteConfig;
class RemoteTimeLogger;
class RemoteNotify;
typedef TC_AutoPtr<Communicator> CommunicatorPtr;
typedef TC_AutoPtr<ServantProxy> ServantPrx;
typedef TC_AutoPtr<ServantProxyCallback> ServantProxyCallbackPtr;
typedef TC_AutoPtr<ObjectProxy> ObjectPrx;
typedef TC_AutoPtr<TarsCurrent> TarsCurrentPtr;
typedef TC_AutoPtr<Current> CurrentPtr;
typedef TC_AutoPtr<StatFProxy> StatFPrx;
typedef TC_AutoPtr<StatReport> StatReportPtr;
typedef TC_AutoPtr<FDReactor> FDReactorPtr;
// typedef TC_AutoPtr<ServantProxyFactory> ServantProxyFactoryPtr;
//typedef TC_AutoPtr<ObjectProxyFactory> ObjectProxyFactoryPtr;
typedef TC_AutoPtr<AsyncProcThread> AsyncProcThreadPtr;
typedef CurrentPtr TarsCurrentPtr;
typedef RemoteConfig TarsRemoteConfig;
typedef RemoteNotify TarsRemoteNotify;
typedef LocalRollLogger TarsRollLogger;
typedef RemoteTimeLogger TarsTimeLogger;
//////////////////////////////////////////////////////////////
/**
* TARS

View File

@ -49,8 +49,8 @@ struct CheckTimeoutInfo
, frequenceFailInvoke(5)
, minFrequenceFailTime(5)
, radio(0.5)
, tryTimeInterval(30)
, maxConnectExc(5)
, tryTimeInterval(10)
, maxConnectExc(1)
{
}
@ -90,61 +90,6 @@ struct CheckTimeoutInfo
uint32_t maxConnectExc;
};
/////////////////////////////////////////////////////////////////////////
/*
* stat()
*/
struct SampleKey
{
/*
*
*/
SampleKey()
: _root(true)
, _unid("")
, _depth(0)
, _width(0)
, _parentWidth(0)
{}
/*
*
*/
void init()
{
_root = true;
_unid.clear();
_depth = 0;
_width = 0;
_parentWidth = 0;
}
/*
* id
*/
bool _root;
/*
* id
*/
string _unid;
/*
*
*/
int _depth;
/*
* 广
*/
int _width;
/*
* 广
*/
int _parentWidth;
};
/////////////////////////////////////////////////////////////////////////
/**
*
@ -211,6 +156,11 @@ struct ReqMessage : public TC_HandleBase
*/
~ReqMessage()
{
if(deconstructor)
{
deconstructor();
}
if(pMonitor != NULL)
{
delete pMonitor;
@ -263,6 +213,7 @@ struct ReqMessage : public TC_HandleBase
ObjectProxy * pObjectProxy; //调用端的proxy对象
RequestPacket request; //请求消息体
std::function<void()> deconstructor; //析构时调用
shared_ptr<ResponsePacket> response; //响应消息体
// string sReqData; //请求消息体
shared_ptr<TC_NetWorkBuffer::Buffer> sReqData; //请求消息体
@ -289,7 +240,7 @@ struct ReqMessage : public TC_HandleBase
uint32_t iCoroId; //协程的id
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
std::unordered_map<std::string, std::string> trackInfoMap; //调用链信息
#endif
@ -299,7 +250,6 @@ struct ReqMessage : public TC_HandleBase
typedef TC_AutoPtr<ReqMessage> ReqMessagePtr;
typedef TC_LoopQueue<ReqMessage*> ReqInfoQueue;
#define HTTP2 "http2"
}

View File

@ -18,7 +18,7 @@
#define __TARS_NOTIFY_OBSERVER_H_
#include "servant/Global.h"
#include "servant/TarsCurrent.h"
#include "servant/Current.h"
#include "util/tc_singleton.h"
namespace tars

View File

@ -87,6 +87,19 @@ public:
*/
void doInvoke();
/**
*
* @param adapterProxy
*/
// void doInvoke(AdapterProxy *adapterProxy);
/**
*
* @param active
* @param inactive
*/
void onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive);
/**
*
* @return UserProtocol&
@ -121,10 +134,13 @@ public:
ServantProxyCallbackPtr getPushCallback();
/**
* connected
*/
void onConnect(AdapterProxy *adapterProxy);
/**
* adapter
*/
// const vector<AdapterProxy*> & getAdapters() const;
void mergeStat(map<StatMicMsgHead, StatMicMsgBody> & mStatMicMsg);
/**
@ -132,14 +148,6 @@ public:
*/
void doTimeout();
// /**
// * Obj的超时队列的长度
// */
// size_t timeoutQSize()
// {
// return _reqTimeoutQueue.size();
// }
//
/**
* CommunicatorEpoll*
*/
@ -157,6 +165,24 @@ public:
return _name;
}
/**
* address
* @return
*/
inline const string &hash() const
{
return _hash;
}
/**
* address
* @return
*/
inline const string &address() const
{
return _address;
}
/**
* reconnect
* @param second
@ -233,18 +259,34 @@ public:
_servantProxy = pServantProxy;
}
/**
*
* @return
*/
inline EndpointManager* getEndpointManager()
{
return _endpointManger.get();
}
/**
* get all adapter proxy
* @return
*/
const vector<AdapterProxy*> & getAdapters();
/**
*
* @param ep
*/
void onSetInactive(const EndpointInfo& ep);
protected:
/**
*
*/
void doInvokeException(ReqMessage * msg);
/**
*
*
*/
void doInvokeException(ReqMessage * msg);
private:
/*
@ -253,10 +295,22 @@ private:
CommunicatorEpoll * _communicatorEpoll;
/*
* object
* [obname]#hash@tcp -h xxxx -p xxx
*/
string _name;
/**
* obname#[hash]@tcp -h xxxx -p xxx
* ever hash has one connection
*/
string _hash;
/**
* obname#hash@[tcp -h xxxx -p xxx]
* ever hash has one connection
*/
string _address;
/*
* setset
*/
@ -268,7 +322,7 @@ private:
bool _isInvokeBySet;
/*
* tars_set_protocolproxy
* taf_set_protocolproxy
*
*/
bool _hasSetProtocol;

View File

@ -19,7 +19,7 @@
#include "util/tc_lock.h"
#include "util/tc_autoptr.h"
//#include "util/tc_thread_mutex.h"
#include "util/tc_thread_mutex.h"
#include "util/tc_spin_lock.h"
#include <tuple>
#include <vector>
@ -80,7 +80,7 @@ public:
string get();
void set(int o) { _sum += o;++_count; }
protected:
void clear() { _sum = 0; _count = 0; }
void clear() { _sum = 0; _count = 0; }
private:
int _sum;
int _count;
@ -170,7 +170,7 @@ typedef TC_AutoPtr<PropertyReport> PropertyReportPtr;
*/
template <typename... Params>
class PropertyReportImp : public PropertyReport, public TC_SpinLock
class PropertyReportImp : public PropertyReport, public TC_ThreadMutex
{
public:
using PropertyReportData = std::tuple<Params...>;
@ -195,7 +195,7 @@ public:
*/
void report(int iValue) override
{
TC_LockT<TC_SpinLock> lock(*this);
TC_LockT<TC_ThreadMutex> lock(*this);
Helper<std::tuple_size<decltype(_propertyReportData)>::value>::Report(*this, iValue);
}
@ -207,7 +207,7 @@ public:
*/
vector<pair<string, string> > get() override
{
TC_LockT<TC_SpinLock> lock(*this);
TC_LockT<TC_ThreadMutex> lock(*this);
return Helper<std::tuple_size<decltype(_propertyReportData)>::value>::Get(*this);
}

View File

@ -22,7 +22,7 @@
#include "util/tc_thread_pool.h"
#include "util/tc_cas_queue.h"
#include "servant/ServantProxy.h"
#include "servant/TarsCurrent.h"
#include "servant/Current.h"
#include "servant/BaseNotify.h"
namespace tars
@ -250,7 +250,7 @@ protected:
ServantPtr _servant;
/*
* TarsCurrent
* Current
*/
TarsCurrentPtr _current;
};

View File

@ -27,7 +27,7 @@
#include "servant/Servant.h"
#include "servant/StatReport.h"
#include "servant/CoroutineScheduler.h"
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
#include "opentracing/span.h"
#endif
@ -58,10 +58,10 @@ public:
*/
~ServantHandle();
/**
* 线
*/
virtual void run();
/**
* 线
*/
virtual void run();
/**
*
@ -136,14 +136,14 @@ protected:
/**
*
* @param stRecvData
* @return TarsCurrent*
* @return Current*
*/
TarsCurrentPtr createCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data);
/**
*
* @param stRecvData
* @return TarsCurrent*
* @return Current*
*/
TarsCurrentPtr createCloseCurrent(const shared_ptr<TC_EpollServer::RecvContext> &data);
@ -161,14 +161,8 @@ protected:
*/
void handleNoTarsProtocol(const TarsCurrentPtr &current);
/**
* TARS
*
* @param current
*/
void processSample(const TarsCurrentPtr &current);
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
/**
* TARS
*
@ -211,7 +205,7 @@ protected:
*/
CoroutineScheduler *_coroSched;
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
map<int,std::unique_ptr<opentracing::Span>> _spanMap;
#endif
};

View File

@ -56,7 +56,7 @@ struct ServantCreation : public ServantHelperCreation
/**
* Servant
*/
class ServantHelperManager : public TC_Singleton<ServantHelperManager>
class SVT_DLL_API ServantHelperManager : public TC_Singleton<ServantHelperManager>
{
public:
/**
@ -77,8 +77,8 @@ public:
{
if(check && _servant_adapter.end() == _servant_adapter.find(id))
{
cerr<<"[TAF]ServantHelperManager::addServant "<< id <<" not find adapter.(maybe not conf in the web)"<<endl;
throw runtime_error("[TAF]ServantHelperManager::addServant " + id + " not find adapter.(maybe not conf in the web)");
cerr<<"[TARS]ServantHelperManager::addServant "<< id <<" not find adapter.(maybe not conf in the web)"<<endl;
throw runtime_error("[TARS]ServantHelperManager::addServant " + id + " not find adapter.(maybe not conf in the web)");
}
_servant_creator[id] = new ServantCreation<T>(application);
}
@ -188,7 +188,7 @@ protected:
/**
*
*/
bool _isDyeing;
bool _isDyeing;
/**
*

View File

@ -21,7 +21,7 @@
#include "util/tc_autoptr.h"
#include "servant/Message.h"
#include "servant/AppProtocol.h"
#include "servant/TarsCurrent.h"
#include "servant/Current.h"
//#include "servant/EndpointInfo.h"
#include "servant/CommunicatorEpoll.h"
@ -148,7 +148,7 @@ public:
* objectProxy Pointer
*/
shared_ptr<ObjectProxy *> _objectProxyOwn; //保存ObjectProxy对象的指针数组
#ifdef _USE_OPENTRACKING
#ifdef TARS_OPENTRACKING
std::unordered_map<std::string, std::string> _trackInfoMap;
#endif
@ -264,6 +264,12 @@ public:
*/
virtual ~ServantProxyCallback() {}
/**
* servant
* @param prx
*/
void setServantPrx(const ServantPrx &prx) { _servantPrx = prx; }
/**
*
* @return const string&
@ -288,7 +294,7 @@ public:
/**
* 线
* tars
* taf
* */
inline void setNetThreadProcess(bool bNetThreadProcess)
{
@ -301,23 +307,32 @@ public:
}
public:
/**
* dispatch, call onDispatch
* @param msg
* @return
*/
int dispatch(ReqMessagePtr msg);
protected:
/**
*
* @param msg
* @return int
*/
virtual int onDispatch(ReqMessagePtr ptr) = 0;
virtual int onDispatch(ReqMessagePtr msg) = 0;
/**
* (PUSH callback)
* (push callback )
*/
virtual void onClose(){};
/**
* (PUSH callback)
* (push callback )
*/
virtual void onConnect(const TC_Endpoint &ep){};
friend class Transceiver;
protected:
/**
@ -334,18 +349,20 @@ protected:
/**
*
*/
tars::CoroParallelBasePtr _pPtr;
CoroParallelBasePtr _pPtr;
/**
* servant prx
*/
ServantPrx _servantPrx;
};
///////////////////////////////////////////////////////////////////////////////////////////////
// for http
class HttpCallback : public TC_HandleBase
{
public:
virtual int onHttpResponse(const std::map<std::string, std::string>& requestHeaders ,
const std::map<std::string, std::string>& responseHeaders ,
const std::vector<char>& rspBody) = 0;
virtual int onHttpResponseException(const std::map<std::string, std::string>& requestHeaders,
int expCode) = 0;
virtual int onHttpResponse(const shared_ptr<TC_HttpResponse> &rsp) = 0;
virtual int onHttpResponseException(int expCode) = 0;
};
typedef TC_AutoPtr<HttpCallback> HttpCallbackPtr;
@ -411,7 +428,7 @@ public:
static string STATUS_TRACK_KEY; //track信息
static string STATUS_COOKIE; //cookie信息
// static string STATUS_COOKIE; //cookie信息
/**
*
@ -419,6 +436,23 @@ public:
*/
enum { DEFAULT_SYNCTIMEOUT = 3000, DEFAULT_ASYNCTIMEOUT=5000};
/**
* default connection serial num
*/
const static int DEFAULT_CONNECTION_SERIAL = 10;
/**
*
*/
enum SERVANT_PROTOCOL
{
PROTOCOL_TARS, //默认tars服务的协议
PROTOCOL_HTTP1, //http协议
#if TARS_HTTP2
PROTOCOL_HTTP2, //http2协议
#endif
};
/**
*
* @param op
@ -528,19 +562,48 @@ public:
*/
string tars_name() const;
/**
* Object#hash@address
* @return string
*/
string tars_full_name() const;
/**
* IP
* @return string
*/
static TC_Endpoint tars_invoke_endpoint();
/**
* ,
* @param connectionSerial, <=0: (, ), >0: (), (http)
*/
void tars_connection_serial(int connectionSerial);
/**
*
* @return int
*/
int tars_connection_serial() const;
/**
*
*/
void tars_set_protocol(SERVANT_PROTOCOL protocol, int connectionSerial = 0);
/**
*
* @param protocol
*/
void tars_set_protocol(const ProxyProtocol& protocol);
void tars_set_protocol(const ProxyProtocol& protocol, int connectionSerial = 0);
/**
* get protocol
* @return
*/
ProxyProtocol tars_get_protocol();
/**
*
*/
void tars_set_sockopt(int level, int optname, const void *optval, SOCKET_LEN_TYPE optlen);
@ -643,28 +706,19 @@ public:
// std::map<std::string, std::string>& rheaders,
// std::string& rbody);
/**
* http2
*/
void http_call(const std::string& method,
const std::string& uri,
const std::map<std::string, std::string>& headers,
const std::string& body,
std::map<std::string, std::string>& rheaders,
std::string& rbody);
/**
* http2
*/
void http_call_async(const std::string& method,
const std::string& uri,
const std::map<std::string, std::string>& headers,
const std::string& body,
const HttpCallbackPtr &cb);
/**
* http1/2
* @param funcName: ,
*/
void http_call(const string &funcName, shared_ptr<TC_HttpRequest> &request, shared_ptr<TC_HttpResponse> &response);
/**
* RequestPacketcontext
*/
virtual void tars_setMasterFlag(bool bMasterFlag) {_masterFlag = bMasterFlag;}
/**
* http1/2
* @param funcName: ,
*/
void http_call_async(const string &funcName, shared_ptr<TC_HttpRequest> &request, const HttpCallbackPtr &cb, bool bCoro = false);
protected:
/**
* TARS
@ -686,6 +740,14 @@ public:
const ServantProxyCallbackPtr& callback,
bool bCoro = false);
/**
* servant
* @return
*/
ServantPrx getServantPrx(ReqMessage *msg);
friend class ServantProxyCallback;
private:
/**
*
@ -694,6 +756,13 @@ private:
*/
void invoke(ReqMessage *msg, bool bCoroAsync = false);
/**
* servant
* @param msg
* @param bCoroAsync
*/
int servant_invoke(ReqMessage *msg, bool bCoroAsync);
// /**
// * invoke 异步
// * @param msg
@ -724,6 +793,17 @@ private:
*/
void checkDye(RequestPacket& req);
/**
* endpoint
* @param active
* @param inactive
*/
void onNotifyEndpoints(const set<EndpointInfo> & active,const set<EndpointInfo> & inactive);
/**
*
*/
void onSetInactive(const EndpointInfo& ep);
/**
* cookie
* @param req
@ -737,29 +817,29 @@ private:
/**
*
*/
Communicator * _communicator;
Communicator * _communicator;
/**
* ObjectProxy
*/
ObjectProxy ** _objectProxy; //保存ObjectProxy对象的指针数组
shared_ptr<ObjectProxy *> _objectProxyOwn; //保存ObjectProxy对象的指针数组
ObjectProxy ** _objectProxy; //保存ObjectProxy对象的指针数组
shared_ptr<ObjectProxy *> _objectProxyOwn; //保存ObjectProxy对象的指针数组
/**
* ObjectProxy线
* 线ObjectProxy
*/
size_t _objectProxyNum;
size_t _objectProxyNum;
/**
* ()
*/
int _syncTimeout;
int _syncTimeout;
/**
* ()
*/
int _asyncTimeout;
int _asyncTimeout;
/**
* id
@ -780,6 +860,31 @@ private:
*
*/
int64_t _minTimeout;
/**
* (0, )
*/
int _connectionSerial = 0;
/**
* 使http使
*/
ServantPrx _rootPrx;
/**
*
*/
int _servantId = 0;
/**
*
*/
std::mutex _servantMutex;
/**
*
*/
vector<ServantPrx> _servantList;
};
}
#endif

View File

@ -42,6 +42,11 @@
namespace tars
{
/**
* , :
* 1
* 2
*/
struct StatSampleMsgHead
{
string slaveName;

View File

@ -1,154 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TARS_CONFIG_H_
#define __TARS_CONFIG_H_
#include "util/tc_autoptr.h"
#include "util/tc_singleton.h"
#include "servant/Global.h"
#include "servant/ConfigF.h"
using namespace std;
namespace tars
{
/**
*
*
*
* ConfigServer
* ()
*
*
* addConfig
* TarsRemoteConfig
*
* 5
*
*
*/
class TarsRemoteConfig : public TC_Singleton<TarsRemoteConfig>
{
public:
/**
*
* @param comm,
* @param obj,
* @param app,
* @param serverName,
* @param basePath,
* @param maxBakNum,
*
* @return int
*/
int setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision="",int maxBakNum = 5);
/**
* ConfigServer
* @param sFullFileName
* @param result
* @param bAppOnly
*
* @return bool
*/
bool addConfig(const string & filename, string &result, bool bAppConfigOnly = false);
private:
/**
* ConfigServer
* @param sFullFileName
* @param bAppOnly
*
* @return string
*/
string getRemoteFile(const string & sFullFileName, bool bAppConfigOnly = false);
/**
*
* 使
*
* @return string
*/
string recoverSysConfig(const string & sFullFileName);
/**
* Config.conf.1.bak,Config.conf.2.bak ...
*
*
* @param index
*
* @return string
*/
inline string index2file(const string & sFullFileName, int index);
/**
* renameoldFile
*
* @param oldFile
* @param newFile
*/
inline void localRename(const string& oldFile, const string& newFile);
protected:
/**
*
*/
CommunicatorPtr _comm;
/**
*
*/
ConfigPrx _configPrx;
/**
*
*/
string _app;
/**
*
*/
string _serverName;
/**
*
*/
string _basePath;
/**
* set
*/
string _setdivision;
/**
*
*/
int _maxBakNum;
/**
* 线
*/
TC_ThreadMutex _mutex;
};
}
#endif

View File

@ -1,72 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TARS_COOKIE_H__
#define __TARS_COOKIE_H__
/**
* cookie
*/
class TarsCookieOp
{
public:
/**
*
*/
TarsCookieOp()
{
}
/**
* cookie
*/
~TarsCookieOp()
{
ServantProxyThreadData * td = ServantProxyThreadData::getData();
assert(NULL != td);
if (td)
{
td->_cookie.clear();
}
}
/**
* cookie
*/
static map<string, string> & getCookie()
{
ServantProxyThreadData * td = ServantProxyThreadData::getData();
assert(NULL != td);
return td->_cookie;
}
/**
* cookie
*/
void setCookie(const map<string, string> &cookie)
{
ServantProxyThreadData * td = ServantProxyThreadData::getData();
assert(NULL != td);
if(td)
{
td->_cookie = cookie;
}
}
};
#endif

View File

@ -1,330 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TARS_CURRENT_H_
#define __TARS_CURRENT_H_
#include "util/tc_epoll_server.h"
#include "tup/RequestF.h"
#include "tup/tup.h"
#include "servant/BaseF.h"
namespace tars
{
class ServantHandle;
//////////////////////////////////////////////////////////////
/**
*
*/
class TarsCurrent : public TC_HandleBase
{
public:
typedef std::map<string, string> TARS_STATUS;
typedef std::vector<char> TARS_BUFFER;
/**
*
* @param pServantHandle
*/
TarsCurrent(ServantHandle *pServantHandle);
/**
*
*/
~TarsCurrent();
/**
* IP
* @return string
*/
const string &getIp() const;
/**
* get host name
* @return
*/
const string &getHostName() const;
/**
*
* @return int
*/
int getPort() const;
/**
* uid
* @return uint32
*/
uint32_t getUId() const;
/**
* fd
* @return int
*/
int getFd() const { return _data->fd(); }
/**
*
* @return bool
*/
bool isResponse() const;
/**
* TC_EpollServer::EM_CLOSE_T
*/
void setCloseType(int type);
/**
* TC_EpollServer::EM_CLOSE_T
*/
int getCloseType() const;
/**
*
*/
void setResponse(bool value) { _response = value; }
/**
* context(TARS)
*/
void setResponseContext(const map<std::string, std::string> & context){_responseContext = context;}
/**
* context(TARS)
*/
const map<std::string, std::string> & getResponseContext() const {return _responseContext;}
/**
*
*/
void close();
/**
* ServantHandle
*/
ServantHandle* getServantHandle();
/**
* Adapter
* @return TC_EpollServer::BindAdapter*
*/
TC_EpollServer::BindAdapter* getBindAdapter();
/**
* buffer
* @return string
*/
const vector<char> &getRequestBuffer() const;
/**
* Servant
* @return string
*/
string getServantName() const;
/**
* (TARS)
*
* @return short
*/
short getRequestVersion() const;
/**
* map(TARS)
* @return map<string,string>&
*/
map<string, string>& getContext();
/**
* (TARS)
* @return map<string,string>&
*/
const map<string, string>& getRequestStatus() const;
/**
* (TARS)
* @return string
*/
string getFuncName() const;
/**
* ID(TARS)
* @return int
*/
uint32_t getRequestId() const;
/**
* (TARS)
* @return char
*/
char getPacketType() const;
/**
* (TARS)
* @return tars::Int32
*/
tars::Int32 getMessageType() const;
/**
*
*/
struct timeval getRecvTime() const;
/**
*
*/
void setReportStat(bool bReport);
/**
* taf(TAF)
* @param iRet
* @param status
* @param buffer
*/
void sendResponse(int iRet);
/**
* taf(TAF), swapbuffer , copy
* @param iRet
* @param status
* @param buffer
*/
void sendResponse(int iRet, tars::TarsOutputStream<tars::BufferWriterVector>& os);
/**
* taf(TAF), swapbuffer , copy
* @param iRet
* @param status
* @param buffer
*/
void sendResponse(int iRet, tup::UniAttribute<tars::BufferWriterVector, tars::BufferReader>& attr);
/**
* taf(TAF)
* @param iRet
* @param buff
*/
void sendResponse(int iRet, const vector<char> &buff);
/**
* (TAF)
* @param buff
* @param len
*/
void sendResponse(const char* buff, uint32_t len);
/**
* cookie
*/
void setCookie(const map<string, string> &cookie)
{
_cookie = cookie;
}
/**
* cookie
*/
map<string, string> & getCookie()
{
return _cookie;
}
protected:
friend class ServantHandle;
friend class Application;
/**
*
* @param data
*/
void initialize(const shared_ptr<TC_EpollServer::RecvContext> &data);
/**
*
* @param data
*/
void initializeClose(const shared_ptr<TC_EpollServer::RecvContext> &data);
/**
*
* @param sRecvBuffer
*/
void initialize(const vector<char> &sRecvBuffer);
/**
* TUP(TARS)
*/
void reportToStat(const string & sObj);
/**
*
* @param iRet
* @param response
* @param status
* @param sResultDesc
* @param push
*/
void sendResponse(int iRet, const vector<char> &buffer, const map<string, string>& status, const string& sResultDesc);
protected:
/**
*
*/
ServantHandle* _servantHandle;
/**
*
*/
shared_ptr<TC_EpollServer::RecvContext> _data;
/**
*
*/
RequestPacket _request;
/**
*
*/
bool _response;
/**
*
*/
int _ret;
/**
* stat
*/
bool _reportStat;
/**
*
*/
map<std::string, std::string> _responseContext;
/**
* cookie
*/
map<string, string> _cookie;
};
//////////////////////////////////////////////////////////////
}
#endif

View File

@ -1,893 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TARS_LOGGER_H__
#define __TARS_LOGGER_H__
#include "util/tc_logger.h"
#include "util/tc_file.h"
#include "util/tc_singleton.h"
#include "servant/Global.h"
#include "servant/LogF.h"
#include "servant/PropertyReport.h"
#define DYEING_DIR "tars_dyeing"
#define DYEING_FILE "dyeing"
namespace tars
{
/**
* LOG:
* 1 TLOGERROR(...),TLOGDEBUG(...)
* 2
* 3 DLOG, FDLOG
* 4 :DLOG("")->disableRemote();
* 5 :
* DLOG("abc3")->setFormat("%Y%m%d%H");
*
*/
/*****************************************************************************
(, tarslog):
1 WriteT:RemoteTimeWriteT
2 RemoteTimeWriteT,
3 :typedef TC_Logger<RemoteTimeWriteT, TC_RollByTime> RemoteTimeLogger;
4 线,
5 WriteT:TimeWriteT
6 TimeWriteTRemoteTimeLogger
7 TimeWriteT, , RemoteTimeLogger
8 RemoteTimeLoggerRemoteTimeWriteT,
9 线.
*****************************************************************************/
///////////////////////////////////////////////////////////////////////////////
class RollWriteT
{
public:
RollWriteT();
~RollWriteT();
void operator()(ostream &of, const deque<pair<size_t, string> > &ds);
void setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath,
int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string & sLogObj);
protected:
TC_RollLogger *_dyeingRollLogger;
static int _dyeingThread;
string _app;
string _server;
string _logPath;
int _maxSize;
int _maxNum;
/**
*
*/
LogPrx _logPrx;
};
/**
* ,
* , 使
* , cout
*/
class TarsRollLogger : public TC_Singleton<TarsRollLogger, CreateUsingNew, PhoneixLifetime>
{
public:
enum
{
NONE_LOG = 1, /**所有的log都不写*/
ERROR_LOG = 2, /**写错误log*/
WARN_LOG = 3, /**写错误,警告log*/
DEBUG_LOG = 4, /**写错误,警告,调试log*/
INFO_LOG = 5, /**写错误,警告,调试,Info log*/
TARS_LOG = 6 /**写错误,警告,调试,Info log*/
};
public:
typedef TC_Logger<RollWriteT, TC_RollBySize> RollLogger;
/**
*
* @param app,
* @param server,
* @param logpath,
* @param iMaxSize, ,
* @param iMaxNum,
*/
void setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize = 1024*1024*50, int iMaxNum = 10, const CommunicatorPtr &comm=NULL, const string &sLogObj="");
/**
*
*
* @param bSync
*/
void sync(bool bSync = true);
/**
*
*
* @return RollLogger
*/
RollLogger *logger() { return &_logger; }
/**
*
* @param bEnable
*/
void enableDyeing(bool bEnable, const string& sDyeingKey = "");
protected:
/**
*
*/
string _app;
/**
*
*/
string _server;
/**
*
*/
string _logpath;
/**
*
*/
RollLogger _logger;
/**
* 线
*/
TC_LoggerThreadGroup _local;
};
///////////////////////////////////////////////////////////////////////////////////////
//
/**
* 线
* 线
* ,
*/
class TarsLoggerThread : public TC_Singleton<TarsLoggerThread, CreateUsingNew, PhoneixLifetime>
{
public:
/**
*
*/
TarsLoggerThread();
/**
*
*/
~TarsLoggerThread();
/**
* 线
*/
TC_LoggerThreadGroup* local();
/**
* 线
*
* @return TC_LoggerThreadGroup*
*/
TC_LoggerThreadGroup* remote();
protected:
/**
* 线
*/
TC_LoggerThreadGroup _local;
/**
* 线
*/
TC_LoggerThreadGroup _remote;
};
///////////////////////////////////////////////////////////////////////////////////////
class TimeWriteT;
/**
* Log
*/
class RemoteTimeWriteT
{
public:
RemoteTimeWriteT();
~RemoteTimeWriteT();
/**
*
*/
void setTimeWriteT(TimeWriteT *pTimeWrite);
/**
*
* @param of
* @param buffer
*/
void operator()(ostream &of, const deque<pair<size_t, string> > &buffer);
protected:
/**
*
*/
void sync2remote(const vector<string> &buffer);
/**
*
*/
void sync2remoteDyeing(const vector<string> &buffer);
protected:
/**
*
*/
TimeWriteT *_timeWrite;
};
////////////////////////////////////////////////////////////////////////////
/**
* Logger
*/
class TimeWriteT
{
public:
typedef TC_Logger<RemoteTimeWriteT, TC_RollByTime> RemoteTimeLogger;
typedef TC_Logger<TC_DefaultWriteT, TC_RollByTime> DyeingTimeLogger;
/**
*
*/
TimeWriteT();
/**
*
*/
~TimeWriteT();
/**
*
* @param app,
* @param server,
* @param file,
* @param sFormat,
* @param setdivision,set
* @param sLogType,
*/
void setLogInfo(const LogPrx &logPrx, const string &sApp, const string &sServer, const string &sFile, const string &sLogpath, const string &sFormat, const string& setdivision = "", const string& sLogType = "", const PropertyReportPtr &reportSuccPtr = NULL, const PropertyReportPtr &reportFailPtr = NULL);
/**
*
* @param logPrx
*/
void setLogPrx(const LogPrx &logPrx);
/**
*
* @param bEnable
*/
void enableRemote(bool bEnable) { _remote = bEnable; }
/**
*
* @param bEnable
*/
void enableLocal(bool bEnable);
/**
*
* @param bEnable
*/
void enableDyeing (bool bEnable, const string& sDyeingKey = "");
/**
* @brief .log
* @param bEnable
*/
void enableSufix(bool bEnable=true){_hasSufix = bEnable;}
/**
* @brief
* @param bEnable
*/
void enablePrefix(bool bEnable=true){_hasAppNamePrefix = bEnable;}
/**
* @brief "_"
* @param str
*/
void setFileNameConcatStr(const string& str) {_concatStr = str;}
/**
* @brief "|"
* @param str
*/
void setSeparator(const string& str) {_separ = str;}
/**
* @brief [],
* @param bEnable
*/
void enableSqareWrapper(bool bEnable) {_hasSquareBracket = bEnable;}
/**
* ("%Y%m%d")
* @param sFormat
*/
void setFormat(const string &sFormat) { _format = sFormat;}
/**
*
* @param of
* @param buffer
*/
void operator()(ostream &of, const deque<pair<size_t, string> > &buffer);
protected:
/**
*
*/
friend class RemoteTimeWriteT;
/**
*
* @param buffer
*/
void writeError(const vector<string> &buffer);
/**
*
* @param buffer
*/
void writeError(const deque<pair<size_t, string> > &buffer);
/**
* logger
*/
void initError();
/**
*
*/
void initDyeingLog();
protected:
/**
*
*/
RemoteTimeLogger *_remoteTimeLogger;
/**
*
*/
bool _local;
/**
*
*/
bool _remote;
/**
*
*/
LogPrx _logPrx;
/**
* app
*/
string _app;
/**
*
*/
string _server;
/**
*
*/
string _file;
/**
*
*/
string _format;
/**
*
*/
string _filePath;
/**
*
*/
TC_DayLogger _logger;
/**
*
*/
TC_DefaultWriteT _wt;
/**
*
*/
static int _dyeing;
/**
*
*/
string _dyeingFilePath;
/**
*
*/
DyeingTimeLogger *_dyeingTimeLogger;
/**
* set
*/
string _setDivision;
/**
* .log
*/
bool _hasSufix;
/**
*
*/
bool _hasAppNamePrefix;
/**
* "_"
*/
string _concatStr;
/**
*
*/
string _separ;
/**
* []
*/
bool _hasSquareBracket;
/*
* ,TarsLogType.toString(),TarsLogType""
*/
string _logType;
/*
* logser
*/
PropertyReportPtr _reportSuccPtr;
/*
* logser
*/
PropertyReportPtr _reportFailPtr;
};
////////////////////////////////////////////////////////////////////////////
/**
* ,
*/
class TarsTimeLogger : public TC_HandleBase
, public TC_ThreadLock
, public TC_Singleton<TarsTimeLogger, CreateUsingNew, DefaultLifetime>
{
public:
//定义按时间滚动的日志
typedef TC_Logger<TimeWriteT, TC_RollByTime> TimeLogger;
/**
*
*/
TarsTimeLogger();
/**
*
*/
~TarsTimeLogger();
/**
*
* @param comm,
* @param obj,
* @param app,
* @param server,
* @param logpath,
*/
void setLogInfo(const CommunicatorPtr &comm, const string &obj, const string &sApp, const string &sServer, const string &sLogpath,const string& setdivision="", const bool &bLogStatReport=false);
/**
* ("%Y%m%d")
* , 线
* ,
* @param sFormat, ,
*/
void initFormat(const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
void initFormat(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
/**
* ("%Y%m%d")
* , 线
* ,
* @param sFormat, ,
* @param frequency //TC_logger.hTarsLogByDay,TarsLogByHour,TarsLogByMinute
*
* :
* initFormat<TarsLogByHour>("logfile",TarsLogByHour::FORMAT,2);
*/
template<class TarsLogType>
void initFormatWithType(const string &sFile, const string &sFormat,size_t frequency)
{
TarsLogTypePtr logTypePtr = new TarsLogType(sFormat,frequency);
initFormat(sFile,sFormat,logTypePtr);
}
template<class TarsLogType>
void initFormatWithType(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,size_t frequency)
{
TarsLogTypePtr logTypePtr = new TarsLogType(sFormat,frequency);
initFormat(sApp,sServer,sFile,sFormat,logTypePtr);
}
/**
*
* @param file
*/
TimeLogger *logger(const string &sFile = "");
/**
*
* @param app,
* @param server,
* @param file
*/
TimeLogger *logger(const string &sApp, const string &sServer,const string &sFile = "");
/**
* (, )
* @param bSync
*/
void sync(const string &sFile, bool bSync);
/**
*
* @param sFile, ,
* @param bEnable
*/
void enableRemote(const string &sFile, bool bEnable);
/**
*
* @param sApp,
* @param sServer,
* @param sFile, ,
* @param bEnable
*/
void enableRemoteEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable);
/**
*
* @param sFile,,
* @param bEnable
*/
void enableLocal(const string &sFile, bool bEnable);
/**
*
* @param sApp,
* @param sServer,
* @param sFile, ,
* @param bEnable
*/
void enableLocalEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable);
/**
* @brief .log,
* @param bEnable
*/
void enableSufix(bool bEnable=true){_hasSufix = bEnable;}
/**
* @brief ,
* @param bEnable
*/
void enablePrefix(bool bEnable=true){_hasAppNamePrefix = bEnable;}
/**
* @brief "_",
* @param str
*/
void setFileNameConcatStr(const string& str) {_concatStr = str;}
/**
* @brief "|",
* @param str
*/
void setSeparator(const string& str) {_separ = str;}
/**
* @brief [],,
* @param bEnable
*/
void enableSqareWrapper(bool bEnable) {_hasSquareBracket = bEnable;}
/**
* @brief
* @param bEnable
*/
void enableLocalLog(bool bEnable) {_local = bEnable;}
/**
* @brief ,
* @param bEnable
*/
void enableRemoteLog(bool bEnable) {_remote = bEnable;}
protected:
/**
*
* @param pTimeLogger
* @param sFile
* @param sFormat
* @param frequence, //,
*/
void initTimeLogger(TimeLogger *pTimeLogger, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
/**
*
* @param pTimeLogger
* @param sApp
* @param sServer
* @param sFile
* @param sFormat
* @param frequence, //,
*/
void initTimeLogger(TimeLogger *pTimeLogger,const string &sApp, const string &sServer, const string &sFile, const string &sFormat,const TarsLogTypePtr& logTypePtr=NULL);
protected:
/**
*
*/
CommunicatorPtr _comm;
/**
*
*/
LogPrx _logPrx;
/**
*
*/
string _app;
/**
*
*/
string _server;
/**
*
*/
string _logpath;
/**
*
*/
TimeLogger *_defaultLogger;
/**
*
*/
map<string, TimeLogger*> _loggers;
/**
* set
*/
string _setDivision;
/**
* .log
*/
bool _hasSufix;
/**
*
*/
bool _hasAppNamePrefix;
/**
* "_"
*/
string _concatStr;
/**
*
*/
string _separ;
/**
* []
*/
bool _hasSquareBracket;
/**
*
*/
bool _local;
/**
*
*/
bool _remote;
/*
* logser
*/
bool _logStatReport;
};
/**
*
*/
class TarsDyeingSwitch
{
public:
/**
*
*/
TarsDyeingSwitch()
:_needDyeing(false)
{
}
/**
*
*/
~TarsDyeingSwitch()
{
if(_needDyeing)
{
TarsRollLogger::getInstance()->enableDyeing(false);
ServantProxyThreadData * td = ServantProxyThreadData::getData();
assert(NULL != td);
if (td)
{
td->_dyeing = false;
td->_dyeingKey = "";
}
}
}
/**
* key
*
* @param key
* @return bool
*/
static bool getDyeingKey(string & sDyeingkey)
{
ServantProxyThreadData * td = ServantProxyThreadData::getData();
assert(NULL != td);
if (td && td->_dyeing == true)
{
sDyeingkey = td->_dyeingKey;
return true;
}
return false;
}
/**
*
*/
void enableDyeing(const string & sDyeingKey = "")
{
TarsRollLogger::getInstance()->enableDyeing(true);
ServantProxyThreadData * td = ServantProxyThreadData::getData();
assert(NULL != td);
if(td)
{
td->_dyeing = true;
td->_dyeingKey = sDyeingKey;
}
_needDyeing = true;
_dyeingKey = sDyeingKey;
}
protected:
bool _needDyeing;
string _dyeingKey;
};
/**
*
*/
#define LOG (TarsRollLogger::getInstance()->logger())
/**
* @brief
*
* @param level ,TarsRollLogger::INFO_LOG,TarsRollLogger::DEBUG_LOG,TarsRollLogger::WARN_LOG,TarsRollLogger::ERROR_LOG
* @msg ,<<, "Demo begin" << " testing !" <<endl;
*
* @:
* : cout << "I have " << vApple.size() << " apples!"<<endl;
* : LOGMSG(TarsRollLogger::INFO_LOG,"I have " << vApple.size() << " apples!"<<endl);
*/
#if TARGET_PLATFORM_WINDOWS
#define LOGMSG(level,...) do{ if(LOG->isNeedLog(level)) LOG->log(level)<<__VA_ARGS__;}while(0)
#else
#define LOGMSG(level,msg...) do{ if(LOG->isNeedLog(level)) LOG->log(level)<<msg;}while(0)
#endif
/**
* @brief
*
* @msg ,<<, "Demo begin" << " testing !" <<endl;
*
* @:
* : cout << "I have " << vApple.size() << " apples!"<<endl;
* : TLOGINFO("I have " << vApple.size() << " apples!"<<endl);
*/
#if TARGET_PLATFORM_WINDOWS
#define TLOGINFO(...) LOGMSG(TarsRollLogger::INFO_LOG,__VA_ARGS__)
#define TLOGDEBUG(...) LOGMSG(TarsRollLogger::DEBUG_LOG,__VA_ARGS__)
#define TLOGWARN(...) LOGMSG(TarsRollLogger::WARN_LOG,__VA_ARGS__)
#define TLOGERROR(...) LOGMSG(TarsRollLogger::ERROR_LOG,__VA_ARGS__)
#define TLOGTARS(...) LOGMSG(TarsRollLogger::TARS_LOG,__VA_ARGS__)
#else
#define TLOGINFO(msg...) LOGMSG(TarsRollLogger::INFO_LOG,msg)
#define TLOGDEBUG(msg...) LOGMSG(TarsRollLogger::DEBUG_LOG,msg)
#define TLOGWARN(msg...) LOGMSG(TarsRollLogger::WARN_LOG,msg)
#define TLOGERROR(msg...) LOGMSG(TarsRollLogger::ERROR_LOG,msg)
#define TLOGTARS(msg...) LOGMSG(TarsRollLogger::TARS_LOG,msg)
#endif
/**
*
*/
#define DLOG (TarsTimeLogger::getInstance()->logger()->any())
#define FDLOG(x) (TarsTimeLogger::getInstance()->logger(x)->any())
#define FFDLOG(x,y,z) (TarsTimeLogger::getInstance()->logger(x,y,z)->any())
/**
* 使使
*/
#define TENREMOTE_FDLOG(swith,sApp,sServer,sFile) (TarsTimeLogger::getInstance()->enableRemoteEx(sApp,sServer,sFile,swith))
#define TENLOCAL_FDLOG(swith,sApp,sServer,sFile) (TarsTimeLogger::getInstance()->enableLocalEx(sApp,sServer,sFile,swith))
/**
* 使
*/
#define TENREMOTE(swith) (TarsTimeLogger::getInstance()->enableRemoteLog(swith))
#define TENLOCAL(swith) (TarsTimeLogger::getInstance()->enableLocalLog(swith))
}
#endif

View File

@ -1,80 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TARS_NODEF_H__
#define __TARS_NODEF_H__
#include "servant/NodeF.h"
#include "servant/Global.h"
#include "util/tc_singleton.h"
namespace tars
{
/**
* node
* keepAlivenode
*/
class TarsNodeFHelper : public TC_Singleton<TarsNodeFHelper>,public TC_ThreadMutex
{
public:
/**
* node
* @param comm,
* @param obj,
* @param app
* @param server
*/
void setNodeInfo(const CommunicatorPtr &comm, const string &obj, const string &app, const string &server);
/**
* keepAlive
*/
void keepAlive(const string &adapter = "");
void keepActiving();
/**
* TARS
* @param version
*/
void reportVersion(const string &version);
protected:
/**
*
*/
CommunicatorPtr _comm;
/**
* Node
*/
ServerFPrx _nodePrx;
/**
*
*/
ServerInfo _si;
set<string> _adapterSet;
};
}
#endif

View File

@ -1,101 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TARS_NOTIFY_H_
#define __TARS_NOTIFY_H_
#include "servant/NotifyF.h"
#include "servant/Global.h"
#include "util/tc_singleton.h"
using namespace std;
namespace tars
{
/**
* Notify
* notify
*/
class TarsRemoteNotify : public TC_Singleton<TarsRemoteNotify>
{
public:
/**
*
* @param comm,
* @param obj,
* @param notifyPrx
* @param app
* @param serverName
*
* @return int
*/
int setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &nodeName, const string &sSetName="");
/**
* ,
* @param message
*/
void notify(NOTIFYLEVEL level, const string &sMesage);
/**
*
* @param sResult
* @param bSync
*/
void report(const string &sResult, bool bSync = false);
/**
* ,
* @param message
*/
void report(const string &sMesage, const string & app, const string &serverName, const string &sNodeName);
protected:
/**
*
*/
CommunicatorPtr _comm;
/**
*
*/
NotifyPrx _notifyPrx;
/**
*
*/
string _app;
/**
*
*/
string _serverName;
/*
*set
*/
string _setName;
/*
*
*/
string _nodeName;
};
}
#endif

View File

@ -183,8 +183,8 @@ public:
/*
*
*/
EndpointInfo& getEndpointInfo()
{
const EndpointInfo& getEndpointInfo() const
{
return _ep;
}

View File

@ -38,7 +38,7 @@ string CodeGenerator::generateTSServerAsync(const NamespacePtr &nPtr, const Inte
sParams += ": " + getTsType(vParamDecl[i]->getTypeIdPtr()->getTypePtr());
}
str << TAB << "protected static __" << oPtr->getId() << "_responser(this: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent, " << sParams << ") {" << endl;
str << TAB << "protected static __" << oPtr->getId() << "_responser(this: " << IDL_NAMESPACE_STR << "Rpc.Current, " << sParams << ") {" << endl;
INC_TAB;
@ -105,7 +105,7 @@ string CodeGenerator::generateTSServerDispatch(const NamespacePtr &nPtr, const I
ostringstream str;
vector<ParamDeclPtr> & vParamDecl = oPtr->getAllParamDeclPtr();
str << TAB << "protected __" << oPtr->getId() << "(current: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent";
str << TAB << "protected __" << oPtr->getId() << "(current: " << IDL_NAMESPACE_STR << "Rpc.Current";
if (vParamDecl.size() != 0) str << ", binBuffer: " << IDL_NAMESPACE_STR << "Stream.BinBuffer";
str << ") {" << endl;
@ -228,7 +228,7 @@ string CodeGenerator::generateTSServer(const InterfacePtr &pPtr, const Namespace
str << TAB << "initialize(): PromiseLike<any> | void {}" << endl << endl;
// generate the dispatch function
str << TAB << "onDispatch(current: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent, funcName: string, binBuffer: " << IDL_NAMESPACE_STR << "Stream.BinBuffer) { " << endl;
str << TAB << "onDispatch(current: " << IDL_NAMESPACE_STR << "Rpc.Current, funcName: string, binBuffer: " << IDL_NAMESPACE_STR << "Stream.BinBuffer) { " << endl;
INC_TAB;
str << TAB << "if (\"__\" + funcName in this) {" << endl;
INC_TAB;
@ -243,7 +243,7 @@ string CodeGenerator::generateTSServer(const InterfacePtr &pPtr, const Namespace
str << TAB << "}" << endl << endl;
// generate the ping function
str << TAB << "__" << TC_Common::lower(IDL_NAMESPACE_STR) << "_ping(current: " << IDL_NAMESPACE_STR << "Rpc.TarsCurrent) { " << endl;
str << TAB << "__" << TC_Common::lower(IDL_NAMESPACE_STR) << "_ping(current: " << IDL_NAMESPACE_STR << "Rpc.Current) { " << endl;
INC_TAB;
str << TAB << "const _ret = 0;" << endl;
str << TAB << "if (current.getRequestVersion() === " << PROTOCOL_SIMPLE << " || current.getRequestVersion() === " << PROTOCOL_COMPLEX << ") {" << endl;

View File

@ -513,7 +513,7 @@ int yy_flex_debug = 0;
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 1 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
/**
* Tencent is pleased to support the open source community by making Tars available.
*
@ -529,7 +529,7 @@ char *yytext;
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#line 20 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 20 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#include <map>
#include <string>
#include <sstream>
@ -742,7 +742,7 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#line 67 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 67 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 749 "tars.lex.cpp"
@ -840,12 +840,12 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 69 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 69 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{ BEGIN(INCL); }
YY_BREAK
case 2:
YY_RULE_SETUP
#line 71 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 71 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
if ( include_file_stack_ptr >= MAX_INCLUDE_DEPTH )
{
@ -878,7 +878,7 @@ YY_RULE_SETUP
YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(INCL):
#line 101 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 101 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
--include_file_stack_ptr;
if ( include_file_stack_ptr < 0 )
@ -897,14 +897,14 @@ case YY_STATE_EOF(INCL):
YY_BREAK
case 3:
YY_RULE_SETUP
#line 117 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 117 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
return TARS_SCOPE_DELIMITER;
}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 121 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 121 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
// C++ comment
bool e = false;
@ -925,7 +925,7 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
#line 139 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 139 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
// C comment
bool e = false;
@ -976,7 +976,7 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
#line 187 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 187 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
StringGrammarPtr ident = new StringGrammar;
ident->v = yytext;
@ -987,7 +987,7 @@ YY_RULE_SETUP
case 7:
/* rule 7 can match eol */
YY_RULE_SETUP
#line 194 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 194 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
StringGrammarPtr ident = new StringGrammar;
ident->v = yytext;
@ -1000,7 +1000,7 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
#line 204 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 204 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
StringGrammarPtr str = new StringGrammar;
bool e = false;
@ -1115,7 +1115,7 @@ YY_RULE_SETUP
YY_BREAK
case 9:
YY_RULE_SETUP
#line 316 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 316 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
errno = 0;
IntergerGrammarPtr ptr = new IntergerGrammar;
@ -1140,7 +1140,7 @@ YY_RULE_SETUP
YY_BREAK
case 10:
YY_RULE_SETUP
#line 338 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 338 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
errno = 0;
FloatGrammarPtr ptr = new FloatGrammar;
@ -1175,7 +1175,7 @@ YY_RULE_SETUP
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
#line 369 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 369 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
if(yytext[0] == '\n')
{
@ -1185,7 +1185,7 @@ YY_RULE_SETUP
YY_BREAK
case 12:
YY_RULE_SETUP
#line 376 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 376 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
{
if(yytext[0] < 32 || yytext[0] > 126)
{
@ -1204,7 +1204,7 @@ YY_RULE_SETUP
YY_BREAK
case 13:
YY_RULE_SETUP
#line 392 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 392 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
ECHO;
YY_BREAK
#line 1211 "tars.lex.cpp"
@ -2214,7 +2214,7 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 392 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 392 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@
#define __TC_AUTOPTR_H
#include "util/tc_ex.h"
// #include "util/tc_atomic.h"
#include "util/tc_platform.h"
#include <atomic>
#include <typeinfo>
@ -40,7 +40,7 @@ struct TC_AutoPtrNull_Exception : public TC_Exception
*
*
*/
class TC_HandleBase
class UTIL_DLL_API TC_HandleBase
{
public:

View File

@ -51,18 +51,18 @@ namespace tars
*/
/////////////////////////////////////////////////
/**
* @brief 使.
*
* :
*
* Trim,,
*
* ,,,,
*
* ,Ip,
*/
class TC_Common
/**
* @brief 使.
*
* :
*
* Trim,,
*
* ,,,,
*
* ,Ip,
*/
class UTIL_DLL_API TC_Common
{
public:

View File

@ -1170,6 +1170,12 @@ public:
*/
TC_NetWorkBuffer &getSendBuffer() { return _sendBuffer; }
/**
* buffer
* @return
*/
int sendBuffer();
friend class NetThread;
protected:
@ -1197,12 +1203,6 @@ public:
*/
int send(const shared_ptr<SendContext> &data);
/**
* buffer
* @return
*/
int sendBuffer();
/**
*
* @param fd

View File

@ -107,8 +107,7 @@ private:
//为了避免windows平台GetLastError()获取不对的问题, 因为抛异常, throw TC_Exception("xxxx", TC_Exception::getSystemCode())时
//回调用系统函数分配内存, 导致错误码被改写, 因此专门定义宏来抛出异常
//先获取到错误码, 再throw
#define TARS_THROW_EXCEPTION(EX_CLASS, buffer) throw EX_CLASS(buffer)
#define TARS_THROW_EXCEPTION_SYSCODE(EX_CLASS, buffer) \
#define THROW_EXCEPTION_SYSCODE(EX_CLASS, buffer) \
{ \
int ret = TC_Exception::getSystemCode(); \
throw EX_CLASS(buffer, ret); \

View File

@ -343,6 +343,9 @@ protected:
class TC_Http
{
public:
static unordered_map<string, int> HEADER;
static unordered_map<int, string> HEADER_REVERSE;
/**
* @brief
*/
@ -562,10 +565,25 @@ public:
string getHeader(const string& sHeader) const;
/**
* @brief httpmap.
*
* @return http_header_type&
* header
* @param sHeader
* @return
*/
bool hasHeader(const char *sHeader) const;
/**
* @brief
* @param sHeader
* @param value
* @return
*/
bool checkHeader(const char *sHeader, const char *value) const;
/**
* @brief httpmap.
*
* @return http_header_type&
*/
const http_header_type& getHeaders() const{return _headers;}
/**
@ -579,82 +597,89 @@ public:
*/
void reset();
// /**
// * @brief 读取一行.
// *
// * @param ppChar 读取位置指针
// * @return string 读取的内容
// */
// static string getLine(const char** ppChar);
/**
* @brief .
*
* @param ppChar
* @param iBufLen
* @return string
*/
// static string getLine(const char** ppChar, int iBufLen);
/**
* @brief ().
* @brief (), sHttpHeader
*
* @return string
*/
string genHeader() const;
void genHeader(string &sHttpHeader) const;
/**
* @brief httpchunk.
*
* @return booltruefalse
* @brief ()
* @return
*/
string genHeader() const;
/**
* @brief httpchunk.
*
* @return booltruefalse
*/
bool isChunked() const { return _bIsChunked; }
/**
* @brief head,
* map
* @param szBuffer
* @param szBuffer
* @return const char*,
*/
// static const char* parseHeader(const char* szBuffer, http_header_type &sHeader);
//
// template<typename ForwardIterator1, typename ForwardIterator2>
// static void parseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt, http_header_type &sHeader)
// {
// sHeader.clear();
//
// string sep = "\r\n";
// string colon = ":";
//
// bool first = true;
// auto lineStartIt= beginIt;
//
// while (true)
// {
// auto it = std::search(lineStartIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
// if(it == headerIt)
// {
// break;
// }
//
// //first line ignore
// if(!first)
// {
// auto itF = std::search(lineStartIt, it, colon.c_str(), colon.c_str() + colon.size());
// if (itF != it)
// {
// string name;
// name.resize(itF - lineStartIt);
// std::copy(lineStartIt, itF, name.begin());
//
// string value;
// value.resize(it - (itF + 1));
// std::copy(itF + 1, it, value.begin());
//
// sHeader.insert(multimap<string, string>::value_type(TC_Common::trim(name, " "),
// TC_Common::trim(value, " ")));
//
// }
// }
// else
// {
// first = false;
// }
//
// lineStartIt = it + sep.size();
// }
// }
/**
* , copy,
* @param beginIt
* @param headerIt
* @param sHeader
*/
static size_t parseHeaderString(const char *beginIt, const char *headerIt, http_header_type &sHeader);
template<typename ForwardIterator1, typename ForwardIterator2>
static void parseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt, http_header_type &sHeader)
{
sHeader.clear();
string sep = "\r\n";
string colon = ":";
bool first = true;
auto lineStartIt= beginIt;
while (true)
{
auto it = std::search(lineStartIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
if(it == headerIt)
{
break;
}
if(!first)
{
auto itF = std::search(lineStartIt, it, colon.c_str(), colon.c_str() + colon.size());
if (itF != it)
{
string name;
name.resize(itF - lineStartIt);
std::copy(lineStartIt, itF, name.begin());
string value;
value.resize(it - (itF + 1));
std::copy(itF + 1, it, value.begin());
sHeader.insert(multimap<string, string>::value_type(TC_Common::trim(name, " "),
TC_Common::trim(value, " ")));
}
}
else
{
first = false;
}
lineStartIt = it + sep.size();
}
}
protected:
/**
@ -667,6 +692,11 @@ protected:
*/
size_t _headLength;
/**
*
*/
string _version;
/**
* http
*/
@ -989,45 +1019,67 @@ public:
/**
* @brief .
*
*
* @param szBuffer
* @return
*/
// void parseResponseHeader(const char* szBuffer, const char* header);
// /**
// *
// * @param szBuffer
// */
// template<typename ForwardIterator1, typename ForwardIterator2>
// void parseResponseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt)
// {
// string line = "\r\n";
//
// auto it = std::search(beginIt, headerIt, line.c_str(), line.c_str() + line.size());
//
// assert(it != headerIt);
//
// string sep = " ";
//
// auto f1 = std::search(beginIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
// if(f1 == headerIt)
// {
// throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse version format error : " + string(beginIt, it));
// }
//
// auto f2 = std::search(f1 + 1, headerIt, sep.c_str(), sep.c_str() + sep.size());
// if(f1 == headerIt)
// {
// throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse status format error : " + string(beginIt, it));
// }
//
// _headerLine = string(beginIt, it);
//
// if(TC_Port::strncasecmp(_headerLine.c_str(), "HTTP/", 5) != 0)
// {
// throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response version is not start with 'HTTP/' : " + _headerLine);
// }
//
// _version = string(beginIt, f1);
//
// _status = TC_Common::strto<int>(string(f1 + 1, f2));
//
// _about = TC_Common::trim(string(f2 + 1, it));
//
// parseHeader(beginIt, headerIt, _headers);
// }
size_t parseResponseHeaderString(const char *beginIt, const char *headerIt);
template<typename ForwardIterator1, typename ForwardIterator2>
void parseResponseHeader(const ForwardIterator1 &beginIt, const ForwardIterator2 &headerIt)
{
string line = "\r\n";
auto it = std::search(beginIt, headerIt, line.c_str(), line.c_str() + line.size());
assert(it != headerIt);
string sep = " ";
auto f1 = std::search(beginIt, headerIt, sep.c_str(), sep.c_str() + sep.size());
if(f1 == headerIt)
{
throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse version format error : " + string(beginIt, it));
}
auto f2 = std::search(f1 + 1, headerIt, sep.c_str(), sep.c_str() + sep.size());
if(f1 == headerIt)
{
throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response parse status format error : " + string(beginIt, it));
}
_headerLine = string(beginIt, it);
if(TC_Port::strncasecmp(_headerLine.c_str(), "HTTP/", 5) != 0)
{
throw TC_HttpResponse_Exception("[TC_HttpResponse_Exception::parseResponeHeader] http response version is not start with 'HTTP/' : " + _headerLine);
}
_version = string(beginIt, f1);
_status = TC_Common::strto<int>(string(f1 + 1, f2));
_about = TC_Common::trim(string(f2 + 1, it));
parseHeader(beginIt, headerIt, _headers);
}
protected:
/**
* ,
*
* @param sBuffer
*/
void addContent(const string &sBuffer);
/**
*
* @param buffer
* @param length
*/
void addContent(const char *buffer, size_t length);
protected:
@ -1042,11 +1094,6 @@ protected:
*/
string _about;
/**
*
*/
string _version;
/**
*
*/
@ -1089,11 +1136,12 @@ public:
REQUEST_PUT,
REQUEST_DELETE,
REQUEST_PATCH,
REQUEST_PRI,
};
/**
* @brief http.
*
*
* @param sBuffer http
* @throws TC_HttpRequest_Exception, http,
* @return true: , false:
@ -1142,7 +1190,16 @@ public:
*/
bool decode(const string &sBuffer);
/**
/**
* @brief http, HTTP.
*
* @param sBuffer http
* @return sBufferhttp
* @throw TC_HttpRequest_Exception
*/
bool decode(const vector<char> &sBuffer);
/**
* @brief http,
* HTTP(vector<char>).
*
@ -1276,6 +1333,12 @@ public:
*/
void setRequestType(int requestType) { _requestType = requestType ; }
/**
* get method
* @return
*/
const string &getMethod() const;
/**
* set method
* @param
@ -1335,10 +1398,9 @@ public:
* @return deletetruefalse
*/
bool isDELETE() const { return _requestType == REQUEST_DELETE; }
/**
* @brief URL.
*
*
* @return const TC_URL&
*/
const TC_URL &getURL() const { return _httpURL; }
@ -1379,13 +1441,13 @@ public:
*/
void parseRequestHeader(const char* szBuffer, const char *header);
/**
* @brief .
*
* @param iRequestType
* @return
*/
string requestType2str(int iRequestType) const;
// /**
// * @brief 请求类型到字符串.
// *
// * @param iRequestType 请求
// * @return 解析后的字符串
// */
// const char *requestType2str(int iRequestType) const;
protected:
@ -1396,7 +1458,7 @@ protected:
* @param iRequestType
* @return void
*/
void encode(int iRequestType, ostream &os);
// void encode(int iRequestType, ostream &os);
/**
* @brief URL

View File

@ -198,11 +198,12 @@ public:
* @param buff
* @return
*/
int submit(const string &method, const string &path, const map<string, string> &header, const vector<char> &buff);
// int submit(const string &method, const string &path, const map<string, string> &header, const vector<char> &buff);
int submit(const TC_HttpRequest &request);
/**
* @brief response
*/
/**
* @brief response
*/
std::unordered_map<int, shared_ptr<TC_HttpResponse>> &responses() { return _responses; }
/**

View File

@ -134,7 +134,8 @@ namespace tars
/**
* @brief
*/
class TC_LoggerRoll : public TC_HandleBase
class UTIL_DLL_API TC_LoggerRoll : public TC_HandleBase
{
public:
/**
@ -1231,7 +1232,7 @@ namespace tars
//抛异常前继续进入_t 以便打远程日志
_t(_of, buffer);
TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
// throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
}
}
@ -1281,7 +1282,7 @@ namespace tars
_of.open(sLogFileName.c_str(), ios::app);
if (!_of)
{
TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
// throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
}
}
@ -1329,16 +1330,16 @@ namespace tars
/**
* @brief
*/
class TarsLogType : public TC_HandleBase
class LogType : public TC_HandleBase
{
public:
TarsLogType() : _next_time_t(0), _format("%Y%m%d"), _frequency(1), _des("day")
LogType() : _next_time_t(0), _format("%Y%m%d"), _frequency(1), _des("day")
{
_next_time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
_next_cut_time = TC_Common::tm2str(_next_time_t, "%Y%m%d");
}
virtual ~TarsLogType() {}
virtual ~LogType() {}
//频率值
virtual size_t frequence() = 0;
@ -1391,15 +1392,15 @@ namespace tars
size_t _frequency;
string _des;
};
typedef TC_AutoPtr<TarsLogType> TarsLogTypePtr;
typedef TC_AutoPtr<LogType> LogTypePtr;
class TarsLogByDay : public TarsLogType
class LogByDay : public LogType
{
public:
static const string FORMAT;
public:
explicit TarsLogByDay(const string &format = "%Y%m%d", size_t frequency = 1)
explicit LogByDay(const string &format = "%Y%m%d", size_t frequency = 1)
{
init(format, frequency);
_des = TC_Common::tostr(_frequency) + "day";
@ -1411,13 +1412,13 @@ namespace tars
}
};
class TarsLogByHour : public TarsLogType
class LogByHour : public LogType
{
public:
static const string FORMAT;
public:
explicit TarsLogByHour(const string &format = "%Y%m%d%H", size_t frequency = 1)
explicit LogByHour(const string &format = "%Y%m%d%H", size_t frequency = 1)
{
init(format, frequency);
_des = TC_Common::tostr(_frequency) + "hour";
@ -1430,13 +1431,13 @@ namespace tars
}
};
class TarsLogByMinute : public TarsLogType
class LogByMinute : public LogType
{
public:
static const string FORMAT;
public:
explicit TarsLogByMinute(const string &format = "%Y%m%d%H%M", size_t frequency = 1)
explicit LogByMinute(const string &format = "%Y%m%d%H%M", size_t frequency = 1)
{
init(format, frequency);
_des = TC_Common::tostr(_frequency) + "minute";
@ -1470,10 +1471,10 @@ namespace tars
* @param format
* @param bHasSufix,".log"
* @param sConcatstr,,app_log/test_20121210.log
* @param logTypePtr,TarsLogType
* @param logTypePtr,LogType
* @param bIsRemote,
*/
void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const TarsLogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const LogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
{
this->_roll->init(path, format, bHasSufix, sConcatstr, logTypePtr, bIsRemote);
}
@ -1539,7 +1540,7 @@ namespace tars
* @param bIsRemote
*/
void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const TarsLogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
void init(const string &path, const string &format = "%Y%m%d", bool bHasSufix = true, const string &sConcatstr = "_", const LogTypePtr &logTypePtr = NULL, bool bIsRemote = false)
{
std::lock_guard<std::mutex> lock(*this);
@ -1692,7 +1693,7 @@ namespace tars
{
//抛异常前继续进入_t 以便打远程日志
_t(_of, buffer);
TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollByTime::roll]:fopen fail: " + sLogFileName);
THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollByTime::roll]:fopen fail: " + sLogFileName);
// throw TC_Logger_Exception("[TC_RollByTime::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
}
}
@ -1744,7 +1745,7 @@ namespace tars
* //
*/
TarsLogTypePtr _logTypePtr;
LogTypePtr _logTypePtr;
/**
*
*/

View File

@ -368,11 +368,17 @@ public:
}
}
/**
* connection, ,
* @param buff
*/
void* getConnection() { return _connection; }
/**
* connection, ,
* @param buff
*/
void* getConnection() { return _connection; }
/**
* connection, ,
* @param buff
*/
void setConnection(void *connection) { _connection = connection; }
/**
* ,

View File

@ -77,7 +77,7 @@ public:
* @param verifyClient
* @return
*/
static shared_ptr<CTX> newCtx(const std::string& cafile, const std::string& certfile, const std::string& keyfile, bool verifyClient);
static shared_ptr<CTX> newCtx(const std::string& cafile, const std::string& certfile, const std::string& keyfile, bool verifyClient, const string &ciphers);
/**
* new ssl

View File

@ -43,4 +43,43 @@
#include <unistd.h>
#endif
//UTIL 动态库编译的导入和导出
#if TARGET_PLATFORM_WINDOWS
#ifdef UTIL_DLL_EXPORT
#define UTIL_DLL_API __declspec(dllexport)
#else
#ifdef UTIL_USE_DLL
#define UTIL_DLL_API __declspec(dllimport)
#else
#define UTIL_DLL_API
#endif
#endif
#else
#define UTIL_DLL_API
#endif
//servant 动态库编译的导入和导出
#if TARGET_PLATFORM_WINDOWS
#ifdef SVT_DLL_EXPORT
#define SVT_DLL_API __declspec(dllexport)
#else
#ifdef SVT_USE_DLL
#define SVT_DLL_API __declspec(dllimport)
#else
#define SVT_DLL_API
#endif
#endif
#else
#define SVT_DLL_API
#endif
#endif

View File

@ -163,9 +163,35 @@ public:
}
};
template<typename T>
class CreateRealStatic
{
public:
/**
* @brief .
*
* @return T*
*/
static T* create()
{
static T t;
return &t;
}
/**
* @brief .
*
* @param t
*/
static void destroy(T *t)
{
}
};
////////////////////////////////////////////////////////////////
/**
* @brief LifetimePolicy:
* 退
*/
template<typename T>
class DefaultLifetime
@ -182,6 +208,12 @@ public:
}
};
/**
* @brief,
* (log,)
*
* @author jarod (7/29/2015)
*/
template<typename T>
class PhoneixLifetime
{
@ -202,10 +234,15 @@ private:
template <class T>
bool PhoneixLifetime<T>::_bDestroyedOnce = false;
template <typename T>
struct NoDestroyLifetime
{
static void scheduleDestruction(T*, void (*)())
/**
* @brief
*
* @author jarod (7/29/2015)
*/
template <typename T>
struct NoDestroyLifetime
{
static void scheduleDestruction(T*, void (*)())
{
}
@ -237,56 +274,54 @@ public:
*/
static T *getInstance()
{
//加锁, 双check机制, 保证正确和效率
if(!_pInstance)
{
TC_ThreadLock::Lock lock(_tl);
if(!_pInstance)
{
if(_destroyed)
static std::mutex __mutex_singleton;
auto sin= __pInstance.load();
if ( !sin ){
std::lock_guard<std::mutex> myLock(__mutex_singleton);
sin= __pInstance.load();
if( !sin ){
if(__destroyed)
{
LifetimePolicy<T>::deadReference();
_destroyed = false;
__destroyed = false;
}
_pInstance = CreatePolicy<T>::create();
LifetimePolicy<T>::scheduleDestruction((T*)_pInstance, &destroySingleton);
sin = CreatePolicy<T>::create();
__pInstance.store(sin);
LifetimePolicy<T>::scheduleDestruction(__pInstance, &destroySingleton);
}
}
return (T*)_pInstance;
}
protected:
return sin;
}
virtual ~TC_Singleton(){};
protected:
static void destroySingleton()
{
assert(!_destroyed);
CreatePolicy<T>::destroy((T*)_pInstance);
_pInstance = NULL;
_destroyed = true;
assert(!__destroyed);
CreatePolicy<T>::destroy((T*)__pInstance);
__pInstance = NULL;
__destroyed = true;
}
protected:
static TC_ThreadLock _tl;
static volatile T* _pInstance;
static bool _destroyed;
static atomic<T*> __pInstance;
static bool __destroyed;
protected:
TC_Singleton(){}
virtual ~TC_Singleton(){};
TC_Singleton (const TC_Singleton &);
TC_Singleton &operator=(const TC_Singleton &);
TC_Singleton() = default;
TC_Singleton (const TC_Singleton &) = default;
TC_Singleton &operator=(const TC_Singleton &) = default;
};
template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy>
TC_ThreadLock TC_Singleton<T, CreatePolicy, LifetimePolicy>::_tl;
template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy>
bool TC_Singleton<T, CreatePolicy, LifetimePolicy>::_destroyed = false;
template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy>
volatile T* TC_Singleton<T, CreatePolicy, LifetimePolicy>::_pInstance = NULL;
template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy>
bool TC_Singleton<T, CreatePolicy, LifetimePolicy>::__destroyed = false;
template <class T, template<class> class CreatePolicy, template<class> class LifetimePolicy>
atomic<T*> TC_Singleton<T, CreatePolicy, LifetimePolicy>::__pInstance = {nullptr};
}
#endif

View File

@ -2,6 +2,7 @@
#ifndef __TC_SPIN_LOCK_H
#define __TC_SPIN_LOCK_H
#include "util/tc_platform.h"
#include <atomic>
#include <memory>
@ -15,7 +16,7 @@ namespace tars
* wait, , , 线
* trylock
*/
class TC_SpinLock
class UTIL_DLL_API TC_SpinLock
{
public:

View File

@ -18,6 +18,7 @@
#define __TC_THREAD_MUTEX_H
#include "util/tc_lock.h"
#include "util/tc_platform.h"
#include <mutex>
#include <atomic>
@ -41,7 +42,7 @@ class TC_ThreadCond;
*
* 使TC_Monitor使TC_ThreadLock;
*/
class TC_ThreadMutex
class UTIL_DLL_API TC_ThreadMutex
{
public:
@ -68,8 +69,8 @@ public:
protected:
// noncopyable
TC_ThreadMutex(const TC_ThreadMutex&);
void operator=(const TC_ThreadMutex&);
TC_ThreadMutex(const TC_ThreadMutex&) = delete;
void operator=(const TC_ThreadMutex&) = delete;
friend class TC_ThreadCond;
@ -82,7 +83,7 @@ protected:
*
* 线
**/
class TC_ThreadRecMutex
class UTIL_DLL_API TC_ThreadRecMutex
{
public:

View File

@ -20,6 +20,7 @@
#include <mutex>
#include <condition_variable>
#include "util/tc_lock.h"
#include "util/tc_platform.h"
#include <functional>
using namespace std;
@ -36,7 +37,7 @@ namespace tars
/////////////////////////////////////////////////
class TC_ThreadRWLocker
class UTIL_DLL_API TC_ThreadRWLocker
{
protected:

Some files were not shown because too many files have changed in this diff Show More