MySQL 9.1.0
Source Code Documentation
gcs_communication_interface.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef GCS_COMMUNICATION_INTERFACE_INCLUDED
25#define GCS_COMMUNICATION_INTERFACE_INCLUDED
26
27#include <future>
28#include <utility> // std::pair
32
34
35/**
36 @class Gcs_communication_interface
37
38 This interface represents all the communication facilities that a binding
39 implementation should provide. Like all interfaces in this API, it is
40 group-oriented, meaning that a single instance shall exist per group,
41 as it was returned by the class Gcs_interface::get_communication_session.
42
43 It has two major subsections:
44 - Message sending: represented by the method send_message, it will
45 broadcast a message to the group in which this interface is bound.
46 All message data is encapsulated in the Gcs_message object that
47 contains more detail about the information to be sent.
48 Guarantees are bound to the binding implementation. This means that the
49 implementation shall send message of this message and shall not be
50 maintained between different groups.
51
52 - Message receiving: Due to the asynchronous nature of this interface,
53 message reception is done via an event. They shall be delivered in
54 form of callbacks defined in Gcs_communication_event_listener class,
55 that should be implemented by a client of this interface interested
56 in receiving those notifications.
57
58 A typical usage for this interface would be:
59
60 @code{.cpp}
61 class my_Gcs_communication_event_listener: Gcs_communication_event_listener
62 {
63 void on_message_received(const Gcs_message &message)
64 {
65 //Do something when message arrives...
66 }
67 }
68
69 //meanwhile in your client code...
70 Gcs_communication_interface *gcs_comm_interface_instance; // obtained
71 // previously
72
73 Gcs_communication_event_listener listener_instance;
74
75 int ref_handler=
76 gcs_comm_interface_instance->add_event_listener(listener_instance);
77
78 Gcs_message *msg= new Gcs_message(<message_params>);
79
80 gcs_comm_interface_instance->send_message(msg);
81
82 //Normal program flow...
83
84 //In the end...
85 gcs_comm_interface_instance->remove_event_listener(ref_handler);
86
87 @endcode
88
89*/
91 public:
92 /**
93 Method used to broadcast a message to a group in which this interface
94 pertains.
95
96 Note that one must belong to an active group to send messages.
97
98 @param[in] message_to_send the Gcs_message object to send
99 @return A gcs_error value
100 @retval GCS_OK When message is transmitted successfully
101 @retval GCS_ERROR When error occurred while transmitting message
102 @retval GCS_MESSAGE_TOO_BIG When message is bigger than
103 the GCS can handle
104 */
105
106 virtual enum_gcs_error send_message(const Gcs_message &message_to_send) = 0;
107
108 /**
109 Registers an implementation of a Gcs_communication_event_listener that will
110 receive Communication Events.
111
112 Note that a binding implementation shall not offer the possibility of
113 changing listeners while the system is up and running. In that sense,
114 listeners must be added to it only when booting up the system.
115
116 @param[in] event_listener a class that implements
117 Gcs_communication_event_listener
118 @return an handle representing the registration of this object to
119 be used in remove_event_listener
120 */
121
123 const Gcs_communication_event_listener &event_listener) = 0;
124
125 /**
126 Removes a previously registered event listener.
127
128 Note that a binding implementation shall not offer the possibility of
129 changing listeners while the system is up and running. In that sense
130 listeners must be removed from it only when shutting down the system.
131
132 @param[in] event_listener_handle the handle returned when the listener was
133 registered
134 */
135
136 virtual void remove_event_listener(int event_listener_handle) = 0;
137
138 /**
139 Retrieves the current GCS protocol version in use.
140 */
142
143 /**
144 * Modifies the GCS protocol version in use.
145 *
146 * The method is non-blocking. It returns a future on which the caller can
147 * wait for the action to finish.
148 *
149 * This method has the following requirements:
150 * - It must be called by all group members at the same logical instant, i.e.
151 * it is part of the replicated state machine.
152 * - It must not be called concurrently, i.e. a new protocol change may only
153 * begin after the previous one has finished.
154 *
155 * A GCS client must ensure the requirements are met.
156 * In the case of Group Replication, these requirements are ensured by
157 * initiating a GCS protocol change as part of a GR group action.
158 *
159 * @param new_version The desired GCS protocol version
160 *
161 * @retval {true, future} If successful
162 * @retval {false, _} If unsuccessful because @c new_version is unsupported
163 */
164 virtual std::pair<bool, std::future<void>> set_protocol_version(
165 Gcs_protocol_version new_version) = 0;
166
167 /**
168 * Get the maximum protocol version currently supported by the group.
169 *
170 * @returns the maximum protocol version currently supported by the group
171 */
173 const = 0;
174
175 /**
176 * @brief Sets the communication protocol to use
177 *
178 * @param protocol the protocol to use
179 */
181
182 /**
183 * @brief Get the incoming connections protocol which is currently active
184 *
185 * @return GcsRunningProtocol
186 */
188
189 virtual ~Gcs_communication_interface() = default;
190};
191
192#endif // GCS_COMMUNICATION_INTERFACE_H
This interface is implemented by those who wish to receive messages.
Definition: gcs_communication_event_listener.h:36
This interface represents all the communication facilities that a binding implementation should provi...
Definition: gcs_communication_interface.h:90
virtual int add_event_listener(const Gcs_communication_event_listener &event_listener)=0
Registers an implementation of a Gcs_communication_event_listener that will receive Communication Eve...
virtual enum_transport_protocol get_incoming_connections_protocol()=0
Get the incoming connections protocol which is currently active.
virtual enum_gcs_error send_message(const Gcs_message &message_to_send)=0
Method used to broadcast a message to a group in which this interface pertains.
virtual Gcs_protocol_version get_protocol_version() const =0
Retrieves the current GCS protocol version in use.
virtual void set_communication_protocol(enum_transport_protocol protocol)=0
Sets the communication protocol to use.
virtual Gcs_protocol_version get_maximum_supported_protocol_version() const =0
Get the maximum protocol version currently supported by the group.
virtual ~Gcs_communication_interface()=default
virtual void remove_event_listener(int event_listener_handle)=0
Removes a previously registered event listener.
virtual std::pair< bool, std::future< void > > set_protocol_version(Gcs_protocol_version new_version)=0
Modifies the GCS protocol version in use.
Class that represents the data that is exchanged within a group.
Definition: gcs_message.h:357
enum_gcs_error
This enumeration describes errors which can occur during group communication operations.
Definition: gcs_types.h:41
Gcs_protocol_version
The GCS protocol versions.
Definition: gcs_types.h:128
enum_transport_protocol
Enum that describes the available XCom Communication Stacks.
Definition: network_provider.h:45