You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2017/12/05 18:34:52 UTC
[1/2] mesos git commit: Separated `Event` visitation and consumption.
Repository: mesos
Updated Branches:
refs/heads/master ececa1159 -> c9462f492
Separated `Event` visitation and consumption.
This introduces the `EventConsumer` interface, which add support of
`Event`s with move-only data. This allows consumers to move data out of
`Event`, rather than copying it. This is required to implement move-only
objects support in `defer` to guarantee that deferred function object is
invoked only once, allowing deferred parameters to be moved into call.
Review: https://reviews.apache.org/r/63631/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6b91f627
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6b91f627
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6b91f627
Branch: refs/heads/master
Commit: 6b91f62769a1f8c525162fc716b1d5c231c77811
Parents: ececa11
Author: Dmitry Zhuk <dz...@twopensource.com>
Authored: Tue Dec 5 10:11:23 2017 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Tue Dec 5 10:31:42 2017 -0800
----------------------------------------------------------------------
3rdparty/libprocess/include/process/event.hpp | 120 ++++++++++++-------
3rdparty/libprocess/include/process/process.hpp | 32 ++---
.../libprocess/include/process/protobuf.hpp | 4 +-
3rdparty/libprocess/include/process/run.hpp | 2 +-
3rdparty/libprocess/src/process.cpp | 22 ++--
3rdparty/libprocess/src/tests/benchmarks.cpp | 10 +-
3rdparty/libprocess/src/tests/process_tests.cpp | 16 ++-
7 files changed, 121 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b91f627/3rdparty/libprocess/include/process/event.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/event.hpp b/3rdparty/libprocess/include/process/event.hpp
index 571ffb1..4b785e3 100644
--- a/3rdparty/libprocess/include/process/event.hpp
+++ b/3rdparty/libprocess/include/process/event.hpp
@@ -46,11 +46,23 @@ struct EventVisitor
};
+struct EventConsumer
+{
+ virtual ~EventConsumer() {}
+ virtual void consume(MessageEvent&&) {}
+ virtual void consume(DispatchEvent&&) {}
+ virtual void consume(HttpEvent&&) {}
+ virtual void consume(ExitedEvent&&) {}
+ virtual void consume(TerminateEvent&&) {}
+};
+
+
struct Event
{
virtual ~Event() {}
virtual void visit(EventVisitor* visitor) const = 0;
+ virtual void consume(EventConsumer* consumer) && = 0;
template <typename T>
bool is() const
@@ -108,22 +120,23 @@ struct MessageEvent : Event
std::string&& data)
: message{std::move(name), from, to, std::move(data)} {}
- MessageEvent(const MessageEvent& that) = default;
MessageEvent(MessageEvent&& that) = default;
-
- // Keep MessageEvent not assignable even though we made it
- // copyable.
- // Note that we are violating the "rule of three" here but it helps
- // keep the fields const.
+ // TODO(dzhuk) Make it movable only, when move is properly supported in defer.
+ MessageEvent(const MessageEvent& that) = default;
+ MessageEvent& operator=(MessageEvent&&) = default;
MessageEvent& operator=(const MessageEvent&) = delete;
- MessageEvent& operator=(MessageEvent&&) = delete;
- virtual void visit(EventVisitor* visitor) const
+ void visit(EventVisitor* visitor) const override
{
visitor->visit(*this);
}
- const Message message;
+ void consume(EventConsumer* consumer) && override
+ {
+ consumer->consume(std::move(*this));
+ }
+
+ Message message;
};
@@ -135,27 +148,31 @@ struct HttpEvent : Event
: request(_request),
response(_response) {}
+ HttpEvent(HttpEvent&&) = default;
+ HttpEvent(const HttpEvent&) = delete;
+ HttpEvent& operator=(HttpEvent&&) = default;
+ HttpEvent& operator=(const HttpEvent&) = delete;
+
virtual ~HttpEvent()
{
- delete request;
-
- // Fail the response in case it wasn't set.
- response->set(http::InternalServerError());
- delete response;
+ if (response) {
+ // Fail the response in case it wasn't set.
+ response->set(http::InternalServerError());
+ }
}
- virtual void visit(EventVisitor* visitor) const
+ void visit(EventVisitor* visitor) const override
{
visitor->visit(*this);
}
- http::Request* const request;
- Promise<http::Response>* response;
+ void consume(EventConsumer* consumer) && override
+ {
+ consumer->consume(std::move(*this));
+ }
-private:
- // Not copyable, not assignable.
- HttpEvent(const HttpEvent&);
- HttpEvent& operator=(const HttpEvent&);
+ std::unique_ptr<http::Request> request;
+ std::unique_ptr<Promise<http::Response>> response;
};
@@ -170,23 +187,28 @@ struct DispatchEvent : Event
functionType(_functionType)
{}
- virtual void visit(EventVisitor* visitor) const
+ DispatchEvent(DispatchEvent&&) = default;
+ DispatchEvent(const DispatchEvent&) = delete;
+ DispatchEvent& operator=(DispatchEvent&&) = default;
+ DispatchEvent& operator=(const DispatchEvent&) = delete;
+
+ void visit(EventVisitor* visitor) const override
{
visitor->visit(*this);
}
+ void consume(EventConsumer* consumer) && override
+ {
+ consumer->consume(std::move(*this));
+ }
+
// PID receiving the dispatch.
- const UPID pid;
+ UPID pid;
// Function to get invoked as a result of this dispatch event.
- const std::shared_ptr<lambda::function<void(ProcessBase*)>> f;
-
- const Option<const std::type_info*> functionType;
+ std::shared_ptr<lambda::function<void(ProcessBase*)>> f;
-private:
- // Not copyable, not assignable.
- DispatchEvent(const DispatchEvent&);
- DispatchEvent& operator=(const DispatchEvent&);
+ Option<const std::type_info*> functionType;
};
@@ -195,18 +217,23 @@ struct ExitedEvent : Event
explicit ExitedEvent(const UPID& _pid)
: pid(_pid) {}
- virtual void visit(EventVisitor* visitor) const
+ ExitedEvent(ExitedEvent&&) = default;
+ // TODO(dzhuk) Make it movable only, when move is properly supported in defer.
+ ExitedEvent(const ExitedEvent&) = default;
+ ExitedEvent& operator=(ExitedEvent&&) = default;
+ ExitedEvent& operator=(const ExitedEvent&) = delete;
+
+ void visit(EventVisitor* visitor) const override
{
visitor->visit(*this);
}
- const UPID pid;
+ void consume(EventConsumer* consumer) && override
+ {
+ consumer->consume(std::move(*this));
+ }
-private:
- // Keep ExitedEvent not assignable even though we made it copyable.
- // Note that we are violating the "rule of three" here but it helps
- // keep the fields const.
- ExitedEvent& operator=(const ExitedEvent&);
+ UPID pid;
};
@@ -215,18 +242,23 @@ struct TerminateEvent : Event
TerminateEvent(const UPID& _from, bool _inject)
: from(_from), inject(_inject) {}
- virtual void visit(EventVisitor* visitor) const
+ TerminateEvent(TerminateEvent&&) = default;
+ TerminateEvent(const TerminateEvent&) = delete;
+ TerminateEvent& operator=(TerminateEvent&&) = default;
+ TerminateEvent& operator=(const TerminateEvent&) = delete;
+
+ void visit(EventVisitor* visitor) const override
{
visitor->visit(*this);
}
- const UPID from;
- const bool inject;
+ void consume(EventConsumer* consumer) && override
+ {
+ consumer->consume(std::move(*this));
+ }
-private:
- // Not copyable, not assignable.
- TerminateEvent(const TerminateEvent&);
- TerminateEvent& operator=(const TerminateEvent&);
+ UPID from;
+ bool inject;
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b91f627/3rdparty/libprocess/include/process/process.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/process.hpp b/3rdparty/libprocess/include/process/process.hpp
index d88c2f2..8b8323f 100644
--- a/3rdparty/libprocess/include/process/process.hpp
+++ b/3rdparty/libprocess/include/process/process.hpp
@@ -69,7 +69,7 @@ void install(std::vector<Owned<FirewallRule>>&& rules);
} // namespace firewall {
-class ProcessBase : public EventVisitor
+class ProcessBase : public EventConsumer
{
public:
explicit ProcessBase(const std::string& id = "");
@@ -82,17 +82,17 @@ protected:
/**
* Invoked when an event is serviced.
*/
- virtual void serve(const Event& event)
+ virtual void serve(Event&& event)
{
- event.visit(this);
+ std::move(event).consume(this);
}
- // Callbacks used to visit (i.e., handle) a specific event.
- virtual void visit(const MessageEvent& event);
- virtual void visit(const DispatchEvent& event);
- virtual void visit(const HttpEvent& event);
- virtual void visit(const ExitedEvent& event);
- virtual void visit(const TerminateEvent& event);
+ // Callbacks used to consume (i.e., handle) a specific event.
+ void consume(MessageEvent&& event) override;
+ void consume(DispatchEvent&& event) override;
+ void consume(HttpEvent&& event) override;
+ void consume(ExitedEvent&& event) override;
+ void consume(TerminateEvent&& event) override;
/**
* Invoked when a process gets spawned.
@@ -103,7 +103,7 @@ protected:
* Invoked when a process is terminated.
*
* **NOTE**: this does not get invoked automatically if
- * `process::ProcessBase::visit(const TerminateEvent&)` is overridden.
+ * `process::ProcessBase::consume(TerminateEvent&&)` is overridden.
*/
virtual void finalize() {}
@@ -200,7 +200,7 @@ protected:
* Any function which takes a "from" `UPID` and a message body as
* arguments.
*
- * The default visit implementation for message events invokes
+ * The default consume implementation for message events invokes
* installed message handlers, or delegates the message to another
* process. A message handler always takes precedence over delegating.
*
@@ -248,7 +248,7 @@ protected:
* Any function which takes a `process::http::Request` and returns a
* `process::http::Response`.
*
- * The default visit implementation for HTTP events invokes
+ * The default consume implementation for HTTP events invokes
* installed HTTP handlers.
*
* @see process::ProcessBase::route
@@ -312,7 +312,7 @@ protected:
* If the principal is not set, then the endpoint's
* realm does not require authentication.
*
- * The default visit implementation for HTTP events invokes
+ * The default consume implementation for HTTP events invokes
* installed HTTP handlers.
*
* @see process::ProcessBase::route
@@ -421,7 +421,7 @@ private:
// (1) `realm` and `authenticatedHandler` will be set.
// Libprocess will perform HTTP authentication for
// all requests to this endpoint (by default during
- // HttpEvent visitation). The authentication principal
+ // HttpEvent consumption). The authentication principal
// will be passed to the `authenticatedHandler`.
//
// Otherwise, if the endpoint is not associated with an
@@ -456,8 +456,8 @@ private:
std::map<std::string, std::string> types;
};
- // Continuation for `visit(const HttpEvent&)`.
- Future<http::Response> _visit(
+ // Continuation for `consume(HttpEvent&&)`.
+ Future<http::Response> _consume(
const HttpEndpoint& endpoint,
const std::string& name,
const Owned<http::Request>& request);
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b91f627/3rdparty/libprocess/include/process/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/protobuf.hpp b/3rdparty/libprocess/include/process/protobuf.hpp
index 08605db..257832e 100644
--- a/3rdparty/libprocess/include/process/protobuf.hpp
+++ b/3rdparty/libprocess/include/process/protobuf.hpp
@@ -93,7 +93,7 @@ public:
virtual ~ProtobufProcess() {}
protected:
- virtual void visit(const process::MessageEvent& event)
+ void consume(process::MessageEvent&& event) override
{
if (protobufHandlers.count(event.message.name) > 0) {
from = event.message.from; // For 'reply'.
@@ -101,7 +101,7 @@ protected:
event.message.from, event.message.body);
from = process::UPID();
} else {
- process::Process<T>::visit(event);
+ process::Process<T>::consume(std::move(event));
}
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b91f627/3rdparty/libprocess/include/process/run.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/run.hpp b/3rdparty/libprocess/include/process/run.hpp
index 46a182b..0d282c9 100644
--- a/3rdparty/libprocess/include/process/run.hpp
+++ b/3rdparty/libprocess/include/process/run.hpp
@@ -38,7 +38,7 @@ public:
virtual ~ThunkProcess() {}
protected:
- virtual void serve(const Event& event)
+ void serve(Event&& event) override
{
promise->set((*thunk)());
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b91f627/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 64bcce2..2b17e25 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -1258,7 +1258,7 @@ void finalize(bool finalize_wsa)
// potentially dereference it.
socket_manager->finalize();
- // This is dereferenced inside `ProcessBase::visit(HttpEvent&)`.
+ // This is dereferenced inside `ProcessBase::consume(HttpEvent&&)`.
// We can safely delete it since no further incoming HTTP connections
// can be made because the server socket has been destroyed. This must
// be deleted before the `ProcessManager` as it will indirectly
@@ -2917,7 +2917,7 @@ void ProcessManager::resume(ProcessBase* process)
// Now service the event.
try {
- process->serve(*event);
+ process->serve(std::move(*event));
} catch (const std::exception& e) {
LOG(ERROR) << "libprocess: " << process->pid
<< " terminating due to " << e.what();
@@ -3476,7 +3476,7 @@ void ProcessBase::send(
}
-void ProcessBase::visit(const MessageEvent& event)
+void ProcessBase::consume(MessageEvent&& event)
{
if (handlers.message.count(event.message.name) > 0) {
handlers.message[event.message.name](
@@ -3492,13 +3492,13 @@ void ProcessBase::visit(const MessageEvent& event)
}
-void ProcessBase::visit(const DispatchEvent& event)
+void ProcessBase::consume(DispatchEvent&& event)
{
- (*event.f)(this);
+ std::move(*event.f)(this);
}
-void ProcessBase::visit(const HttpEvent& event)
+void ProcessBase::consume(HttpEvent&& event)
{
VLOG(1) << "Handling HTTP event for process '" << pid.id << "'"
<< " with path: '" << event.request->url.path << "'";
@@ -3548,10 +3548,10 @@ void ProcessBase::visit(const HttpEvent& event)
response = convert(std::move(request))
.then(defer(self(), [this, endpoint, name](
const Owned<Request>& request) {
- return _visit(endpoint, name, request);
+ return _consume(endpoint, name, request);
}));
} else {
- response = _visit(endpoint, name, request);
+ response = _consume(endpoint, name, request);
}
response
@@ -3609,7 +3609,7 @@ void ProcessBase::visit(const HttpEvent& event)
}
-Future<Response> ProcessBase::_visit(
+Future<Response> ProcessBase::_consume(
const HttpEndpoint& endpoint,
const string& name,
const Owned<Request>& request)
@@ -3687,13 +3687,13 @@ Future<Response> ProcessBase::_visit(
}
-void ProcessBase::visit(const ExitedEvent& event)
+void ProcessBase::consume(ExitedEvent&& event)
{
exited(event.pid);
}
-void ProcessBase::visit(const TerminateEvent& event)
+void ProcessBase::consume(TerminateEvent&& event)
{
finalize();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b91f627/3rdparty/libprocess/src/tests/benchmarks.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/benchmarks.cpp b/3rdparty/libprocess/src/tests/benchmarks.cpp
index 2c6de62..10fd492 100644
--- a/3rdparty/libprocess/src/tests/benchmarks.cpp
+++ b/3rdparty/libprocess/src/tests/benchmarks.cpp
@@ -385,7 +385,7 @@ TEST(ProcessTest, Process_BENCHMARK_LargeNumberOfLinks)
class Destination : public Process<Destination>
{
protected:
- virtual void visit(const MessageEvent& event)
+ void consume(MessageEvent&& event) override
{
if (event.message.name == "ping") {
send(event.message.from, "pong");
@@ -401,7 +401,7 @@ public:
: destination(destination), latch(latch), repeat(repeat) {}
protected:
- virtual void visit(const MessageEvent& event)
+ void consume(MessageEvent&& event) override
{
if (event.message.name == "pong") {
received += 1;
@@ -606,15 +606,15 @@ public:
bool success = message.SerializeToString(&data);
CHECK(success);
- MessageEvent event(self(), self(), message.GetTypeName(), std::move(data));
-
Stopwatch watch;
watch.start();
size_t count;
for (count = 0; watch.elapsed() < Seconds(1); count++) {
- visit(event);
+ MessageEvent event(self(), self(), message.GetTypeName(),
+ data.c_str(), data.length());
+ consume(std::move(event));
}
watch.stop();
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b91f627/3rdparty/libprocess/src/tests/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/process_tests.cpp b/3rdparty/libprocess/src/tests/process_tests.cpp
index d1b30b0..45ddd17 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -714,7 +714,11 @@ TEST(ProcessTest, InjectExited)
class MessageEventProcess : public Process<MessageEventProcess>
{
public:
- MOCK_METHOD1(visit, void(const MessageEvent&));
+ // This is a workaround for mocking methods taking
+ // rvalue reference parameters.
+ // See https://github.com/google/googletest/issues/395
+ void consume(MessageEvent&& event) { consume_(event.message); }
+ MOCK_METHOD1(consume_, void(const Message&));
};
@@ -729,9 +733,9 @@ protected:
MessageEventProcess coordinator;
spawn(coordinator);
- Future<MessageEvent> event;
- EXPECT_CALL(coordinator, visit(_))
- .WillOnce(FutureArg<0>(&event));
+ Future<Message> message;
+ EXPECT_CALL(coordinator, consume_(_))
+ .WillOnce(FutureArg<0>(&message));
Try<Subprocess> s = process::subprocess(
path::join(BUILD_DIR, "test-linkee") +
@@ -740,10 +744,10 @@ protected:
linkee = s.get();
// Wait until the subprocess sends us a message.
- AWAIT_ASSERT_READY(event);
+ AWAIT_ASSERT_READY(message);
// Save the PID of the linkee.
- pid = event->message.from;
+ pid = message->from;
terminate(coordinator);
wait(coordinator);
[2/2] mesos git commit: Migrated to use the `EventConsumer` interface.
Posted by mp...@apache.org.
Migrated to use the `EventConsumer` interface.
Review: https://reviews.apache.org/r/63632/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c9462f49
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c9462f49
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c9462f49
Branch: refs/heads/master
Commit: c9462f4927cfffb1f3a90827467ded730c0f40b9
Parents: 6b91f62
Author: Dmitry Zhuk <dz...@twopensource.com>
Authored: Tue Dec 5 10:11:28 2017 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Tue Dec 5 10:33:19 2017 -0800
----------------------------------------------------------------------
src/common/recordio.hpp | 2 ++
src/master/master.cpp | 34 ++++++++++++++++++++--------------
src/master/master.hpp | 16 ++++++++--------
src/tests/fetcher_cache_tests.cpp | 6 +++---
4 files changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9462f49/src/common/recordio.hpp
----------------------------------------------------------------------
diff --git a/src/common/recordio.hpp b/src/common/recordio.hpp
index 3783634..c58bb14 100644
--- a/src/common/recordio.hpp
+++ b/src/common/recordio.hpp
@@ -213,6 +213,8 @@ private:
}
}
+ using process::Process<ReaderProcess<T>>::consume;
+
void consume()
{
reader.read()
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9462f49/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 31991b5..1fff323 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -1473,7 +1473,7 @@ Future<bool> Master::authorizeLogAccess(const Option<Principal>& principal)
}
-void Master::visit(const MessageEvent& event)
+void Master::consume(MessageEvent&& event)
{
// There are three cases about the message's UPID with respect to
// 'frameworks.principals':
@@ -1547,7 +1547,7 @@ void Master::visit(const MessageEvent& event)
limiter->messages < limiter->capacity.get()) {
limiter->messages++;
limiter->limiter->acquire()
- .onReady(defer(self(), &Self::throttled, event, principal));
+ .onReady(defer(self(), &Self::throttled, std::move(event), principal));
} else {
exceededCapacity(
event,
@@ -1563,7 +1563,7 @@ void Master::visit(const MessageEvent& event)
frameworks.defaultLimiter.get()->capacity.get()) {
frameworks.defaultLimiter.get()->messages++;
frameworks.defaultLimiter.get()->limiter->acquire()
- .onReady(defer(self(), &Self::throttled, event, None()));
+ .onReady(defer(self(), &Self::throttled, std::move(event), None()));
} else {
exceededCapacity(
event,
@@ -1571,14 +1571,14 @@ void Master::visit(const MessageEvent& event)
frameworks.defaultLimiter.get()->capacity.get());
}
} else {
- _visit(event);
+ _consume(std::move(event));
}
}
-void Master::visit(const ExitedEvent& event)
+void Master::consume(ExitedEvent&& event)
{
- // See comments in 'visit(const MessageEvent& event)' for which
+ // See comments in 'consume(MessageEvent&& event)' for which
// RateLimiter is used to throttle this UPID and when it is not
// throttled.
// Note that throttling ExitedEvent is necessary so the order
@@ -1596,15 +1596,15 @@ void Master::visit(const ExitedEvent& event)
frameworks.limiters.contains(principal.get()) &&
frameworks.limiters[principal.get()].isSome()) {
frameworks.limiters[principal.get()].get()->limiter->acquire()
- .onReady(defer(self(), static_cast<F>(&Self::_visit), event));
+ .onReady(defer(self(), static_cast<F>(&Self::_consume), event));
} else if ((principal.isNone() ||
!frameworks.limiters.contains(principal.get())) &&
isRegisteredFramework &&
frameworks.defaultLimiter.isSome()) {
frameworks.defaultLimiter.get()->limiter->acquire()
- .onReady(defer(self(), static_cast<F>(&Self::_visit), event));
+ .onReady(defer(self(), static_cast<F>(&Self::_consume), event));
} else {
- _visit(event);
+ _consume(std::move(event));
}
}
@@ -1625,11 +1625,13 @@ void Master::throttled(
frameworks.defaultLimiter.get()->messages--;
}
- _visit(event);
+ // TODO(dzhuk): Use std::move(event), when defer supports
+ // rvalue references as handler parameters.
+ _consume(event);
}
-void Master::_visit(const MessageEvent& event)
+void Master::_consume(const MessageEvent& event)
{
// Obtain the principal before processing the Message because the
// mapping may be deleted in handling 'UnregisterFrameworkMessage'
@@ -1639,7 +1641,9 @@ void Master::_visit(const MessageEvent& event)
? frameworks.principals[event.message.from]
: Option<string>::none();
- ProtobufProcess<Master>::visit(event);
+ // TODO(dzhuk): Use std::move(event), when defer supports
+ // rvalue references as handler parameters.
+ ProtobufProcess<Master>::consume(MessageEvent(event));
// Increment 'messages_processed' counter if it still exists.
// Note that it could be removed in handling
@@ -1679,9 +1683,11 @@ void Master::exceededCapacity(
}
-void Master::_visit(const ExitedEvent& event)
+void Master::_consume(const ExitedEvent& event)
{
- Process<Master>::visit(event);
+ // TODO(dzhuk): Use std::move(event), when defer supports
+ // rvalue references as handler parameters.
+ Process<Master>::consume(ExitedEvent(event));
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9462f49/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 448be3b..d7fa536 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -551,13 +551,13 @@ public:
}
protected:
- virtual void initialize();
- virtual void finalize();
+ void initialize() override;
+ void finalize() override;
- virtual void visit(const process::MessageEvent& event);
- virtual void visit(const process::ExitedEvent& event);
+ void consume(process::MessageEvent&& event) override;
+ void consume(process::ExitedEvent&& event) override;
- virtual void exited(const process::UPID& pid);
+ void exited(const process::UPID& pid) override;
void exited(const FrameworkID& frameworkId, const HttpConnection& http);
void _exited(Framework* framework);
@@ -575,9 +575,9 @@ protected:
const process::MessageEvent& event,
const Option<std::string>& principal);
- // Continuations of visit().
- void _visit(const process::MessageEvent& event);
- void _visit(const process::ExitedEvent& event);
+ // Continuations of consume().
+ void _consume(const process::MessageEvent& event);
+ void _consume(const process::ExitedEvent& event);
// Helper method invoked when the capacity for a framework
// principal is exceeded.
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9462f49/src/tests/fetcher_cache_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fetcher_cache_tests.cpp b/src/tests/fetcher_cache_tests.cpp
index e2ecb10..7db7b7d 100644
--- a/src/tests/fetcher_cache_tests.cpp
+++ b/src/tests/fetcher_cache_tests.cpp
@@ -960,7 +960,7 @@ public:
return "http://" + stringify(self().address) + "/" + self().id + "/";
}
- // Stalls the execution of future HTTP requests inside visit().
+ // Stalls the execution of future HTTP requests inside consume().
void pause()
{
// If there is no latch or if the existing latch has already been
@@ -977,7 +977,7 @@ public:
}
}
- virtual void visit(const HttpEvent& event)
+ virtual void consume(HttpEvent&& event)
{
if (latch.get() != nullptr) {
latch->await();
@@ -993,7 +993,7 @@ public:
countArchiveRequests++;
}
- ProcessBase::visit(event);
+ ProcessBase::consume(std::move(event));
}
void resetCounts()