aboutsummaryrefslogtreecommitdiffstats
path: root/slobrok
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-06-07 15:26:21 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-06-07 17:26:13 +0200
commit66ccfc97c765c7cb5faf1ca007dad1d3cde31c34 (patch)
tree79ceb52e0a1f4f8ffd0645805d811d66eb9c5758 /slobrok
parentd21881192bc98aa6d45beb8ae3503427f6c82ce4 (diff)
Throw instead of asserting giving the user the ability to handle the error more gracefully.
Also replace tab with spaces.
Diffstat (limited to 'slobrok')
-rw-r--r--slobrok/src/vespa/slobrok/sbregister.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/slobrok/src/vespa/slobrok/sbregister.cpp b/slobrok/src/vespa/slobrok/sbregister.cpp
index c930c35f8bb..51ca6b61497 100644
--- a/slobrok/src/vespa/slobrok/sbregister.cpp
+++ b/slobrok/src/vespa/slobrok/sbregister.cpp
@@ -5,11 +5,14 @@
#include <vespa/fnet/frt/target.h>
#include <vespa/vespalib/util/host_name.h>
#include <vespa/vespalib/stllike/asciistream.h>
+#include <vespa/vespalib/util/exceptions.h>
#include <sstream>
#include <vespa/log/log.h>
LOG_SETUP(".slobrok.register");
+using vespalib::IllegalStateException;
+
namespace {
vespalib::string
@@ -47,8 +50,7 @@ discard(std::vector<vespalib::string> &vec, const vespalib::stringref & val)
} // namespace <unnamed>
-namespace slobrok {
-namespace api {
+namespace slobrok::api {
RegisterAPI::RegisterAPI(FRT_Supervisor &orb, const ConfiguratorFactory & config)
: FNET_Task(orb.GetScheduler()),
@@ -69,6 +71,10 @@ RegisterAPI::RegisterAPI(FRT_Supervisor &orb, const ConfiguratorFactory & config
_req(0)
{
_configurator->poll();
+ if ( ! _slobrokSpecs.ok()) {
+ throw IllegalStateException("Failed configuring the RegisterAPI. No valid slobrok specs from config",
+ VESPA_STRLOC);
+ }
LOG_ASSERT(_slobrokSpecs.ok());
ScheduleNow();
}
@@ -127,8 +133,8 @@ RegisterAPI::handleReqDone()
_reqDone = false;
if (_req->IsError()) {
if (_req->GetErrorCode() != FRTE_RPC_METHOD_FAILED) {
- LOG(debug, "register failed: %s (code %d)",
- _req->GetErrorMessage(), _req->GetErrorCode());
+ LOG(debug, "register failed: %s (code %d)",
+ _req->GetErrorMessage(), _req->GetErrorCode());
// unexpected error; close our connection to this
// slobrok server and try again with a fresh slate
if (_target != 0) {
@@ -187,7 +193,7 @@ RegisterAPI::handleReconnect()
LOG(warning, "cannot connect to location broker at %s "
"(retry in %f seconds)", cps.c_str(), delay);
} else {
- LOG(debug, "slobrok retry in %f seconds", delay);
+ LOG(debug, "slobrok retry in %f seconds", delay);
}
return;
}
@@ -220,7 +226,7 @@ RegisterAPI::handlePending()
_req = _orb.AllocRPCRequest();
_req->SetMethodName("slobrok.unregisterRpcServer");
_req->GetParams()->AddString(name.c_str());
- LOG(debug, "unregister [%s]", name.c_str());
+ LOG(debug, "unregister [%s]", name.c_str());
_req->GetParams()->AddString(createSpec(_orb).c_str());
_target->InvokeAsync(_req, 35.0, this);
} else if (reg) {
@@ -228,7 +234,7 @@ RegisterAPI::handlePending()
_req = _orb.AllocRPCRequest();
_req->SetMethodName("slobrok.registerRpcServer");
_req->GetParams()->AddString(name.c_str());
- LOG(debug, "register [%s]", name.c_str());
+ LOG(debug, "register [%s]", name.c_str());
_req->GetParams()->AddString(createSpec(_orb).c_str());
_target->InvokeAsync(_req, 35.0, this);
} else {
@@ -236,7 +242,7 @@ RegisterAPI::handlePending()
// names after a long delay.
_lock.Lock();
_pending = _names;
- LOG(debug, "done, reschedule in 30s");
+ LOG(debug, "done, reschedule in 30s");
_busy = false;
Schedule(30.0);
_lock.Unlock();
@@ -248,7 +254,7 @@ RegisterAPI::PerformTask()
{
handleReqDone();
if (_req != 0) {
- LOG(debug, "req in progress");
+ LOG(debug, "req in progress");
return; // current request still in progress, don't start anything new
}
handleReconnect();
@@ -312,5 +318,4 @@ RegisterAPI::RPCHooks::rpc_notifyUnregistered(FRT_RPCRequest *req)
LOG(warning, "unregistered name %s", args[0]._string._str);
}
-} // namespace api
-} // namespace slobrok
+}