add files

This commit is contained in:
ruanshudong 2020-04-01 20:40:43 +08:00
parent 6d5f517be7
commit 750ee9e6fd
13 changed files with 3402 additions and 151 deletions

View 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);
}
}
////////////////////////////////////////////////////////////////////////////
}

View 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);
}
}
}

View 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 goodenpeiwindows下面先remove后rename否则rename会失败
if (TC_File::isFileExist(oldFile) && TC_File::isFileExist(newFile))
{
::remove(newFile.c_str());
}
#endif
if (::rename(oldFile.c_str(), newFile.c_str()) != 0)
{
throw runtime_error("rename file error:" + oldFile + "->" + newFile);
}
}
string 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.";
}
}

View 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);
}
}

View 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
View 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
View 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

View 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

View 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
View 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

View 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

View File

@ -513,7 +513,7 @@ int yy_flex_debug = 0;
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "/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