Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
Node.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef DATASTORM_NODE_H
4#define DATASTORM_NODE_H
5
6#include "Config.h"
7#include "InternalI.h"
8
9namespace DataStorm
10{
11 template<typename, typename, typename> class Topic;
12
13 /// The exception that is thrown when a blocking operation is interrupted by the shutdown of the node.
14 /// @headerfile DataStorm/DataStorm.h
15 class DATASTORM_API NodeShutdownException final : public std::exception
16 {
17 public:
18 /// Gets the error message of this exception.
19 /// @return The error message.
20 [[nodiscard]] const char* what() const noexcept final;
21 };
22
23 /// The Node class allows creating topic readers and writers.
24 /// A Node is the main DataStorm object which allows creating topic readers or writers.
25 /// @headerfile DataStorm/DataStorm.h
26 class DATASTORM_API Node
27 {
28 public:
29 /// Constructs a DataStorm node.
30 /// A node is the main DataStorm object. It is required to construct topics.
31 /// @param argc The number of arguments in argv.
32 /// @param argv The configuration arguments.
33 /// @param configFile The path to an optional Ice configuration file.
34 /// @param customExecutor An optional executor used to execute user callbacks, if no callback executor is
35 /// provided the Node will use the default callback executor that executes callback in a dedicated thread.
37 int& argc,
38 const char* argv[],
39 std::optional<std::string_view> configFile = std::nullopt,
40 std::function<void(std::function<void()> call)> customExecutor = nullptr);
41
42 /// Constructs a DataStorm node.
43 /// A node is the main DataStorm object. It is required to construct topics.
44 /// @param argc The number of arguments in argv.
45 /// @param argv The configuration arguments.
46 /// @param configFile The path to an optional Ice configuration file.
47 /// @param customExecutor An optional executor used to execute user callbacks, if no callback executor is
48 /// provided the Node will use the default callback executor that executes callback in a dedicated thread.
50 int& argc,
51 char* argv[],
52 std::optional<std::string_view> configFile = std::nullopt,
53 std::function<void(std::function<void()> call)> customExecutor = nullptr)
54 : Node(argc, const_cast<const char**>(argv), configFile, std::move(customExecutor))
55 {
56 }
57
58#if defined(_WIN32) || defined(ICE_DOXYGEN)
59 /// Constructs a DataStorm node.
60 /// A node is the main DataStorm object. It is required to construct topics.
61 /// @param argc The number of arguments in argv.
62 /// @param argv The configuration arguments.
63 /// @param configFile The path to an optional Ice configuration file.
64 /// @param customExecutor An optional executor used to execute user callbacks, if no callback executor is
65 /// provided the Node will use the default callback executor that executes callback in a dedicated thread.
66 /// @remark Windows only.
68 int& argc,
69 const wchar_t* argv[],
70 std::optional<std::string_view> configFile = std::nullopt,
71 std::function<void(std::function<void()> call)> customExecutor = nullptr);
72
73 /// Constructs a DataStorm node.
74 /// A node is the main DataStorm object. It is required to construct topics.
75 /// @param argc The number of arguments in argv.
76 /// @param argv The configuration arguments.
77 /// @param configFile The path to an optional Ice configuration file.
78 /// @param customExecutor An optional executor used to execute user callbacks, if no callback executor is
79 /// provided the Node will use the default callback executor that executes callback in a dedicated thread.
80 /// @remark Windows only.
82 int& argc,
83 wchar_t* argv[],
84 std::optional<std::string_view> configFile = std::nullopt,
85 std::function<void(std::function<void()> call)> customExecutor = nullptr)
86 : Node(argc, const_cast<const wchar_t**>(argv), configFile, customExecutor)
87 {
88 }
89#endif
90
91 /// Constructs a DataStorm node.
92 /// A node is the main DataStorm object. It is required to construct topics.
93 /// @param configFile The path to an optional Ice configuration file.
94 /// @param customExecutor An optional executor used to execute user callbacks, if no callback executor is
95 /// provided the Node will use the default callback executor that executes callback in a dedicated thread.
97 std::optional<std::string_view> configFile = std::nullopt,
98 std::function<void(std::function<void()> call)> customExecutor = nullptr);
99
100 /// Constructs a DataStorm node.
101 /// A node is the main DataStorm object. It is required to construct topics. The node uses the given Ice
102 /// communicator.
103 /// @param communicator The Ice communicator used by the topic factory for its configuration and communications.
104 /// This communicator must be initialized with a property set to use the "DataStorm" opt-in prefix.
105 /// @param customExecutor An optional executor used to execute user callbacks, if no callback executor is
106 /// provided the Node will use the default callback executor that executes callback in a dedicated thread.
108 Ice::CommunicatorPtr communicator,
109 std::function<void(std::function<void()> call)> customExecutor = nullptr);
110
111 /// Move constructor.
112 /// @param node The node to move from.
113 Node(Node&& node) noexcept;
114
115 /// Destructor.
116 /// The node destruction releases associated resources. If the node created the Ice communicator, the
117 /// communicator is destroyed.
119
120 /// Shuts down the node. The shutdown interrupts calls which are waiting for events, writers or readers.
121 void shutdown() noexcept;
122
123 /// Returns whether or not the node shutdown has been initiated.
124 /// @return `true` if the node is shutdown, `false` otherwise.
125 [[nodiscard]] bool isShutdown() const noexcept;
126
127 /// Waits for shutdown to be called.
128 void waitForShutdown() const noexcept;
129
130 /// Move assignment operator.
131 /// @param node The node to move from.
132 /// @return A reference to this node.
133 Node& operator=(Node&& node) noexcept;
134
135 /// Returns the Ice communicator associated with the node.
136 [[nodiscard]] Ice::CommunicatorPtr getCommunicator() const noexcept;
137
138 /// Returns the Ice connection associated with a session given a session identifier. Session identifiers are
139 /// provided with the sample origin data member as the first tuple element.
140 /// @param ident The session identifier.
141 /// @return The connection associated with the given session
142 /// @see DataStorm::Sample::ElementId DataStorm::Sample::getSession
143 [[nodiscard]] Ice::ConnectionPtr getSessionConnection(std::string_view ident) const noexcept;
144
145 private:
146 Node(
147 Ice::CommunicatorPtr,
148 std::function<void(std::function<void()> call)> customExecutor,
149 bool ownsCommunicator);
150
151 std::shared_ptr<DataStormI::Instance> _instance;
152 std::shared_ptr<DataStormI::TopicFactory> _factory;
153 bool _ownsCommunicator;
154
155 template<typename, typename, typename> friend class Topic;
156 };
157}
158#endif
const char * what() const noexcept final
Gets the error message of this exception.
The exception that is thrown when a blocking operation is interrupted by the shutdown of the node.
Definition Node.h:16
Ice::CommunicatorPtr getCommunicator() const noexcept
Returns the Ice communicator associated with the node.
Node(Ice::CommunicatorPtr communicator, std::function< void(std::function< void()> call)> customExecutor=nullptr)
Constructs a DataStorm node.
void shutdown() noexcept
Shuts down the node. The shutdown interrupts calls which are waiting for events, writers or readers.
Node(Node &&node) noexcept
Move constructor.
Ice::ConnectionPtr getSessionConnection(std::string_view ident) const noexcept
Returns the Ice connection associated with a session given a session identifier.
Node(int &argc, char *argv[], std::optional< std::string_view > configFile=std::nullopt, std::function< void(std::function< void()> call)> customExecutor=nullptr)
Constructs a DataStorm node.
Definition Node.h:49
bool isShutdown() const noexcept
Returns whether or not the node shutdown has been initiated.
~Node()
Destructor.
void waitForShutdown() const noexcept
Waits for shutdown to be called.
Node(int &argc, const char *argv[], std::optional< std::string_view > configFile=std::nullopt, std::function< void(std::function< void()> call)> customExecutor=nullptr)
Constructs a DataStorm node.
Node(int &argc, wchar_t *argv[], std::optional< std::string_view > configFile=std::nullopt, std::function< void(std::function< void()> call)> customExecutor=nullptr)
Constructs a DataStorm node.
Definition Node.h:81
Node(std::optional< std::string_view > configFile=std::nullopt, std::function< void(std::function< void()> call)> customExecutor=nullptr)
Constructs a DataStorm node.
Node(int &argc, const wchar_t *argv[], std::optional< std::string_view > configFile=std::nullopt, std::function< void(std::function< void()> call)> customExecutor=nullptr)
Constructs a DataStorm node.
The Topic class.
Definition DataStorm.h:295
Data-centric, broker-less publish/subscribe framework. C++ only.
Definition DataStorm.h:24
std::shared_ptr< Communicator > CommunicatorPtr
A shared pointer to a Communicator.
The Ice RPC framework.
Definition SampleEvent.h:59