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