aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-03-24 12:18:51 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-03-24 12:18:51 +0000
commit3b22ac90c3c55128963bf29702604549ed651549 (patch)
treea713df0f39125cd584d0e220d940f87c2c6143a9 /messagebus
parentadf7b03ebec1614fa9b0bba2a14042968bc876b5 (diff)
- Avoid adding empty traces that you need to carry on.
- Avoid copying shared pointers when not necessary. - Some c++11 improvements.
Diffstat (limited to 'messagebus')
-rw-r--r--messagebus/src/tests/routeparser/routeparser.cpp61
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendv2.cpp7
-rw-r--r--messagebus/src/vespa/messagebus/routable.cpp2
-rw-r--r--messagebus/src/vespa/messagebus/routing/hop.cpp30
-rw-r--r--messagebus/src/vespa/messagebus/routing/hop.h23
-rw-r--r--messagebus/src/vespa/messagebus/routing/hopblueprint.cpp17
-rw-r--r--messagebus/src/vespa/messagebus/routing/hopblueprint.h8
-rw-r--r--messagebus/src/vespa/messagebus/routing/routeparser.cpp6
-rw-r--r--messagebus/src/vespa/messagebus/routing/routingcontext.cpp11
-rw-r--r--messagebus/src/vespa/messagebus/routing/routingnode.cpp99
-rw-r--r--messagebus/src/vespa/messagebus/trace.h4
-rw-r--r--messagebus/src/vespa/messagebus/tracenode.h11
12 files changed, 94 insertions, 185 deletions
diff --git a/messagebus/src/tests/routeparser/routeparser.cpp b/messagebus/src/tests/routeparser/routeparser.cpp
index eb72b03e76a..12054c6c494 100644
--- a/messagebus/src/tests/routeparser/routeparser.cpp
+++ b/messagebus/src/tests/routeparser/routeparser.cpp
@@ -29,11 +29,11 @@ public:
private:
bool testError(const Route &route, const string &msg);
bool testError(const Hop &hop, const string &msg);
- bool testErrorDirective(IHopDirective::SP dir, const string &msg);
- bool testPolicyDirective(IHopDirective::SP dir, const string &name, const string &param);
- bool testRouteDirective(IHopDirective::SP dir, const string &name);
- bool testTcpDirective(IHopDirective::SP dir, const string &host, uint32_t port, const string &session);
- bool testVerbatimDirective(IHopDirective::SP dir, const string &image);
+ bool testErrorDirective(const IHopDirective & dir, const string &msg);
+ bool testPolicyDirective(const IHopDirective & dir, const string &name, const string &param);
+ bool testRouteDirective(const IHopDirective & dir, const string &name);
+ bool testTcpDirective(const IHopDirective & dir, const string &host, uint32_t port, const string &session);
+ bool testVerbatimDirective(const IHopDirective & dir, const string &image);
};
TEST_APPHOOK(Test);
@@ -77,84 +77,69 @@ Test::testError(const Hop &hop, const string &msg)
}
bool
-Test::testErrorDirective(IHopDirective::SP dir, const string &msg)
+Test::testErrorDirective(const IHopDirective & dir, const string &msg)
{
- if (!EXPECT_TRUE(dir.get() != NULL)) {
+ if (!EXPECT_EQUAL(IHopDirective::TYPE_ERROR, dir.getType())) {
return false;
}
- if (!EXPECT_EQUAL(IHopDirective::TYPE_ERROR, dir->getType())) {
- return false;
- }
- if (!EXPECT_EQUAL(msg, static_cast<const ErrorDirective&>(*dir).getMessage())) {
+ if (!EXPECT_EQUAL(msg, static_cast<const ErrorDirective&>(dir).getMessage())) {
return false;
}
return true;
}
bool
-Test::testPolicyDirective(IHopDirective::SP dir, const string &name, const string &param)
+Test::testPolicyDirective(const IHopDirective & dir, const string &name, const string &param)
{
- if (!EXPECT_TRUE(dir.get() != NULL)) {
+ if (!EXPECT_EQUAL(IHopDirective::TYPE_POLICY, dir.getType())) {
return false;
}
- if (!EXPECT_EQUAL(IHopDirective::TYPE_POLICY, dir->getType())) {
+ if (!EXPECT_EQUAL(name, static_cast<const PolicyDirective&>(dir).getName())) {
return false;
}
- if (!EXPECT_EQUAL(name, static_cast<const PolicyDirective&>(*dir).getName())) {
- return false;
- }
- if (!EXPECT_EQUAL(param, static_cast<const PolicyDirective&>(*dir).getParam())) {
+ if (!EXPECT_EQUAL(param, static_cast<const PolicyDirective&>(dir).getParam())) {
return false;
}
return true;
}
bool
-Test::testRouteDirective(IHopDirective::SP dir, const string &name)
+Test::testRouteDirective(const IHopDirective & dir, const string &name)
{
- if (!EXPECT_TRUE(dir.get() != NULL)) {
- return false;
- }
- if (!EXPECT_EQUAL(IHopDirective::TYPE_ROUTE, dir->getType())) {
+ if (!EXPECT_EQUAL(IHopDirective::TYPE_ROUTE, dir.getType())) {
return false;
}
- if (!EXPECT_EQUAL(name, static_cast<const RouteDirective&>(*dir).getName())) {
+ if (!EXPECT_EQUAL(name, static_cast<const RouteDirective&>(dir).getName())) {
return false;
}
return true;
}
bool
-Test::testTcpDirective(IHopDirective::SP dir, const string &host, uint32_t port, const string &session)
+Test::testTcpDirective(const IHopDirective & dir, const string &host, uint32_t port, const string &session)
{
- if (!EXPECT_TRUE(dir.get() != NULL)) {
- return false;
- }
- if (!EXPECT_EQUAL(IHopDirective::TYPE_TCP, dir->getType())) {
+ if (!EXPECT_EQUAL(IHopDirective::TYPE_TCP, dir.getType())) {
return false;
}
- if (!EXPECT_EQUAL(host, static_cast<const TcpDirective&>(*dir).getHost())) {
+ if (!EXPECT_EQUAL(host, static_cast<const TcpDirective&>(dir).getHost())) {
return false;
}
- if (!EXPECT_EQUAL(port, static_cast<const TcpDirective&>(*dir).getPort())) {
+ if (!EXPECT_EQUAL(port, static_cast<const TcpDirective&>(dir).getPort())) {
return false;
}
- if (!EXPECT_EQUAL(session, static_cast<const TcpDirective&>(*dir).getSession())) {
+ if (!EXPECT_EQUAL(session, static_cast<const TcpDirective&>(dir).getSession())) {
return false;
}
return true;
}
bool
-Test::testVerbatimDirective(IHopDirective::SP dir, const string &image)
+Test::testVerbatimDirective(const IHopDirective & dir, const string &image)
{
- if (!EXPECT_TRUE(dir.get() != NULL)) {
- return false;
- }
- if (!EXPECT_EQUAL(IHopDirective::TYPE_VERBATIM, dir->getType())) {
+ if (!EXPECT_EQUAL(IHopDirective::TYPE_VERBATIM, dir.getType())) {
return false;
}
- if (!EXPECT_EQUAL(image, static_cast<const VerbatimDirective&>(*dir).getImage())) {
+ if (!EXPECT_EQUAL(image, static_cast<const VerbatimDirective&>(dir).getImage())) {
return false;
}
return true;
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
index 3b0c10500b9..6afa1528092 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
@@ -207,7 +207,7 @@ RPCSendV2::createReply(const FRT_Values & ret, const string & serviceName,
reply = decode(root[PROTOCOL_F].asString().make_stringref(), version, BlobRef(payload.data, payload.size), error);
}
if ( ! reply ) {
- reply.reset(new EmptyReply());
+ reply = std::make_unique<EmptyReply>();
}
reply->setRetryDelay(root[RETRYDELAY_F].asDouble());
Inspector & errors = root[ERRORS_F];
@@ -217,7 +217,10 @@ RPCSendV2::createReply(const FRT_Values & ret, const string & serviceName,
reply->addError(Error(e[CODE_F].asLong(), e[MSG_F].asString().make_string(),
(service.size > 0) ? service.make_string() : serviceName));
}
- rootTrace.addChild(TraceNode::decode(root[TRACE_F].asString().make_string()));
+ Inspector & trace = root[TRACE_F];
+ if (trace.valid() && (trace.asString().size > 0)) {
+ rootTrace.addChild(TraceNode::decode(trace.asString().make_string()));
+ }
return reply;
}
diff --git a/messagebus/src/vespa/messagebus/routable.cpp b/messagebus/src/vespa/messagebus/routable.cpp
index 6c62d7e75ca..801029c5bc7 100644
--- a/messagebus/src/vespa/messagebus/routable.cpp
+++ b/messagebus/src/vespa/messagebus/routable.cpp
@@ -11,7 +11,7 @@ Routable::Routable() :
_trace()
{ }
-Routable::~Routable() { }
+Routable::~Routable() = default;
void
Routable::discard()
diff --git a/messagebus/src/vespa/messagebus/routing/hop.cpp b/messagebus/src/vespa/messagebus/routing/hop.cpp
index 232ae9f840a..76f58d57d7b 100644
--- a/messagebus/src/vespa/messagebus/routing/hop.cpp
+++ b/messagebus/src/vespa/messagebus/routing/hop.cpp
@@ -25,41 +25,19 @@ Hop::Hop(std::vector<IHopDirective::SP> selector, bool ignoreResult) :
Hop::Hop(const Hop &) = default;
Hop & Hop::operator = (const Hop &) = default;
-Hop::~Hop() { }
+Hop::~Hop() = default;
Hop &
Hop::addDirective(IHopDirective::SP dir)
{
- _selector.push_back(dir);
+ _selector.emplace_back(std::move(dir));
return *this;
}
Hop &
Hop::setDirective(uint32_t i, IHopDirective::SP dir)
{
- _selector[i] = dir;
- return *this;
-}
-
-IHopDirective::SP
-Hop::removeDirective(uint32_t i)
-{
- IHopDirective::SP ret = _selector[i];
- _selector.erase(_selector.begin() + i);
- return ret;
-}
-
-Hop &
-Hop::clearDirectives()
-{
- _selector.clear();
- return *this;
-}
-
-Hop &
-Hop::setIgnoreResult(bool ignoreResult)
-{
- _ignoreResult = ignoreResult;
+ _selector[i] = std::move(dir);
return *this;
}
@@ -76,7 +54,7 @@ Hop::matches(const Hop &hop) const
return false;
}
for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) {
- if (!_selector[i]->matches(*hop.getDirective(i))) {
+ if (!_selector[i]->matches(hop.getDirective(i))) {
return false;
}
}
diff --git a/messagebus/src/vespa/messagebus/routing/hop.h b/messagebus/src/vespa/messagebus/routing/hop.h
index 6e7ab94caa1..94140bdd953 100644
--- a/messagebus/src/vespa/messagebus/routing/hop.h
+++ b/messagebus/src/vespa/messagebus/routing/hop.h
@@ -77,7 +77,8 @@ public:
* @param i The index of the directive to return.
* @return The item.
*/
- IHopDirective::SP getDirective(uint32_t i) const { return _selector[i]; }
+ const IHopDirective & getDirective(uint32_t i) const { return *_selector[i]; }
+ IHopDirective::SP getDirectiveSP(uint32_t i) const { return _selector[i]; }
/**
* Sets the directive at a given index.
@@ -89,21 +90,6 @@ public:
Hop &setDirective(uint32_t i, IHopDirective::SP dir);
/**
- * Removes the directive at the given index.
- *
- * @param i The index of the directive to remove.
- * @return The removed directive.
- */
- IHopDirective::SP removeDirective(uint32_t i);
-
- /**
- * Clears all directives from this hop.
- *
- * @return This, to allow chaining.
- */
- Hop &clearDirectives();
-
- /**
* Returns the service name referenced by this hop. This is the concatenation of all selector primitives,
* but with no ignore-result prefix.
*
@@ -124,7 +110,10 @@ public:
* @param ignoreResult Whether or not to ignore the result.
* @return This, to allow chaining.
*/
- Hop &setIgnoreResult(bool ignoreResult);
+ Hop &setIgnoreResult(bool ignoreResult) {
+ _ignoreResult = ignoreResult;
+ return *this;
+ }
/**
* Parses the given string as a single hop. The {@link this#toString()} method is compatible with this parser.
diff --git a/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp b/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp
index 0bd9aaa6c50..b9d6780fd63 100644
--- a/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp
+++ b/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp
@@ -11,26 +11,17 @@ HopBlueprint::HopBlueprint(const HopSpec &spec) :
{
Hop hop = Hop::parse(spec.getSelector());
for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) {
- _selector.push_back(hop.getDirective(i));
+ _selector.emplace_back(hop.getDirectiveSP(i));
}
std::vector<string> lst;
for (uint32_t i = 0; i < spec.getNumRecipients(); ++i) {
- lst.push_back(spec.getRecipient(i));
+ lst.emplace_back(spec.getRecipient(i));
}
- for (std::vector<string>::iterator it = lst.begin();
- it != lst.end(); ++it)
- {
- _recipients.push_back(Hop::parse(*it));
+ for (const string & recipient : lst) {
+ _recipients.emplace_back(Hop::parse(recipient));
}
}
-HopBlueprint &
-HopBlueprint::setIgnoreResult(bool ignoreResult)
-{
- _ignoreResult = ignoreResult;
- return *this;
-}
-
string
HopBlueprint::toString() const
{
diff --git a/messagebus/src/vespa/messagebus/routing/hopblueprint.h b/messagebus/src/vespa/messagebus/routing/hopblueprint.h
index 1ae8def398d..21b449651f1 100644
--- a/messagebus/src/vespa/messagebus/routing/hopblueprint.h
+++ b/messagebus/src/vespa/messagebus/routing/hopblueprint.h
@@ -84,14 +84,6 @@ public:
bool getIgnoreResult() const { return _ignoreResult; }
/**
- * Sets whether or not to ignore the result when routing through this hop.
- *
- * @param ignoreResult Whether or not to ignore the result.
- * @return This, to allow chaining.
- */
- HopBlueprint &setIgnoreResult(bool ignoreResult);
-
- /**
* Returns a string representation of this.
*
* @return The string.
diff --git a/messagebus/src/vespa/messagebus/routing/routeparser.cpp b/messagebus/src/vespa/messagebus/routing/routeparser.cpp
index 88d5d6e4a0f..c9c10b38014 100644
--- a/messagebus/src/vespa/messagebus/routing/routeparser.cpp
+++ b/messagebus/src/vespa/messagebus/routing/routeparser.cpp
@@ -85,8 +85,8 @@ RouteParser::createHop(stringref str)
}
if (len > 4 && str.substr(0, 4) == "tcp/") {
IHopDirective::SP tcp = createTcpDirective(str.substr(4));
- if (tcp.get() != nullptr) {
- return Hop().addDirective(tcp);
+ if (tcp) {
+ return Hop().addDirective(std::move(tcp));
}
}
if (len > 6 && str.substr(0, 6) == "route:") {
@@ -128,7 +128,7 @@ RouteParser::createRoute(stringref str)
if (from < at - 1) {
Hop hop = createHop(str.substr(from, at - from));
if (hop.hasDirectives() &&
- hop.getDirective(0)->getType() == IHopDirective::TYPE_ERROR)
+ hop.getDirective(0).getType() == IHopDirective::TYPE_ERROR)
{
return std::move(Route().addHop(std::move(hop)));
}
diff --git a/messagebus/src/vespa/messagebus/routing/routingcontext.cpp b/messagebus/src/vespa/messagebus/routing/routingcontext.cpp
index 12aaa160eab..3da0ad700a3 100644
--- a/messagebus/src/vespa/messagebus/routing/routingcontext.cpp
+++ b/messagebus/src/vespa/messagebus/routing/routingcontext.cpp
@@ -44,14 +44,13 @@ RoutingContext::getMatchedRecipients(std::vector<Route> &ret) const
std::set<string> done;
const std::vector<Route> &recipients = _node.getRecipients();
const Hop &hop = getHop();
- for (std::vector<Route>::const_iterator it = recipients.begin();
- it != recipients.end(); ++it)
+ for (const Route & recipient : recipients)
{
- if (it->hasHops() && hop.matches(it->getHop(0))) {
- IHopDirective::SP dir = it->getHop(0).getDirective(_directive);
+ if (recipient.hasHops() && hop.matches(recipient.getHop(0))) {
+ IHopDirective::SP dir = recipient.getHop(0).getDirectiveSP(_directive);
string key = dir->toString();
if (done.find(key) == done.end()) {
- Route add = *it;
+ Route add = recipient;
add.setHop(0, hop);
add.getHop(0).setDirective(_directive, std::move(dir));
ret.push_back(std::move(add));
@@ -95,7 +94,7 @@ RoutingContext::getDirectiveIndex() const
const PolicyDirective &
RoutingContext::getDirective() const
{
- return static_cast<const PolicyDirective&>(*getHop().getDirective(_directive));
+ return static_cast<const PolicyDirective&>(getHop().getDirective(_directive));
}
string
diff --git a/messagebus/src/vespa/messagebus/routing/routingnode.cpp b/messagebus/src/vespa/messagebus/routing/routingnode.cpp
index b5b99ea43c2..77a164eddf9 100644
--- a/messagebus/src/vespa/messagebus/routing/routingnode.cpp
+++ b/messagebus/src/vespa/messagebus/routing/routingnode.cpp
@@ -67,10 +67,8 @@ RoutingNode::~RoutingNode()
void
RoutingNode::clearChildren()
{
- for (std::vector<RoutingNode*>::iterator it = _children.begin();
- it != _children.end(); ++it)
- {
- delete *it;
+ for (auto child : _children) {
+ delete child;
}
_children.clear();
}
@@ -101,15 +99,12 @@ RoutingNode::prepareForRetry()
{
_shouldRetry = false;
_reply.reset();
- if (_routingContext.get() != nullptr && _routingContext->getSelectOnRetry()) {
+ if (_routingContext && _routingContext->getSelectOnRetry()) {
clearChildren();
} else if (!_children.empty()) {
bool retryingSome = false;
- for (std::vector<RoutingNode*>::iterator it = _children.begin();
- it != _children.end(); ++it)
- {
- RoutingNode *child= *it;
- if (child->_shouldRetry || child->_reply.get() == nullptr) {
+ for (auto child : _children) {
+ if (child->_shouldRetry || ! child->_reply) {
child->prepareForRetry();
retryingSome = true;
}
@@ -159,7 +154,7 @@ RoutingNode::setError(uint32_t code, const string &msg)
void
RoutingNode::setError(const Error &err)
{
- Reply::UP reply(new EmptyReply());
+ auto reply = std::make_unique<EmptyReply>();
reply->getTrace().setLevel(_trace.getLevel());
reply->addError(err);
setReply(std::move(reply));
@@ -188,8 +183,10 @@ RoutingNode::setReply(Reply::UP reply)
{
if (reply) {
_shouldRetry = _resender != nullptr && _resender->shouldRetry(*reply);
- _trace.getRoot().addChild(std::move(reply->getTrace().getRoot()));
- reply->getTrace().clear();
+ if ( ! reply->getTrace().getRoot().isEmpty()) {
+ _trace.getRoot().addChild(std::move(reply->getTrace().getRoot()));
+ reply->getTrace().clear();
+ }
}
_reply = std::move(reply);
}
@@ -211,16 +208,14 @@ RoutingNode::notifyAbort(const string &msg)
mystack.pop();
if (!node->_isActive) {
// reply not pending
- } else if (node->_reply.get() != nullptr) {
+ } else if (node->_reply) {
node->notifyParent();
} else if (node->_children.empty()) {
node->setError(ErrorCode::SEND_ABORTED, msg);
node->notifyParent();
} else {
- for (std::vector<RoutingNode*>::iterator it = node->_children.begin();
- it != node->_children.end(); ++it)
- {
- mystack.push(*it);
+ for (auto child : node->_children) {
+ mystack.push(child);
}
}
}
@@ -240,14 +235,12 @@ RoutingNode::notifyTransmit()
if (node->hasReply()) {
node->notifyParent();
} else {
- assert(node->_serviceAddress.get() != nullptr);
+ assert(node->_serviceAddress);
sendTo.push_back(node);
}
} else {
- for (std::vector<RoutingNode*>::iterator it = node->_children.begin();
- it != node->_children.end(); ++it)
- {
- mystack.push(*it);
+ for (auto child : node->_children) {
+ mystack.push(child);
}
}
}
@@ -275,10 +268,8 @@ RoutingNode::notifyMerge()
// manipulating the trace in case tracing is disabled.
if (_trace.getLevel() > 0) {
TraceNode tail;
- for (std::vector<RoutingNode*>::iterator it = _children.begin();
- it != _children.end(); ++it)
- {
- TraceNode &root = (*it)->_trace.getRoot();
+ for (auto child : _children) {
+ TraceNode &root = child->_trace.getRoot();
tail.addChild(root);
root.clear();
}
@@ -296,7 +287,7 @@ RoutingNode::notifyMerge()
setError(ErrorCode::POLICY_ERROR, make_string("Policy '%s' threw an exception; %s",
dir.getName().c_str(), e.what()));
}
- if (_reply.get() == nullptr) {
+ if ( ! _reply) {
setError(ErrorCode::APP_FATAL_ERROR, make_string("Routing policy '%s' failed to merge replies.",
dir.getName().c_str()));
}
@@ -315,12 +306,12 @@ RoutingNode::hasUnconsumedErrors()
while (!mystack.empty()) {
RoutingNode *node = mystack.top();
mystack.pop();
- if (node->_reply.get() != nullptr) {
+ if (node->_reply) {
for (uint32_t i = 0; i < node->_reply->getNumErrors(); ++i) {
int errorCode = node->_reply->getError(i).getCode();
RoutingNode *it = node;
while (it != nullptr) {
- if (it->_routingContext.get() != nullptr &&
+ if (it->_routingContext &&
it->_routingContext->isConsumableError(errorCode))
{
errorCode = ErrorCode::NONE;
@@ -337,10 +328,8 @@ RoutingNode::hasUnconsumedErrors()
}
}
} else {
- for (std::vector<RoutingNode*>::iterator it = node->_children.begin();
- it != node->_children.end(); ++it)
- {
- mystack.push(*it);
+ for (auto child : node->_children) {
+ mystack.push(child);
}
}
}
@@ -374,17 +363,17 @@ RoutingNode::resolve(uint32_t depth)
if (executePolicySelect()) {
return resolveChildren(depth + 1);
}
- return _reply.get() != nullptr;
+ return bool(_reply);
}
_net.allocServiceAddress(*this);
- return _serviceAddress.get() != nullptr || _reply.get() != nullptr;
+ return _serviceAddress || _reply;
}
bool
RoutingNode::lookupHop()
{
RoutingTable::SP table = _mbus.getRoutingTable(_msg.getProtocol());
- if (table.get() != nullptr) {
+ if (table) {
string name = _route.getHop(0).getServiceName();
if (table->hasHop(name)) {
const HopBlueprint *hop = table->getHop(name);
@@ -402,8 +391,9 @@ RoutingNode::lookupRoute()
{
RoutingTable::SP table = _mbus.getRoutingTable(_msg.getProtocol());
Hop &hop = _route.getHop(0);
- if (hop.getDirective(0)->getType() == IHopDirective::TYPE_ROUTE) {
- RouteDirective &dir = static_cast<RouteDirective&>(*hop.getDirective(0));
+ const RouteDirective &dir = static_cast<const RouteDirective&>(hop.getDirective(0));
+ if (dir.getType() == IHopDirective::TYPE_ROUTE) {
+
if (!table || !table->hasRoute(dir.getName())) {
setError(ErrorCode::ILLEGAL_ROUTE, make_string("Route '%s' does not exist.", dir.getName().c_str()));
return false;
@@ -443,10 +433,10 @@ RoutingNode::findErrorDirective()
{
Hop &hop = _route.getHop(0);
for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) {
- IHopDirective::SP dir = hop.getDirective(i);
- if (dir->getType() == IHopDirective::TYPE_ERROR) {
+ const IHopDirective & dir = hop.getDirective(i);
+ if (dir.getType() == IHopDirective::TYPE_ERROR) {
setError(ErrorCode::ILLEGAL_ROUTE,
- static_cast<ErrorDirective&>(*dir).getMessage());
+ static_cast<const ErrorDirective&>(dir).getMessage());
return true;
}
}
@@ -458,9 +448,8 @@ RoutingNode::findPolicyDirective()
{
Hop &hop = _route.getHop(0);
for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) {
- IHopDirective::SP dir = hop.getDirective(i);
- if (dir->getType() == IHopDirective::TYPE_POLICY) {
- _routingContext.reset(new RoutingContext(*this, i));
+ if (hop.getDirective(i).getType() == IHopDirective::TYPE_POLICY) {
+ _routingContext = std::make_unique<RoutingContext>(*this, i);
return true;
}
}
@@ -472,7 +461,7 @@ RoutingNode::executePolicySelect()
{
const PolicyDirective &dir = _routingContext->getDirective();
_policy = _mbus.getRoutingPolicy(_msg.getProtocol(), dir.getName(), dir.getParam());
- if (_policy.get() == nullptr) {
+ if ( ! _policy) {
setError(ErrorCode::UNKNOWN_POLICY, make_string(
"Protocol '%s' could not create routing policy '%s' with parameter '%s'.",
_msg.getProtocol().c_str(), dir.getName().c_str(), dir.getParam().c_str()));
@@ -487,7 +476,7 @@ RoutingNode::executePolicySelect()
return false;
}
if (_children.empty()) {
- if (_reply.get() == nullptr) {
+ if ( ! _reply) {
setError(ErrorCode::NO_SERVICES_FOR_ROUTE,
make_string("Policy '%s' selected no recipients for route '%s'.",
dir.getName().c_str(), _route.toString().c_str()));
@@ -497,10 +486,7 @@ RoutingNode::executePolicySelect()
}
return false;
}
- for (std::vector<RoutingNode*>::iterator it = _children.begin();
- it != _children.end(); ++it)
- {
- RoutingNode *child = *it;
+ for (auto child : _children) {
Hop &hop = child->_route.getHop(0);
child->_trace.trace(TraceLevel::SPLIT_MERGE,
make_string("Component '%s' selected by policy '%s'.",
@@ -514,13 +500,10 @@ RoutingNode::resolveChildren(uint32_t childDepth)
{
int numActiveChildren = 0;
bool ret = true;
- for (std::vector<RoutingNode*>::iterator it = _children.begin();
- it != _children.end(); ++it)
- {
- RoutingNode *child = *it;
+ for (auto child : _children) {
child->_trace.trace(TraceLevel::SPLIT_MERGE,
make_string("Resolving '%s'.", child->_route.toString().c_str()));
- child->_isActive = (child->_reply.get() == nullptr);
+ child->_isActive = ! child->_reply;
if (child->_isActive) {
++numActiveChildren;
if (!child->resolve(childDepth)) {
@@ -560,10 +543,10 @@ RoutingNode::tryIgnoreResult()
if (!shouldIgnoreResult()) {
return false;
}
- if (_reply.get() == nullptr || !_reply->hasErrors()) {
+ if ( ! _reply || !_reply->hasErrors()) {
return false;
}
- setReply(Reply::UP(new EmptyReply()));
+ setReply(std::make_unique<EmptyReply>());
_trace.trace(TraceLevel::SPLIT_MERGE, "Ignoring errors in reply.");
return true;
}
diff --git a/messagebus/src/vespa/messagebus/trace.h b/messagebus/src/vespa/messagebus/trace.h
index a5f02ea2fa4..5a26cb68e46 100644
--- a/messagebus/src/vespa/messagebus/trace.h
+++ b/messagebus/src/vespa/messagebus/trace.h
@@ -3,11 +3,11 @@
#pragma once
#include <vespa/vespalib/trace/trace.h>
-#include <vespa/messagebus/tracenode.h>
namespace mbus {
- typedef vespalib::Trace Trace;
+ using Trace = vespalib::Trace;
+ using TraceNode = vespalib::TraceNode;
#define MBUS_TRACE2(ttrace, level, note, addTime) \
VESPALIB_TRACE2(ttrace, level, note, addTime)
diff --git a/messagebus/src/vespa/messagebus/tracenode.h b/messagebus/src/vespa/messagebus/tracenode.h
deleted file mode 100644
index f582a70a151..00000000000
--- a/messagebus/src/vespa/messagebus/tracenode.h
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/vespalib/trace/tracenode.h>
-
-namespace mbus {
-
- using TraceNode = vespalib::TraceNode;
-
-} // namespace mbus
-