Commit 401c48ff authored by Dominik Charousset's avatar Dominik Charousset

Remove raw_event_based_actor

This weird actor types originally was meant to simplify writing
system-level actors. However, CAF used it once in a single unit test.
It's safe to say that maintaining this actor type is not worth the
effort.
parent 7283c0d3
......@@ -124,7 +124,6 @@ set(CAF_CORE_SOURCES
src/policy/work_stealing.cpp
src/proxy_registry.cpp
src/raise_error.cpp
src/raw_event_based_actor.cpp
src/ref_counted.cpp
src/replies_to.cpp
src/response_promise.cpp
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/detail/core_export.hpp"
#include "caf/event_based_actor.hpp"
namespace caf {
/// A cooperatively raw scheduled actor is a dynamically typed actor that does
/// not handle any system messages. All handler for system messages as well as
/// the default handler are ignored. This actor type is for testing and
/// system-level actors.
/// @extends event_based_actor
class CAF_CORE_EXPORT raw_event_based_actor : public event_based_actor {
public:
// -- member types -----------------------------------------------------------
/// Required by `spawn` for type deduction.
using signatures = none_t;
/// Required by `spawn` for type deduction.
using behavior_type = behavior;
// -- constructors and destructors -------------------------------------------
explicit raw_event_based_actor(actor_config& cfg);
invoke_message_result consume(mailbox_element& x) override;
};
} // namespace caf
......@@ -441,7 +441,7 @@ public:
message_category categorize(mailbox_element& x);
/// Tries to consume `x`.
virtual invoke_message_result consume(mailbox_element& x);
invoke_message_result consume(mailbox_element& x);
/// Tries to consume `x`.
void consume(mailbox_element_ptr x);
......
......@@ -28,7 +28,6 @@
#include "caf/policy/work_sharing.hpp"
#include "caf/policy/work_stealing.hpp"
#include "caf/raise_error.hpp"
#include "caf/raw_event_based_actor.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/scheduler/coordinator.hpp"
#include "caf/scheduler/test_coordinator.hpp"
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/raw_event_based_actor.hpp"
#include "caf/detail/default_invoke_result_visitor.hpp"
namespace caf {
raw_event_based_actor::raw_event_based_actor(actor_config& cfg)
: event_based_actor(cfg) {
// nop
}
invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
CAF_LOG_TRACE(CAF_ARG(x));
current_element_ = &x;
CAF_LOG_RECEIVE_EVENT(current_element_);
CAF_BEFORE_PROCESSING(this, x);
// Wrap the actual body for the function.
auto body = [this, &x] {
// short-circuit awaited responses
if (!awaited_responses_.empty()) {
auto& pr = awaited_responses_.front();
// skip all messages until we receive the currently awaited response
if (x.mid != pr.first)
return invoke_message_result::skipped;
if (!pr.second(x.content())) {
// try again with error if first attempt failed
auto msg = make_message(
make_error(sec::unexpected_response, std::move(x.payload)));
pr.second(msg);
}
awaited_responses_.pop_front();
return invoke_message_result::consumed;
}
// handle multiplexed responses
if (x.mid.is_response()) {
auto mrh = multiplexed_responses_.find(x.mid);
// neither awaited nor multiplexed, probably an expired timeout
if (mrh == multiplexed_responses_.end())
return invoke_message_result::dropped;
if (!mrh->second(x.content())) {
// try again with error if first attempt failed
auto msg = make_message(
make_error(sec::unexpected_response, std::move(x.payload)));
mrh->second(msg);
}
multiplexed_responses_.erase(mrh);
return invoke_message_result::consumed;
}
auto& content = x.content();
// handle timeout messages
if (content.match_elements<timeout_msg>()) {
auto& tm = content.get_as<timeout_msg>(0);
auto tid = tm.timeout_id;
CAF_ASSERT(x.mid.is_async());
if (is_active_receive_timeout(tid)) {
CAF_LOG_DEBUG("handle timeout message");
if (bhvr_stack_.empty())
return invoke_message_result::dropped;
bhvr_stack_.back().handle_timeout();
return invoke_message_result::consumed;
}
CAF_LOG_DEBUG("dropped expired timeout message");
return invoke_message_result::dropped;
}
// handle everything else as ordinary message
detail::default_invoke_result_visitor<event_based_actor> visitor{this};
auto had_timeout = getf(has_timeout_flag);
if (had_timeout)
unsetf(has_timeout_flag);
if (!bhvr_stack_.empty()) {
auto& bhvr = bhvr_stack_.back();
if (bhvr(visitor, x.content()))
return invoke_message_result::consumed;
}
auto sres = call_handler(default_handler_, this, x.payload);
auto f = detail::make_overload(
[&](auto& x) {
visitor(x);
return invoke_message_result::consumed;
},
[&](skip_t& x) {
// Restore timeout if message was skipped.
if (had_timeout)
setf(has_timeout_flag);
return invoke_message_result::skipped;
});
return visit(f, sres);
};
// Post-process the returned value from the function body.
auto result = body();
CAF_AFTER_PROCESSING(this, result);
CAF_LOG_SKIP_OR_FINALIZE_EVENT(result);
return result;
}
} // namespace caf
......@@ -580,10 +580,11 @@ scheduled_actor::categorize(mailbox_element& x) {
CAF_LOG_DEBUG("handle ordinary timeout message");
if (is_active_receive_timeout(tid) && !bhvr_stack_.empty())
bhvr_stack_.back().handle_timeout();
} else {
CAF_ASSERT(tm.type == "stream");
} else if (tm.type == "stream") {
CAF_LOG_DEBUG("handle stream timeout message");
set_stream_timeout(advance_streams(clock().now()));
} else {
// Drop. Other types not supported yet.
}
return message_category::internal;
}
......
......@@ -27,7 +27,6 @@
#include "caf/all.hpp"
#include "caf/detail/test_actor_clock.hpp"
#include "caf/raw_event_based_actor.hpp"
using namespace caf;
......@@ -39,8 +38,10 @@ struct testee_state {
uint64_t timeout_id = 41;
};
behavior testee(stateful_actor<testee_state, raw_event_based_actor>* self,
behavior testee(stateful_actor<testee_state>* self,
detail::test_actor_clock* t) {
self->set_exit_handler([self](exit_msg& x) { self->quit(x.reason); });
self->set_error_handler([](scheduled_actor*, error&) {});
return {
[=](ok_atom) {
CAF_LOG_TRACE("" << self->current_mailbox_element()->content());
......@@ -61,17 +62,11 @@ behavior testee(stateful_actor<testee_state, raw_event_based_actor>* self,
auto mid = make_message_id(self->state.timeout_id).response_id();
t->set_request_timeout(n, self, mid);
},
[](const timeout_msg&) { CAF_LOG_TRACE(""); },
[](const error&) { CAF_LOG_TRACE(""); },
[](const std::string&) { CAF_LOG_TRACE(""); },
[=](group& grp) {
CAF_LOG_TRACE("");
self->join(grp);
},
[=](exit_msg& x) {
CAF_LOG_TRACE("");
self->quit(x.reason);
},
};
}
......
......@@ -49,7 +49,6 @@
#include "caf/logger.hpp"
#include "caf/make_counted.hpp"
#include "caf/node_id.hpp"
#include "caf/raw_event_based_actor.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/sec.hpp"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment