summaryrefslogtreecommitdiffstats
path: root/messagebus
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-07-24 15:38:24 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2017-07-25 09:17:11 +0200
commit6535f64c263804a888716c655f0c98e248c870b0 (patch)
tree0f87d7a705fde565add6d3d3d3f89c6690a4d3a1 /messagebus
parentd3770afe918fde04da7f69807b107e624c77b80a (diff)
No SP for getProtocol
Diffstat (limited to 'messagebus')
-rw-r--r--messagebus/src/tests/protocolrepository/protocolrepository.cpp2
-rw-r--r--messagebus/src/vespa/messagebus/messagebus.cpp8
-rw-r--r--messagebus/src/vespa/messagebus/messagebus.h2
-rw-r--r--messagebus/src/vespa/messagebus/network/inetworkowner.h4
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendv1.cpp13
-rw-r--r--messagebus/src/vespa/messagebus/protocolrepository.cpp11
-rw-r--r--messagebus/src/vespa/messagebus/protocolrepository.h9
7 files changed, 22 insertions, 27 deletions
diff --git a/messagebus/src/tests/protocolrepository/protocolrepository.cpp b/messagebus/src/tests/protocolrepository/protocolrepository.cpp
index 015185eeec3..b2454eb272a 100644
--- a/messagebus/src/tests/protocolrepository/protocolrepository.cpp
+++ b/messagebus/src/tests/protocolrepository/protocolrepository.cpp
@@ -63,7 +63,7 @@ Test::Main()
IRoutingPolicy::SP policy = repo.getRoutingPolicy("foo", "bar", "baz");
prev = repo.putProtocol(IProtocol::SP(new TestProtocol("foo")));
ASSERT_TRUE(prev.get() != NULL);
- ASSERT_NOT_EQUAL(prev.get(), repo.getProtocol("foo").get());
+ ASSERT_NOT_EQUAL(prev.get(), repo.getProtocol("foo"));
policy = repo.getRoutingPolicy("foo", "bar", "baz");
ASSERT_TRUE(policy.get() == NULL);
diff --git a/messagebus/src/vespa/messagebus/messagebus.cpp b/messagebus/src/vespa/messagebus/messagebus.cpp
index e32f5ca4137..4cd19b62419 100644
--- a/messagebus/src/vespa/messagebus/messagebus.cpp
+++ b/messagebus/src/vespa/messagebus/messagebus.cpp
@@ -286,10 +286,8 @@ MessageBus::setupRouting(const RoutingSpec &spec)
std::map<string, RoutingTable::SP> rtm;
for (uint32_t i = 0; i < spec.getNumTables(); ++i) {
const RoutingTableSpec &cfg = spec.getTable(i);
- IProtocol::SP protocol = getProtocol(cfg.getProtocol());
- if (protocol.get() == 0) { // protocol not found
- LOG(info, "Protocol '%s' is not supported, ignoring routing table.",
- cfg.getProtocol().c_str());
+ if (getProtocol(cfg.getProtocol()) == nullptr) { // protocol not found
+ LOG(info, "Protocol '%s' is not supported, ignoring routing table.", cfg.getProtocol().c_str());
continue;
}
RoutingTable::SP rt(new RoutingTable(cfg));
@@ -303,7 +301,7 @@ MessageBus::setupRouting(const RoutingSpec &spec)
return true;
}
-IProtocol::SP
+IProtocol *
MessageBus::getProtocol(const string &name)
{
return _protocolRepository->getProtocol(name);
diff --git a/messagebus/src/vespa/messagebus/messagebus.h b/messagebus/src/vespa/messagebus/messagebus.h
index 66dcadb98f2..d00444b563a 100644
--- a/messagebus/src/vespa/messagebus/messagebus.h
+++ b/messagebus/src/vespa/messagebus/messagebus.h
@@ -296,7 +296,7 @@ public:
bool setupRouting(const RoutingSpec &spec) override;
// Implements INetworkOwner.
- IProtocol::SP getProtocol(const string &name) override;
+ IProtocol * getProtocol(const string &name) override;
// Implements INetworkOwner.
void deliverMessage(Message::UP msg, const string &session) override;
diff --git a/messagebus/src/vespa/messagebus/network/inetworkowner.h b/messagebus/src/vespa/messagebus/network/inetworkowner.h
index c640033fd5e..7823b45bee9 100644
--- a/messagebus/src/vespa/messagebus/network/inetworkowner.h
+++ b/messagebus/src/vespa/messagebus/network/inetworkowner.h
@@ -1,8 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <memory>
#include <vespa/messagebus/common.h>
+#include <memory>
namespace mbus {
@@ -29,7 +29,7 @@ public:
* @param name The name of the protocol to return.
* @return The named protocol.
*/
- virtual std::shared_ptr<IProtocol> getProtocol(const string &name) = 0;
+ virtual IProtocol * getProtocol(const string &name) = 0;
/**
* All messages that arrive in the network layer is passed to its owner through this function.
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp
index f2922865907..4cf45207010 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp
@@ -232,11 +232,10 @@ RPCSendV1::RequestDone(FRT_RPCRequest *req)
const char *trace = ret[7]._string._str;
if (payloadLen > 0) {
- IProtocol::SP protocol = _net->getOwner().getProtocol(protocolName);
- if (protocol.get() != NULL) {
- Routable::UP routable = protocol->decode(version,
- BlobRef(payload, payloadLen));
- if (routable.get() != NULL) {
+ IProtocol * protocol = _net->getOwner().getProtocol(protocolName);
+ if (protocol != nullptr) {
+ Routable::UP routable = protocol->decode(version, BlobRef(payload, payloadLen));
+ if (routable) {
if (routable->isReply()) {
reply.reset(static_cast<Reply*>(routable.release()));
} else {
@@ -293,8 +292,8 @@ RPCSendV1::invoke(FRT_RPCRequest *req)
uint32_t payloadLen = args[7]._data._len;
uint32_t traceLevel = args[8]._intval32;
- IProtocol::SP protocol = _net->getOwner().getProtocol(protocolName);
- if (protocol.get() == NULL) {
+ IProtocol * protocol = _net->getOwner().getProtocol(protocolName);
+ if (protocol == nullptr) {
replyError(req, version, traceLevel,
Error(ErrorCode::UNKNOWN_PROTOCOL,
make_string("Protocol '%s' is not known by %s.", protocolName, _serverIdent.c_str())));
diff --git a/messagebus/src/vespa/messagebus/protocolrepository.cpp b/messagebus/src/vespa/messagebus/protocolrepository.cpp
index 26f6b53361f..abad6534331 100644
--- a/messagebus/src/vespa/messagebus/protocolrepository.cpp
+++ b/messagebus/src/vespa/messagebus/protocolrepository.cpp
@@ -19,10 +19,9 @@ ProtocolRepository::clearPolicyCache()
IProtocol::SP
ProtocolRepository::putProtocol(const IProtocol::SP & protocol)
{
- vespalib::LockGuard guard(_lock);
const string &name = protocol->getName();
if (_protocols.find(name) != _protocols.end()) {
- _routingPolicyCache.clear();
+ clearPolicyCache();
}
IProtocol::SP prev = _protocols[name];
_protocols[name] = protocol;
@@ -32,19 +31,17 @@ ProtocolRepository::putProtocol(const IProtocol::SP & protocol)
bool
ProtocolRepository::hasProtocol(const string &name) const
{
- vespalib::LockGuard guard(_lock);
return _protocols.find(name) != _protocols.end();
}
-IProtocol::SP
+IProtocol *
ProtocolRepository::getProtocol(const string &name)
{
- vespalib::LockGuard guard(_lock);
ProtocolMap::iterator it = _protocols.find(name);
if (it != _protocols.end()) {
- return it->second;
+ return it->second.get();
}
- return IProtocol::SP();
+ return nullptr;
}
IRoutingPolicy::SP
diff --git a/messagebus/src/vespa/messagebus/protocolrepository.h b/messagebus/src/vespa/messagebus/protocolrepository.h
index 726059a090f..341c7f8bc2d 100644
--- a/messagebus/src/vespa/messagebus/protocolrepository.h
+++ b/messagebus/src/vespa/messagebus/protocolrepository.h
@@ -1,9 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <map>
-#include <vespa/vespalib/util/sync.h>
#include "iprotocol.h"
+#include <vespa/vespalib/util/sync.h>
+#include <map>
namespace mbus {
@@ -16,7 +16,8 @@ private:
typedef std::map<string, IProtocol::SP> ProtocolMap;
typedef std::map<string, IRoutingPolicy::SP> RoutingPolicyCache;
- vespalib::Lock _lock;
+ vespalib::Lock _lock; // Only guards the cache,
+ // not the protocols as they are set up during messagebus construction.
ProtocolMap _protocols;
RoutingPolicyCache _routingPolicyCache;
@@ -52,7 +53,7 @@ public:
* @param name The name of the protocol to return.
* @return The protocol registered, or null.
*/
- IProtocol::SP getProtocol(const string &name);
+ IProtocol * getProtocol(const string &name);
/**
* Creates and returns a routing policy that matches the given arguments. If a routing policy has been