SObjectizer  5.8
Loading...
Searching...
No Matches
message_limit.cpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5/*!
6 * \since
7 * v.5.5.4
8 *
9 * \brief Public part of message limit implementation.
10 */
11
12#include <so_5/message_limit.hpp>
13
14#include <so_5/impl/message_limit_action_msg_tracer.hpp>
15#include <so_5/impl/enveloped_msg_details.hpp>
16
17#include <so_5/environment.hpp>
18#include <so_5/enveloped_msg.hpp>
19
20#include <so_5/error_logger.hpp>
21#include <so_5/ret_code.hpp>
22
23
24#include <so_5/details/abort_on_fatal_error.hpp>
25
26#include <sstream>
27
28namespace so_5
29{
30
31namespace message_limit
32{
33
34namespace impl
35{
36
38void
44
46void
48 {
49 so_5::details::abort_on_fatal_error( [&] {
50 if( ctx.m_msg_tracer )
52
53 SO_5_LOG_ERROR( ctx.m_receiver.so_environment().error_logger(), logger )
54 logger
55 << "message limit exceeded, application will be aborted. "
56 << " msg_type: " << ctx.m_msg_type.name()
57 << ", limit: " << ctx.m_limit.m_limit
58 << ", agent: " << &(ctx.m_receiver)
59 << std::endl;
60 } );
61 }
62
64void
66 const overlimit_context_t & ctx,
67 const mbox_t & to )
68 {
70 {
71 // NOTE: this fragment can throw but it isn't a problem
72 // because redirect_reaction() is called during message
73 // delivery process and exceptions are expected in that
74 // process.
76 ctx.m_receiver.so_environment().error_logger(),
77 logger )
78 logger << "maximum message redirection deep exceeded on "
79 "overlimit redirect_reaction; message will be ignored; "
80 << " msg_type: " << ctx.m_msg_type.name()
81 << ", limit: " << ctx.m_limit.m_limit
82 << ", agent: " << &(ctx.m_receiver)
83 << ", target_mbox: " << to->query_name();
84 }
85 else
86 {
87 if( ctx.m_msg_tracer )
89 &ctx.m_receiver,
90 to );
91
92 // Since v.5.8.0 nonblocking delivery mode
93 // has to be used for redirection.
94 // Otherwise the timer thread can be blocked if
95 // the destination is a full mchain.
96 to->do_deliver_message(
97 message_delivery_mode_t::nonblocking,
98 ctx.m_msg_type,
99 ctx.m_message,
100 ctx.m_reaction_deep + 1 );
101 }
102 }
103
105void
107 const overlimit_context_t & ctx,
108 const mbox_t & to,
109 const std::type_index & msg_type,
110 const message_ref_t & message )
111 {
113 {
114 // NOTE: this fragment can throw but it isn't a problem
115 // because transform_reaction() is called during message
116 // delivery process and exceptions are expected in that
117 // process.
119 ctx.m_receiver.so_environment().error_logger(),
120 logger )
121 logger << "maximum message redirection deep exceeded on "
122 "overlimit transform_reaction; message will be ignored;"
123 << " original_msg_type: " << ctx.m_msg_type.name()
124 << ", limit: " << ctx.m_limit.m_limit
125 << ", agent: " << &(ctx.m_receiver)
126 << ", result_msg_type: " << msg_type.name()
127 << ", target_mbox: " << to->query_name();
128 }
129 else
130 {
131 if( ctx.m_msg_tracer )
132 ctx.m_msg_tracer->reaction_transform(
133 &ctx.m_receiver,
134 to,
135 msg_type,
136 message );
137
138 // Since v.5.8.0 nonblocking delivery mode
139 // has to be used for redirection.
140 // Otherwise the timer thread can be blocked if
141 // the destination is a full mchain.
142 to->do_deliver_message(
143 message_delivery_mode_t::nonblocking,
144 msg_type,
145 message,
146 ctx.m_reaction_deep + 1 );
147 }
148 }
149
150} /* namespace impl */
151
152} /* namespace message_limit */
153
154} /* namespace so_5 */
virtual void reaction_redirect_message(const agent_t *subscriber, const mbox_t &target) const noexcept=0
Message will be redirected to another mbox.
virtual void reaction_abort_app(const agent_t *subscriber) const noexcept=0
Application will be aborted as result of overlimit.
virtual void reaction_drop_message(const agent_t *subscriber) const noexcept=0
Message will be dropped as result of overlimit.
#define SO_5_FUNC
Definition declspec.hpp:48
#define SO_5_LOG_ERROR(logger, var_name)
A special macro for helping error logging.
Some reusable and low-level classes/functions which can be used in public header files.
Internal implementation of message limits related stuff.
Definition message.hpp:883
SO_5_FUNC void redirect_reaction(const overlimit_context_t &ctx, const mbox_t &to)
Actual implementation of redirect message reaction.
SO_5_FUNC void abort_app_reaction(const overlimit_context_t &ctx)
Actual implementation of abort application reaction.
SO_5_FUNC void drop_message_reaction(const overlimit_context_t &ctx)
Actual implementation of drop message reaction.
SO_5_FUNC void transform_reaction(const overlimit_context_t &ctx, const mbox_t &to, const std::type_index &msg_type, const message_ref_t &message)
Actual implementation of transform reaction.
All stuff related to message limits.
Definition message.hpp:862
Private part of message limit implementation.
Definition agent.cpp:33
constexpr unsigned int max_redirection_deep
Maximum deep of message redirections.
Description of context for overlimit action.
Definition message.hpp:895
const unsigned int m_reaction_deep
The current deep of overlimit reaction recursion.
Definition message.hpp:916
const agent_t & m_receiver
Receiver of the message (or enveloped message).
Definition message.hpp:910
const impl::action_msg_tracer_t * m_msg_tracer
An optional pointer to tracer object for message delivery tracing.
Definition message.hpp:933