Skip to content

Commit

Permalink
servant prx suppport keepAliveCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Apr 22, 2024
1 parent c8b8201 commit 8b0d914
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
39 changes: 23 additions & 16 deletions servant/libservant/AdapterProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,28 +1055,35 @@ void AdapterProxy::doKeepAlive()
TLOGTARS("[AdapterProxy::doKeepAlive, " << _objectProxy->name() << ", " << _trans->getConnectionString() << "]" << endl);

ReqMessage *msg = new ReqMessage();
// ServantProxyCallbackPtr callback = new PingCallback();
ServantProxyCallbackPtr callback (new PingCallback());
callback->setServantPrx(_objectProxy->getServantProxy());

msg->init(ReqMessage::ASYNC_CALL, _objectProxy->getServantProxy());
msg->callback = callback;
if(_objectProxy->getRootServantProxy()->tars_get_protocol().keepAliveCallback)
{
_objectProxy->getRootServantProxy()->tars_get_protocol().keepAliveCallback(_objectProxy->getServantProxy());
}
else
{
msg->init(ReqMessage::ASYNC_CALL, _objectProxy->getServantProxy());

ServantProxyCallbackPtr callback(new PingCallback());
callback->setServantPrx(_objectProxy->getServantProxy());

msg->request.iVersion = TARSVERSION;
msg->request.cPacketType = TARSNORMAL;
msg->request.sFuncName = "tars_ping";
msg->request.sServantName = _objectProxy->name();
msg->callback = callback;

msg->request.iTimeout = ServantProxy::DEFAULT_ASYNCTIMEOUT;
msg->request.iVersion = TARSVERSION;
msg->request.cPacketType = TARSNORMAL;
msg->request.sFuncName = "tars_ping";
msg->request.sServantName = _objectProxy->name();
msg->request.iTimeout = ServantProxy::DEFAULT_ASYNCTIMEOUT;

msg->proxy = _objectProxy->getServantProxy();
msg->response->iRet = TARSSERVERUNKNOWNERR;
msg->proxy = _objectProxy->getServantProxy();
msg->response->iRet = TARSSERVERUNKNOWNERR;

//调用发起时间
msg->iBeginTime = TNOWMS;
msg->pObjectProxy = _objectProxy;
//调用发起时间
msg->iBeginTime = TNOWMS;
msg->pObjectProxy = _objectProxy;

invoke(msg);
invoke(msg);
}
}


Expand Down
7 changes: 7 additions & 0 deletions servant/servant/AppProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "tup/tup.h"
#include "servant/BaseF.h"
#include "util/tc_network_buffer.h"
#include "servant/Global.h"

using namespace std;
using namespace tup;
Expand Down Expand Up @@ -319,6 +320,12 @@ class ProxyProtocol
request_protocol requestFunc;

response_protocol responseFunc;

/**
* 开启openalive, 如果keepAliveCallback未设置则直接发包, 如果keepAliveCallback设置, 则回调(不再发tars_ping)
* 如果是非tars协议如果开启openalive, 则需要设置keepAliveCallback, 自己发包
*/
std::function<void(ServantPrx)> keepAliveCallback;
};

//////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions servant/servant/ServantProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,8 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex
* 对应通信内部的moduleName
*/
string _moduleName;


};
}
#endif

0 comments on commit 8b0d914

Please sign in to comment.