mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2024-12-22 22:16:38 +08:00
add files
This commit is contained in:
parent
6d5f517be7
commit
750ee9e6fd
437
servant/libservant/Current.cpp
Normal file
437
servant/libservant/Current.cpp
Normal file
@ -0,0 +1,437 @@
|
||||
/**
|
||||
* 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/Current.h"
|
||||
#include "servant/ServantHandle.h"
|
||||
#include "servant/BaseF.h"
|
||||
#include "servant/Application.h"
|
||||
#include "tup/tup.h"
|
||||
#include <cerrno>
|
||||
|
||||
namespace tars
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////
|
||||
Current::Current(ServantHandle *pServantHandle)
|
||||
: _servantHandle(pServantHandle)
|
||||
// , _bindAdapter(NULL)
|
||||
// , _uid(0)
|
||||
// , _ip("NULL")
|
||||
// , _port(0)
|
||||
// , _fd(-1)
|
||||
, _response(true)
|
||||
// , _begintime(0)
|
||||
, _ret(0)
|
||||
, _reportStat(true)
|
||||
// , _closeType(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Current::~Current()
|
||||
{
|
||||
//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 &Current::getHostName() const
|
||||
{
|
||||
auto it = _request.context.find("node_name");
|
||||
if(it != _request.context.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return _data->ip();
|
||||
|
||||
}
|
||||
|
||||
const string &Current::getIp() const
|
||||
{
|
||||
return _data->ip();
|
||||
}
|
||||
|
||||
int Current::getPort() const
|
||||
{
|
||||
return _data->port();
|
||||
// return _port;
|
||||
}
|
||||
|
||||
uint32_t Current::getUId() const
|
||||
{
|
||||
return _data->uid();
|
||||
// return _uid;
|
||||
}
|
||||
|
||||
string Current::getServantName() const
|
||||
{
|
||||
return _request.sServantName;
|
||||
}
|
||||
|
||||
short Current::getRequestVersion() const
|
||||
{
|
||||
return _request.iVersion;
|
||||
}
|
||||
|
||||
map<string, string>& Current::getContext()
|
||||
{
|
||||
return _request.context;
|
||||
}
|
||||
|
||||
const map<string, string>& Current::getRequestStatus() const
|
||||
{
|
||||
return _request.status;
|
||||
}
|
||||
|
||||
string Current::getFuncName() const
|
||||
{
|
||||
return _request.sFuncName;
|
||||
}
|
||||
|
||||
uint32_t Current::getRequestId() const
|
||||
{
|
||||
return _request.iRequestId;
|
||||
}
|
||||
|
||||
char Current::getPacketType() const
|
||||
{
|
||||
return _request.cPacketType;
|
||||
}
|
||||
|
||||
tars::Int32 Current::getMessageType() const
|
||||
{
|
||||
return _request.iMessageType;
|
||||
}
|
||||
|
||||
struct timeval Current::getRecvTime() const
|
||||
{
|
||||
timeval tm;
|
||||
tm.tv_sec = _data->recvTimeStamp()/1000;
|
||||
tm.tv_usec = (_data->recvTimeStamp()%1000)*1000;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
||||
void Current::setReportStat(bool bReport)
|
||||
{
|
||||
_reportStat = bReport;
|
||||
}
|
||||
|
||||
const vector<char>& Current::getRequestBuffer() const
|
||||
{
|
||||
if (_data->adapter()->isTarsProtocol())
|
||||
{
|
||||
return _request.sBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _data->buffer();
|
||||
}
|
||||
|
||||
// return _request.sBuffer;
|
||||
}
|
||||
|
||||
bool Current::isResponse() const
|
||||
{
|
||||
return _response;
|
||||
}
|
||||
|
||||
void Current::setCloseType(int type)
|
||||
{
|
||||
_data->setCloseType(type);
|
||||
}
|
||||
|
||||
int Current::getCloseType() const
|
||||
{
|
||||
return _data->closeType();
|
||||
}
|
||||
|
||||
void Current::initialize(const shared_ptr<TC_EpollServer::RecvContext> &data)
|
||||
// void Current::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 Current::initializeClose(const shared_ptr<TC_EpollServer::RecvContext> &data)
|
||||
{
|
||||
_data = data;
|
||||
|
||||
_request.sServantName = ServantHelperManager::getInstance()->getAdapterServant(_data->adapter()->getName());
|
||||
|
||||
}
|
||||
|
||||
void Current::initialize(const vector<char>& sRecvBuffer)
|
||||
{
|
||||
TarsInputStream<BufferReader> is;
|
||||
|
||||
is.setBuffer(sRecvBuffer.data(), sRecvBuffer.size());
|
||||
|
||||
_request.readFrom(is);
|
||||
}
|
||||
|
||||
// void Current::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 Current::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 Current::initialize(const string &sRecvBuffer)
|
||||
// {
|
||||
// TarsInputStream<BufferReader> is;
|
||||
|
||||
// is.setBuffer(sRecvBuffer.c_str(), sRecvBuffer.length());
|
||||
|
||||
// _request.readFrom(is);
|
||||
// }
|
||||
|
||||
void Current::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 Current::sendResponse(int iRet, const vector<char> &buff)
|
||||
{
|
||||
//单向调用不需要返回
|
||||
if (_request.cPacketType == TARSONEWAY)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ResponsePacket response;
|
||||
// response.sBuffer = buff;
|
||||
sendResponse(iRet, buff, TARS_STATUS(), "");
|
||||
}
|
||||
|
||||
void Current::sendResponse(int iRet)
|
||||
{
|
||||
// ResponsePacket response;
|
||||
sendResponse(iRet, vector<char>(), TARS_STATUS(), "");
|
||||
}
|
||||
|
||||
void Current::sendResponse(int iRet, tars::TarsOutputStream<tars::BufferWriterVector>& os)
|
||||
{
|
||||
// ResponsePacket response;
|
||||
// os.swap(response.sBuffer);
|
||||
sendResponse(iRet, os.getByteBuffer(), TARS_STATUS(), "");
|
||||
}
|
||||
|
||||
void Current::sendResponse(int iRet, tup::UniAttribute<tars::BufferWriterVector, tars::BufferReader>& attr)
|
||||
{
|
||||
ResponsePacket response;
|
||||
attr.encode(response.sBuffer);
|
||||
sendResponse(iRet, response.sBuffer, TARS_STATUS(), "");
|
||||
}
|
||||
|
||||
void Current::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]Current::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]Current::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 Current::close()
|
||||
{
|
||||
if (_servantHandle)
|
||||
{
|
||||
_servantHandle->close(_data);
|
||||
}
|
||||
}
|
||||
|
||||
ServantHandle* Current::getServantHandle()
|
||||
{
|
||||
return _servantHandle;
|
||||
}
|
||||
|
||||
TC_EpollServer::BindAdapter* Current::getBindAdapter()
|
||||
{
|
||||
return _data->adapter().get();
|
||||
}
|
||||
|
||||
void Current::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);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
}
|
116
servant/libservant/KeepAliveNodeF.cpp
Executable file
116
servant/libservant/KeepAliveNodeF.cpp
Executable file
@ -0,0 +1,116 @@
|
||||
/**
|
||||
* 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/KeepAliveNodeF.h"
|
||||
#include "servant/RemoteLogger.h"
|
||||
#include "servant/Communicator.h"
|
||||
|
||||
namespace tars
|
||||
{
|
||||
|
||||
void KeepAliveNodeFHelper::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 KeepAliveNodeFHelper::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("KeepAliveNodeFHelper::keepAlive error:" << ex.what() << endl);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
TLOGERROR("KeepAliveNodeFHelper::keepAlive unknown error" << endl);
|
||||
}
|
||||
}
|
||||
|
||||
void KeepAliveNodeFHelper::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 KeepAliveNodeFHelper::reportVersion(const string &version)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_nodePrx)
|
||||
{
|
||||
_nodePrx->async_reportVersion(NULL, _si.application, _si.serverName, version);
|
||||
}
|
||||
}
|
||||
catch(exception &ex)
|
||||
{
|
||||
TLOGERROR("KeepAliveNodeFHelper::reportVersion error:" << ex.what() << endl);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
TLOGERROR("KeepAliveNodeFHelper::reportVersion unknown error" << endl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
213
servant/libservant/RemoteConfig.cpp
Executable file
213
servant/libservant/RemoteConfig.cpp
Executable file
@ -0,0 +1,213 @@
|
||||
/**
|
||||
* 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/RemoteConfig.h"
|
||||
#include "util/tc_file.h"
|
||||
#include "servant/Communicator.h"
|
||||
#include "servant/RemoteNotify.h"
|
||||
#include "servant/Application.h"
|
||||
#include <fstream>
|
||||
|
||||
namespace tars
|
||||
{
|
||||
|
||||
int RemoteConfig::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 RemoteConfig::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 RemoteConfig::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." ;
|
||||
RemoteNotify::getInstance()->report(result);
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
out.close();
|
||||
return newFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
string RemoteConfig::index2file(const string & sFullFileName, int index)
|
||||
{
|
||||
return sFullFileName + "." + TC_Common::tostr(index) + ".bak";
|
||||
}
|
||||
|
||||
void RemoteConfig::localRename(const string& oldFile, const string& newFile)
|
||||
{
|
||||
#if TARGET_PLATFORM_WINDOWS
|
||||
//by goodenpei,windows下面先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 RemoteConfig::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.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
723
servant/libservant/RemoteLogger.cpp
Normal file
723
servant/libservant/RemoteLogger.cpp
Normal file
@ -0,0 +1,723 @@
|
||||
/**
|
||||
* 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/RemoteLogger.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 LocalRollLogger::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 LocalRollLogger::sync(bool bSync)
|
||||
{
|
||||
if(bSync)
|
||||
{
|
||||
_logger.unSetupThread();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.setupThread(&_local);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalRollLogger::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);
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RemoteTimeLogger::RemoteTimeLogger() : _defaultLogger(NULL),_hasSufix(true),_hasAppNamePrefix(true),_concatStr("_"),_separ("|"),_hasSquareBracket(false),_local(true),_remote(true)
|
||||
{
|
||||
}
|
||||
|
||||
RemoteTimeLogger::~RemoteTimeLogger()
|
||||
{
|
||||
if(_defaultLogger != NULL)
|
||||
{
|
||||
delete _defaultLogger;
|
||||
}
|
||||
|
||||
map<string, TimeLogger*>::iterator it = _loggers.begin();
|
||||
while(it != _loggers.end())
|
||||
{
|
||||
delete it->second;
|
||||
++it;
|
||||
}
|
||||
_loggers.clear();
|
||||
}
|
||||
|
||||
void RemoteTimeLogger::initTimeLogger(TimeLogger *pTimeLogger, const string &sFile, const string &sFormat,const LogTypePtr& 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 RemoteTimeLogger::initTimeLogger(TimeLogger *pTimeLogger,const string &sApp, const string &sServer, const string &sFile, const string &sFormat,const LogTypePtr& 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 RemoteTimeLogger::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 RemoteTimeLogger::initFormat(const string &sFile, const string &sFormat,const LogTypePtr& 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 RemoteTimeLogger::initFormat(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,const LogTypePtr& 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);
|
||||
}
|
||||
|
||||
RemoteTimeLogger::TimeLogger* RemoteTimeLogger::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;
|
||||
}
|
||||
|
||||
RemoteTimeLogger::TimeLogger* RemoteTimeLogger::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 RemoteTimeLogger::sync(const string &sFile, bool bSync)
|
||||
{
|
||||
if(bSync)
|
||||
{
|
||||
logger(sFile)->unSetupThread();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger(sFile)->setupThread(TarsLoggerThread::getInstance()->local());
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteTimeLogger::enableRemote(const string &sFile, bool bEnable)
|
||||
{
|
||||
logger(sFile)->getWriteT().enableRemote(bEnable);
|
||||
}
|
||||
|
||||
void RemoteTimeLogger::enableRemoteEx(const string &sApp, const string &sServer,const string &sFile, bool bEnable)
|
||||
{
|
||||
logger(sApp,sServer,sFile)->getWriteT().enableRemote(bEnable);
|
||||
}
|
||||
void RemoteTimeLogger::enableLocal(const string &sFile, bool bEnable)
|
||||
{
|
||||
logger(sFile)->getWriteT().enableLocal(bEnable);
|
||||
logger(sFile)->setRemote(!bEnable);
|
||||
}
|
||||
|
||||
void RemoteTimeLogger::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);
|
||||
}
|
||||
|
||||
}
|
132
servant/libservant/RemoteNotify.cpp
Normal file
132
servant/libservant/RemoteNotify.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
/**
|
||||
* 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/RemoteNotify.h"
|
||||
#include "servant/Communicator.h"
|
||||
#include "servant/RemoteLogger.h"
|
||||
|
||||
namespace tars
|
||||
{
|
||||
|
||||
int RemoteNotify::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 RemoteNotify::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("RemoteNotify::report error:" << ex.what() << endl);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
TLOGERROR("RemoteNotify::report unknown error" << endl);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteNotify::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("RemoteNotify::notify error:" << ex.what() << endl);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
TLOGERROR("RemoteNotify::notify unknown error" << endl);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteNotify::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("RemoteNotify::notify error:" << ex.what() << endl);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
TLOGERROR("RemoteNotify::notify unknown error" << endl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
72
servant/servant/Cookie.h
Normal file
72
servant/servant/Cookie.h
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 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 CookieOp
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
CookieOp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 析构函数,清理掉已设置的cookie
|
||||
*/
|
||||
~CookieOp()
|
||||
{
|
||||
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
|
330
servant/servant/Current.h
Normal file
330
servant/servant/Current.h
Normal file
@ -0,0 +1,330 @@
|
||||
/**
|
||||
* 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 Current : public TC_HandleBase
|
||||
{
|
||||
public:
|
||||
typedef std::map<string, string> TARS_STATUS;
|
||||
|
||||
typedef std::vector<char> TARS_BUFFER;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param pServantHandle
|
||||
*/
|
||||
Current(ServantHandle *pServantHandle);
|
||||
|
||||
/**
|
||||
* 析构
|
||||
*/
|
||||
~Current();
|
||||
|
||||
/**
|
||||
* 获取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
|
80
servant/servant/KeepAliveNodeF.h
Normal file
80
servant/servant/KeepAliveNodeF.h
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 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发送心跳
|
||||
* 调用keepAlive异步发送心跳给node
|
||||
*/
|
||||
class KeepAliveNodeFHelper : public TC_Singleton<KeepAliveNodeFHelper>,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
|
||||
|
154
servant/servant/RemoteConfig.h
Normal file
154
servant/servant/RemoteConfig.h
Normal file
@ -0,0 +1,154 @@
|
||||
/**
|
||||
* 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 RemoteConfig : public TC_Singleton<RemoteConfig>
|
||||
{
|
||||
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);
|
||||
|
||||
/**
|
||||
* rename系统操作的封装,当oldFile不存在时抛出异常
|
||||
*
|
||||
* @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
|
893
servant/servant/RemoteLogger.h
Executable file
893
servant/servant/RemoteLogger.h
Executable file
@ -0,0 +1,893 @@
|
||||
/**
|
||||
* 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 在TimeWriteT类中包含RemoteTimeLogger对象
|
||||
7 在TimeWriteT类的写入操作中, 写入本地文件后, 同时写入到RemoteTimeLogger对象中
|
||||
8 RemoteTimeLogger会在RemoteTimeWriteT对象中, 异步写入到远程
|
||||
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 LocalRollLogger : public TC_Singleton<LocalRollLogger, 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;
|
||||
|
||||
/*
|
||||
* 本地日志的记录类型,格式为LogType.toString()返回值,如果不采用LogType,则该值为""
|
||||
*/
|
||||
string _logType;
|
||||
|
||||
/*
|
||||
* 对于远程日志,上报同步到logser的成功量,默认不上报
|
||||
*/
|
||||
PropertyReportPtr _reportSuccPtr;
|
||||
|
||||
/*
|
||||
* 对于远程日志,上报同步到logser的失败量,默认不上报
|
||||
*/
|
||||
PropertyReportPtr _reportFailPtr;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* 远程日志帮助类, 单件
|
||||
*/
|
||||
class RemoteTimeLogger : public TC_HandleBase
|
||||
, public TC_ThreadLock
|
||||
, public TC_Singleton<RemoteTimeLogger, CreateUsingNew, DefaultLifetime>
|
||||
{
|
||||
public:
|
||||
|
||||
//定义按时间滚动的日志
|
||||
typedef TC_Logger<TimeWriteT, TC_RollByTime> TimeLogger;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
RemoteTimeLogger();
|
||||
|
||||
/**
|
||||
* 析够
|
||||
*/
|
||||
~RemoteTimeLogger();
|
||||
|
||||
/**
|
||||
* 设置本地信息
|
||||
* @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 LogTypePtr& logTypePtr=NULL);
|
||||
void initFormat(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,const LogTypePtr& logTypePtr=NULL);
|
||||
/**
|
||||
* 初始化设置时间格式("%Y%m%d")
|
||||
* 不要动态修改, 线程不安全
|
||||
* 如果有需要, 初始化后直接修改
|
||||
* @param sFormat, 文件名称, 为空表示缺省的时间日志
|
||||
* @param frequency 支持每多少天/小时/分钟,详见TC_logger.h中关于TarsLogByDay,TarsLogByHour,TarsLogByMinute的描述
|
||||
*
|
||||
* 用法: 按两个小时记录日志
|
||||
* initFormat<TarsLogByHour>("logfile",TarsLogByHour::FORMAT,2);
|
||||
*/
|
||||
template<class TLogType>
|
||||
void initFormatWithType(const string &sFile, const string &sFormat,size_t frequency)
|
||||
{
|
||||
LogTypePtr logTypePtr = new TLogType(sFormat,frequency);
|
||||
initFormat(sFile,sFormat,logTypePtr);
|
||||
}
|
||||
|
||||
template<class TLogType>
|
||||
void initFormatWithType(const string &sApp, const string &sServer,const string &sFile, const string &sFormat,size_t frequency)
|
||||
{
|
||||
LogTypePtr logTypePtr = new TLogType(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 LogTypePtr& 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 LogTypePtr& 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)
|
||||
{
|
||||
LocalRollLogger::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 = "")
|
||||
{
|
||||
LocalRollLogger::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 (LocalRollLogger::getInstance()->logger())
|
||||
|
||||
/**
|
||||
* @brief 按级别循环日志宏
|
||||
*
|
||||
* @param level 日志等级,LocalRollLogger::INFO_LOG,LocalRollLogger::DEBUG_LOG,LocalRollLogger::WARN_LOG,LocalRollLogger::ERROR_LOG
|
||||
* @msg 日志内容语句,包括<<重定向符连接的语句,如 "Demo begin" << " testing !" <<endl;
|
||||
*
|
||||
* @用法:
|
||||
* 标准输出流方式: cout << "I have " << vApple.size() << " apples!"<<endl;
|
||||
* 框架宏方式: LOGMSG(LocalRollLogger::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(LocalRollLogger::INFO_LOG,__VA_ARGS__)
|
||||
#define TLOGDEBUG(...) LOGMSG(LocalRollLogger::DEBUG_LOG,__VA_ARGS__)
|
||||
#define TLOGWARN(...) LOGMSG(LocalRollLogger::WARN_LOG,__VA_ARGS__)
|
||||
#define TLOGERROR(...) LOGMSG(LocalRollLogger::ERROR_LOG,__VA_ARGS__)
|
||||
#define TLOGTARS(...) LOGMSG(LocalRollLogger::TARS_LOG,__VA_ARGS__)
|
||||
#else
|
||||
#define TLOGINFO(msg...) LOGMSG(LocalRollLogger::INFO_LOG,msg)
|
||||
#define TLOGDEBUG(msg...) LOGMSG(LocalRollLogger::DEBUG_LOG,msg)
|
||||
#define TLOGWARN(msg...) LOGMSG(LocalRollLogger::WARN_LOG,msg)
|
||||
#define TLOGERROR(msg...) LOGMSG(LocalRollLogger::ERROR_LOG,msg)
|
||||
#define TLOGTARS(msg...) LOGMSG(LocalRollLogger::TARS_LOG,msg)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 按天日志
|
||||
*/
|
||||
#define DLOG (RemoteTimeLogger::getInstance()->logger()->any())
|
||||
#define FDLOG(x) (RemoteTimeLogger::getInstance()->logger(x)->any())
|
||||
#define FFDLOG(x,y,z) (RemoteTimeLogger::getInstance()->logger(x,y,z)->any())
|
||||
|
||||
/**
|
||||
* 按天日志局部使能开关,针对单个日志文件进行使能,请在所有按天日志输出前调用
|
||||
*/
|
||||
#define TENREMOTE_FDLOG(swith,sApp,sServer,sFile) (RemoteTimeLogger::getInstance()->enableRemoteEx(sApp,sServer,sFile,swith))
|
||||
#define TENLOCAL_FDLOG(swith,sApp,sServer,sFile) (RemoteTimeLogger::getInstance()->enableLocalEx(sApp,sServer,sFile,swith))
|
||||
|
||||
/**
|
||||
* 按天日志全局使能开关,请在所有按天日志输出前调用
|
||||
*/
|
||||
#define TENREMOTE(swith) (RemoteTimeLogger::getInstance()->enableRemoteLog(swith))
|
||||
#define TENLOCAL(swith) (RemoteTimeLogger::getInstance()->enableLocalLog(swith))
|
||||
}
|
||||
|
||||
#endif
|
||||
|
101
servant/servant/RemoteNotify.h
Normal file
101
servant/servant/RemoteNotify.h
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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 RemoteNotify : public TC_Singleton<RemoteNotify>
|
||||
{
|
||||
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
|
@ -513,7 +513,7 @@ int yy_flex_debug = 0;
|
||||
#define YY_MORE_ADJ 0
|
||||
#define YY_RESTORE_YY_MORE_OFFSET
|
||||
char *yytext;
|
||||
#line 1 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 1 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 20 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 67 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 69 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
{ BEGIN(INCL); }
|
||||
YY_BREAK
|
||||
case 2:
|
||||
YY_RULE_SETUP
|
||||
#line 71 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 71 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 101 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 117 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
{
|
||||
return TARS_SCOPE_DELIMITER;
|
||||
}
|
||||
YY_BREAK
|
||||
case 4:
|
||||
YY_RULE_SETUP
|
||||
#line 121 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 121 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 139 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 187 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 194 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 204 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 316 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 338 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 369 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 376 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 392 "/Users/jarod/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 "/Volumes/MyData/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
#line 392 "/Users/jarod/centos/TarsCloud/framework/tarscpp/tools/tarsgrammar/tars.l"
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user