Debian Codegraph @

cpp/include/proton/messaging_handler.hpp

raw
1 #ifndef PROTON_MESSAGING_HANDLER_HPP
2 #define PROTON_MESSAGING_HANDLER_HPP
3
4 /*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25 #include "./fwd.hpp"
26 #include "./internal/export.hpp"
27
28 /// @file
29 /// @copybrief proton::messaging_handler
30
31 namespace proton {
32
33
34 /// Handler for Proton messaging events.
35 ///
36 /// Subclass and override the event-handling member functions.
37 ///
38 /// **Thread-safety**: A thread-safe handler can use the objects
39 /// passed as arguments, and other objects belonging to the same
40 /// proton::connection. It *must not* use objects belonging to a
41 /// different connection. See @ref mt_page and proton::work_queue for
42 /// safe ways to communicate between connections. Thread-safe
43 /// handlers can also be used in single-threaded code.
44 ///
45 /// **Single-threaded only**: An application is single-threaded if it
46 /// calls container::run() exactly once, and only makes make proton
47 /// calls from handler functions. Single-threaded handler functions
48 /// can use objects belonging to another connection, but *must* call
49 /// connection::wake() on the other connection before returning. Such
50 /// a handler is not thread-safe.
51 ///
52 /// ### Overview of connection life-cycle and automatic re-connect
53 ///
54 /// See the documentation of individual event functions for more details.
55 ///
56 /// on_connection_open() - @copybrief on_connection_open()
57 ///
58 /// on_transport_error() -@copybrief on_transport_error()
59 ///
60 /// on_connection_error() - @copybrief on_connection_error()
61 ///
62 /// on_connection_close() - @copybrief on_connection_close()
63 ///
64 /// on_transport_close() - @copybrief on_transport_close()
65 ///
66 /// @see reconnect_options
67 ///
68 class
69 PN_CPP_CLASS_EXTERN messaging_handler {
70 public:
71 PN_CPP_EXTERN messaging_handler();
72 PN_CPP_EXTERN virtual ~messaging_handler();
73
74 /// The container event loop is starting.
75 ///
76 /// This is the first event received after calling
77 /// `container::run()`.
78 PN_CPP_EXTERN virtual void on_container_start(container&);
79
80 /// The container event loop is stopping.
81 ///
82 /// This is the last event received before the container event
83 /// loop stops.
84 PN_CPP_EXTERN virtual void on_container_stop(container&);
85
86 /// A message is received.
87 PN_CPP_EXTERN virtual void on_message(delivery&, message&);
88
89 /// A message can be sent.
90 PN_CPP_EXTERN virtual void on_sendable(sender&);
91
92 /// The underlying network transport is open
93 PN_CPP_EXTERN virtual void on_transport_open(transport&);
94
95 /// The final event for a connection: there will be no more
96 /// reconnect attempts and no more event functions.
97 ///
98 /// Called exactly once regardless of how many times the connection
99 /// was re-connected, whether it failed due to transport or connection
100 /// errors or was closed without error.
101 ///
102 /// This is a good place to do per-connection clean-up.
103 /// transport::connection() is always valid at this point.
104 ///
105 PN_CPP_EXTERN virtual void on_transport_close(transport&);
106
107 /// Unexpected disconnect, transport::error() provides details; if @ref
108 /// reconnect_options are enabled there may be an automatic re-connect.
109 ///
110 /// If there is a successful automatic reconnect, on_connection_open() will
111 /// be called again.
112 ///
113 /// transport::connection() is always valid at this point.
114 ///
115 /// Calling connection::close() will cancel automatic re-connect and force
116 /// the transport to close immediately, see on_transport_close()
117 ///
118 PN_CPP_EXTERN virtual void on_transport_error(transport&);
119
120 /// The remote peer opened the connection: called once on initial open, and
121 /// again on each successful automatic re-connect (see @ref
122 /// reconnect_options)
123 ///
124 /// connection::reconnected() is false for the initial call, true for
125 /// any subsequent calls due to reconnect.
126 ///
127 /// @note You can use the initial call to open initial @ref session, @ref
128 /// sender and @ref receiver endpoints. All active endpoints are *automatically*
129 /// re-opened after an automatic re-connect so you should take care
130 /// not to open them again, for example:
131 ///
132 /// if (!c.reconnected()) {
133 /// // Do initial per-connection setup here.
134 /// // Open initial senders/receivers if needed.
135 /// } else {
136 /// // Handle a successful reconnect here.
137 /// // NOTE: Don't re-open active senders/receivers
138 /// }
139 ///
140 /// For a server on_connection_open() is called when a client attempts to
141 /// open a connection. The server can call connection::open() to accept or
142 /// connection::close(const error_condition&) to reject.
143 ///
144 /// @see reconnect_options, on_transport_error()
145 PN_CPP_EXTERN virtual void on_connection_open(connection&);
146
147 /// The remote peer closed the connection.
148 ///
149 /// If there was a connection error, this is called immediately after
150 /// on_connection_error() and connection::error() is set
151 ///
152 PN_CPP_EXTERN virtual void on_connection_close(connection&);
153
154 /// The remote peer indicated a fatal error, connection::error() provides details.
155 ///
156 /// A connection error is an application problem, for example an illegal
157 /// action or a lack of resources. There will be no automatic re-connect
158 /// attempts, on_connection_close() will be called immediately after.
159 ///
160 /// @note A connection close with the special error condition
161 /// `amqp:connection-forced` is treated as a transport error, not a
162 /// connection error, see on_transport_error()
163 ///
164 PN_CPP_EXTERN virtual void on_connection_error(connection&);
165
166 /// The remote peer opened the session.
167 PN_CPP_EXTERN virtual void on_session_open(session&);
168
169 /// The remote peer closed the session.
170 PN_CPP_EXTERN virtual void on_session_close(session&);
171
172 /// The remote peer closed the session with an error condition.
173 PN_CPP_EXTERN virtual void on_session_error(session&);
174
175 /// The remote peer opened the link.
176 PN_CPP_EXTERN virtual void on_receiver_open(receiver&);
177
178 /// The remote peer detached the link.
179 PN_CPP_EXTERN virtual void on_receiver_detach(receiver&);
180
181 /// The remote peer closed the link.
182 PN_CPP_EXTERN virtual void on_receiver_close(receiver&);
183
184 /// The remote peer closed the link with an error condition.
185 PN_CPP_EXTERN virtual void on_receiver_error(receiver&);
186
187 /// The remote peer opened the link.
188 PN_CPP_EXTERN virtual void on_sender_open(sender&);
189
190 /// The remote peer detached the link.
191 PN_CPP_EXTERN virtual void on_sender_detach(sender&);
192
193 /// The remote peer closed the link.
194 PN_CPP_EXTERN virtual void on_sender_close(sender&);
195
196 /// The remote peer closed the link with an error condition.
197 PN_CPP_EXTERN virtual void on_sender_error(sender&);
198
199 /// The receiving peer accepted a transfer.
200 PN_CPP_EXTERN virtual void on_tracker_accept(tracker&);
201
202 /// The receiving peer rejected a transfer.
203 PN_CPP_EXTERN virtual void on_tracker_reject(tracker&);
204
205 /// The receiving peer released a transfer.
206 PN_CPP_EXTERN virtual void on_tracker_release(tracker&);
207
208 /// The receiving peer settled a transfer.
209 PN_CPP_EXTERN virtual void on_tracker_settle(tracker&);
210
211 /// The sending peer settled a transfer.
212 PN_CPP_EXTERN virtual void on_delivery_settle(delivery&);
213
214 /// **Unsettled API** - The receiving peer has requested a drain of
215 /// remaining credit.
216 PN_CPP_EXTERN virtual void on_sender_drain_start(sender&);
217
218 /// **Unsettled API** - The credit outstanding at the time of the
219 /// drain request has been consumed or returned.
220 PN_CPP_EXTERN virtual void on_receiver_drain_finish(receiver&);
221
222 /// **Unsettled API** - An event that can be triggered from
223 /// another thread.
224 ///
225 /// This event is triggered by a call to `connection::wake()`. It
226 /// is used to notify the application that something needs
227 /// attention.
228 ///
229 /// **Thread-safety** - The application handler and the triggering
230 /// thread must use some form of thread-safe state or
231 /// communication to tell the handler what it needs to do. See
232 /// `proton::work_queue` for an easier way to execute code safely
233 /// in the handler thread.
234 ///
235 /// @note Spurious calls to `on_connection_wake()` can occur
236 /// without any application call to `connection::wake()`.
237 PN_CPP_EXTERN virtual void on_connection_wake(connection&);
238
239 /// Fallback error handling.
240 PN_CPP_EXTERN virtual void on_error(const error_condition&);
241 };
242
243 } // namespace proton
244
245 #endif // PROTON_MESSAGING_HANDLER_HPP