Faster publishing of order book changes to book listeners

This commit is contained in:
JoelKatz
2013-05-14 18:25:47 -07:00
parent e04ca79778
commit 423635d2ef
3 changed files with 19 additions and 7 deletions

View File

@@ -52,6 +52,8 @@ public:
virtual ~InfoSub();
virtual void send(const Json::Value& jvObj, bool broadcast) = 0;
virtual void send(const Json::Value& jvObj, const std::string& sObj, bool broadcast)
{ send(jvObj, broadcast); }
uint64 getSeq()
{

View File

@@ -167,13 +167,13 @@ void OrderBookDB::processTxn(Ledger::ref ledger, const ALTransaction& alTx, Json
const STObject* data = dynamic_cast<const STObject*>(node.peekAtPField(*field));
if (data)
{
STAmount takerGets = data->getFieldAmount(sfTakerGets);
uint160 currencyGets = takerGets.getCurrency();
uint160 issuerGets = takerGets.getIssuer();
const STAmount& takerGets = data->getFieldAmount(sfTakerGets);
const uint160& currencyGets = takerGets.getCurrency();
const uint160& issuerGets = takerGets.getIssuer();
STAmount takerPays = data->getFieldAmount(sfTakerPays);
uint160 currencyPays = takerPays.getCurrency();
uint160 issuerPays = takerPays.getIssuer();
const STAmount& takerPays = data->getFieldAmount(sfTakerPays);
const uint160& currencyPays = takerPays.getCurrency();
const uint160& issuerPays = takerPays.getIssuer();
// determine the OrderBook
BookListeners::pointer book =
@@ -206,6 +206,9 @@ void BookListeners::removeSubscriber(uint64 seq)
void BookListeners::publish(Json::Value& jvObj)
{
Json::FastWriter jfwWriter;
std::string sObj = jfwWriter.write(jvObj);
boost::recursive_mutex::scoped_lock sl(mLock);
NetworkOPs::subMapType::const_iterator it = mListeners.begin();
while (it != mListeners.end())
@@ -213,7 +216,7 @@ void BookListeners::publish(Json::Value& jvObj)
InfoSub::pointer p = it->second.lock();
if (p)
{
p->send(jvObj, true);
p->send(jvObj, sObj, true);
++it;
}
else

View File

@@ -95,6 +95,13 @@ public:
mHandler->send(ptr, jvObj, broadcast);
}
void send(const Json::Value& jvObj, const std::string& sObj, bool broadcast)
{
connection_ptr ptr = mConnection.lock();
if (ptr)
mHandler->send(ptr, sObj, broadcast);
}
// Utilities
Json::Value invokeCommand(Json::Value& jvRequest)
{