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
9#include <functional>
10
11namespace DataStorm
12{
13 template<typename, typename, typename> class Topic;
14
15 /// The exception that is thrown when a blocking operation is interrupted by the shutdown of the node.
16 /// @headerfile DataStorm/DataStorm.h
17 class DATASTORM_API NodeShutdownException final : public std::exception
18 {
19 public:
20 /// Gets the error message of this exception.
21 /// @return The error message.
22 [[nodiscard]] const char* what() const noexcept final;
23 };
24
25 /// Options to configure a DataStorm node.
26 /// @headerfile DataStorm/DataStorm.h
28 {
29 /// The Ice communicator used by the node. If nullptr, the node creates its own communicator.
31
32 /// Specifies whether or not the node owns the communicator.
33 /// This option is only meaningful when the communicator field is not nullptr. If true, the node's destructor
34 /// destroys the communicator. The default value is false.
36
37 /// An optional executor used to execute user callbacks.
38 /// If no callback executor is set, the node will use the default callback executor that executes callbacks
39 /// in a dedicated thread.
40 std::function<void(std::function<void()> call)> customExecutor{};
41
42 /// The server authentication options used for SSL connections.
43 /// When provided, these options are used to initialize the DataStorm.Node.Server object adapter.
44 std::optional<Ice::SSL::ServerAuthenticationOptions> serverAuthenticationOptions{std::nullopt};
45 };
46
47 /// The Node class allows creating topic readers and writers.
48 /// A node is the main DataStorm object which allows creating topic readers or writers.
49 /// @headerfile DataStorm/DataStorm.h
50 class DATASTORM_API Node
51 {
52 public:
53 /// Constructs a DataStorm node.
54 /// A node is the main DataStorm object. It is required to construct topics.
55 /// @param options The options to configure the node.
56 /// @remark This is the main Node constructor. All other constructors are convenience constructors that call
57 /// this constructor.
58 explicit Node(NodeOptions options = {});
59
60 /// Constructs a DataStorm node with the specified communicator.
61 /// A node is the main DataStorm object. It is required to construct topics.
62 /// @param communicator The communicator used by the node. If nullptr, the node creates its own communicator.
63 /// @remark This constructor sets the nodeOwnsCommunicator option to false.
64 explicit Node(Ice::CommunicatorPtr communicator);
65
66 /// Constructs a DataStorm node with an Ice communicator initialized from command-line arguments.
67 /// A node is the main DataStorm object. It is required to construct topics.
68 /// @tparam ArgvT The type of the argument vector, such as char**, const char**, or wchar_t** (on Windows).
69 /// @param argc The number of arguments in argv.
70 /// @param argv The command-line arguments.
71 template<typename ArgvT> Node(int& argc, ArgvT argv) : Node{createNodeOptions(argc, argv)} {}
72
73 /// Move constructor.
74 /// @param node The node to move from.
75 Node(Node&& node) noexcept;
76
77 /// Destructor.
78 /// The node destruction releases associated resources. If the node created the Ice communicator, the
79 /// communicator is destroyed.
81
82 /// Shuts down the node. The shutdown interrupts calls which are waiting for events, writers or readers.
83 void shutdown() noexcept;
84
85 /// Returns whether or not the node shutdown has been initiated.
86 /// @return `true` if the node is shutdown, `false` otherwise.
87 [[nodiscard]] bool isShutdown() const noexcept;
88
89 /// Waits for shutdown to be called.
90 void waitForShutdown() const noexcept;
91
92 /// Move assignment operator.
93 /// @param node The node to move from.
94 /// @return A reference to this node.
95 Node& operator=(Node&& node) noexcept;
96
97 /// Returns the Ice communicator associated with the node.
98 [[nodiscard]] Ice::CommunicatorPtr getCommunicator() const noexcept;
99
100 /// Returns the Ice connection associated with a session given a session identifier. Session identifiers are
101 /// provided with the sample origin data member as the first tuple element.
102 /// @param ident The session identifier.
103 /// @return The connection associated with the given session
104 /// @see DataStorm::Sample::ElementId DataStorm::Sample::getSession
105 [[nodiscard]] Ice::ConnectionPtr getSessionConnection(std::string_view ident) const noexcept;
106
107 private:
108 template<typename ArgvT> NodeOptions createNodeOptions(int& argc, ArgvT argv)
109 {
110 NodeOptions options;
111 options.communicator = Ice::initialize(argc, argv);
112 options.nodeOwnsCommunicator = true;
113 return options;
114 }
115
116 std::shared_ptr<DataStormI::Instance> _instance;
117 std::shared_ptr<DataStormI::TopicFactory> _factory;
118 bool _ownsCommunicator{false};
119
120 template<typename, typename, typename> friend class Topic;
121 };
122}
123#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:18
Node(Ice::CommunicatorPtr communicator)
Constructs a DataStorm node with the specified communicator.
Ice::CommunicatorPtr getCommunicator() const noexcept
Returns the Ice communicator associated with the 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.
bool isShutdown() const noexcept
Returns whether or not the node shutdown has been initiated.
~Node()
Destructor.
Node(NodeOptions options={})
Constructs a DataStorm node.
Node(int &argc, ArgvT argv)
Constructs a DataStorm node with an Ice communicator initialized from command-line arguments.
Definition Node.h:71
void waitForShutdown() const noexcept
Waits for shutdown to be called.
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.
CommunicatorPtr initialize(InitializationData initData={})
Creates a new communicator.
The Ice RPC framework.
Definition SampleEvent.h:59
bool nodeOwnsCommunicator
Specifies whether or not the node owns the communicator.
Definition Node.h:35
Ice::CommunicatorPtr communicator
The Ice communicator used by the node. If nullptr, the node creates its own communicator.
Definition Node.h:30
std::function< void(std::function< void()> call)> customExecutor
An optional executor used to execute user callbacks.
Definition Node.h:40
std::optional< Ice::SSL::ServerAuthenticationOptions > serverAuthenticationOptions
The server authentication options used for SSL connections.
Definition Node.h:44
Options to configure a DataStorm node.
Definition Node.h:28