2
3
6
7
8
9
10
11
13#include <so_5/impl/subscription_storage_iface.hpp>
25
26
27
28
29
34
35
36
37
38
39
40
41
42
43
44
45
50 std::size_t threshold,
51 subscription_storage_unique_ptr_t small_storage,
52 subscription_storage_unique_ptr_t large_storage );
56 const mbox_t & mbox_ref,
57 const std::type_index & type_index,
60 const event_handler_method_t & method,
67 const std::type_index & msg_type,
68 const state_t & target_state )
noexcept override;
73 const std::type_index & msg_type )
noexcept override;
81 const std::type_index & msg_type,
82 const state_t & current_state )
const noexcept override;
85 debug_dump( std::ostream & to )
const override;
95 subscription_storage_common::subscr_info_vector_t && info )
override;
113 std::size_t threshold,
114 subscription_storage_unique_ptr_t small_storage,
115 subscription_storage_unique_ptr_t large_storage )
120 m_current_storage = m_small_storage.get();
126 const std::type_index & msg_type,
129 const event_handler_method_t & method,
133 if( m_current_storage == m_small_storage.get() &&
134 m_threshold <= m_current_storage->query_subscriptions_count() )
140 m_large_storage->setup_content(
141 m_small_storage->query_content() );
143 m_small_storage->drop_content();
145 m_current_storage = m_large_storage.get();
148 m_current_storage->create_event_subscription(
161 const std::type_index & msg_type,
162 const state_t & target_state )
noexcept
164 m_current_storage->drop_subscription( mbox, msg_type, target_state );
172 const std::type_index & msg_type )
noexcept
174 m_current_storage->drop_subscription_for_all_states( mbox, msg_type );
183 m_current_storage = m_small_storage.get();
189 const std::type_index & msg_type,
190 const state_t & current_state )
const noexcept
192 return m_current_storage->find_handler(
201 m_current_storage->debug_dump( to );
208 m_current_storage = m_small_storage.get();
219 subscription_storage_common::subscr_info_vector_t && info )
221 auto s = info.size() <= m_threshold ?
222 m_small_storage.get() : m_large_storage.get();
224 s->setup_content( std::move( info ) );
226 m_current_storage = s;
238 if( m_current_storage == m_large_storage.get() &&
239 m_threshold >= m_large_storage->query_subscriptions_count() )
246 m_small_storage->setup_content(
247 m_large_storage->query_content() );
249 m_large_storage->drop_content();
251 m_current_storage = m_small_storage.get();
266 return [threshold]() {
267 return impl::subscription_storage_unique_ptr_t(
268 new impl::adaptive_subscr_storage::storage_t(
270 vector_based_subscription_storage_factory( threshold )(),
271 map_based_subscription_storage_factory()() ) );
282 return impl::subscription_storage_unique_ptr_t(
283 new impl::adaptive_subscr_storage::storage_t(
285 small_storage_factory(),
286 large_storage_factory() ) );
293 return adaptive_subscription_storage_factory( 8 );
Interface for message sink.
An adaptive storage for agent's subscriptions information.
virtual void drop_subscription(const mbox_t &mbox, const std::type_index &msg_type, const state_t &target_state) noexcept override
subscription_storage_t * m_current_storage
void setup_content(subscription_storage_common::subscr_info_vector_t &&info) override
Setup content from information from another storage object.
const event_handler_data_t * find_handler(mbox_id_t mbox_id, const std::type_index &msg_type, const state_t ¤t_state) const noexcept override
void drop_all_subscriptions() noexcept override
Drop all subscriptions.
const std::size_t m_threshold
void drop_content() noexcept override
Drop all content.
std::size_t query_subscriptions_count() const override
Count of subscriptions in the storage.
storage_t(std::size_t threshold, subscription_storage_unique_ptr_t small_storage, subscription_storage_unique_ptr_t large_storage)
virtual void create_event_subscription(const mbox_t &mbox_ref, const std::type_index &type_index, abstract_message_sink_t &message_sink, const state_t &target_state, const event_handler_method_t &method, thread_safety_t thread_safety, event_handler_kind_t handler_kind) override
subscription_storage_unique_ptr_t m_small_storage
void drop_subscription_for_all_states(const mbox_t &mbox, const std::type_index &msg_type) noexcept override
subscription_storage_unique_ptr_t m_large_storage
void try_switch_to_smaller_storage() noexcept
void debug_dump(std::ostream &to) const override
subscription_storage_common::subscr_info_vector_t query_content() const override
An interface of subscription storage.
virtual void drop_content() noexcept=0
Drop all content.
virtual void drop_all_subscriptions() noexcept=0
Drop all subscriptions.
std::enable_if< details::is_agent_method_pointer< details::method_arity::nullary, Method_Pointer >::value, state_t & >::type on_enter(Method_Pointer pfn)
Set on enter handler.
An adaptive storage for agent's subscriptions information.
Details of SObjectizer run-time implementations.
Private part of message limit implementation.
SO_5_FUNC subscription_storage_factory_t default_subscription_storage_factory()
Factory for default subscription storage object.
thread_safety_t
Thread safety indicator.
SO_5_FUNC subscription_storage_factory_t adaptive_subscription_storage_factory(std::size_t threshold, const subscription_storage_factory_t &small_storage_factory, const subscription_storage_factory_t &large_storage_factory)
Factory for adaptive subscription storage.
SO_5_FUNC subscription_storage_factory_t adaptive_subscription_storage_factory(std::size_t threshold)
Factory for adaptive subscription storage.
event_handler_kind_t
Kind of an event handler.
Information about event_handler and its properties.