Ice 3.9
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.
30 /// @remark A DataStorm node requires the requests it receives on a connection to be dispatched in the order
31 /// they were sent; a partial update is applied to the value left by the preceding sample. A node configures
32 /// the communicators it creates accordingly, but it does not change the configuration of a communicator
33 /// supplied here. Such a communicator must set `Ice.ThreadPool.Client.Serialize` to 1 before it is created.
34 /// An executor set through Ice::InitializationData must likewise preserve the dispatch order.
36
37 /// Specifies whether or not the node owns the communicator.
38 /// This option is only meaningful when the communicator field is not nullptr. If true, the node's destructor
39 /// destroys the communicator. The default value is false.
41
42 /// An optional executor used to execute user callbacks.
43 /// If no callback executor is set, the node will use the default callback executor that executes callbacks
44 /// in a dedicated thread.
45 std::function<void(std::function<void()> call)> customExecutor{};
46
47 /// The server authentication options used for SSL connections.
48 /// When provided, these options are used to initialize the DataStorm.Node.Server object adapter.
49 std::optional<Ice::SSL::ServerAuthenticationOptions> serverAuthenticationOptions{std::nullopt};
50 };
51
52 /// The Node class allows creating topic readers and writers.
53 /// A node is the main DataStorm object which allows creating topic readers or writers.
54 /// @headerfile DataStorm/DataStorm.h
55 class DATASTORM_API Node
56 {
57 public:
58 /// Constructs a DataStorm node.
59 /// A node is the main DataStorm object. It is required to construct topics.
60 /// @param options The options to configure the node.
61 /// @remark This is the main Node constructor. All other constructors are convenience constructors that call
62 /// this constructor.
63 explicit Node(NodeOptions options = {});
64
65 /// Constructs a DataStorm node with the specified communicator.
66 /// A node is the main DataStorm object. It is required to construct topics.
67 /// @param communicator The communicator used by the node. If nullptr, the node creates its own communicator.
68 /// @remark This constructor sets the nodeOwnsCommunicator option to false. The communicator must be
69 /// configured for ordered dispatch, as described in NodeOptions::communicator.
70 explicit Node(Ice::CommunicatorPtr communicator);
71
72 /// Constructs a DataStorm node with an Ice communicator initialized from command-line arguments.
73 /// A node is the main DataStorm object. It is required to construct topics.
74 /// @tparam ArgvT The type of the argument vector, such as char**, const char**, or wchar_t** (on Windows).
75 /// @param argc The number of arguments in argv.
76 /// @param argv The command-line arguments.
77 template<typename ArgvT> Node(int& argc, ArgvT argv) : Node{createNodeOptions(argc, argv)} {}
78
79 /// Move constructor.
80 /// @param node The node to move from.
81 Node(Node&& node) noexcept;
82
83 /// Destructor.
84 /// The node destruction releases associated resources. If the node created the Ice communicator, the
85 /// communicator is destroyed.
87
88 /// Shuts down the node. The shutdown interrupts calls which are waiting for events, writers or readers.
89 void shutdown() noexcept;
90
91 /// Returns whether or not the node shutdown has been initiated.
92 /// @return `true` if the node is shutdown, `false` otherwise.
93 [[nodiscard]] bool isShutdown() const noexcept;
94
95 /// Waits for shutdown to be called.
96 void waitForShutdown() const noexcept;
97
98 /// Move assignment operator.
99 /// @param node The node to move from.
100 /// @return A reference to this node.
101 Node& operator=(Node&& node) noexcept;
102
103 /// Returns the Ice communicator associated with the node.
104 [[nodiscard]] Ice::CommunicatorPtr getCommunicator() const noexcept;
105
106 /// Returns the Ice connection associated with a session given a session identifier. Session identifiers are
107 /// returned by DataStorm::Sample::getSession.
108 /// @param ident The session identifier.
109 /// @return The connection associated with the given session
110 /// @see DataStorm::Sample::getSession
111 [[nodiscard]] Ice::ConnectionPtr getSessionConnection(std::string_view ident) const noexcept;
112
113 private:
114 /// Returns the properties a node applies to the communicators it creates.
115 static Ice::PropertiesPtr defaultProperties();
116
117 template<typename ArgvT> NodeOptions createNodeOptions(int& argc, ArgvT argv)
118 {
119 // The node defaults have to be in place before the communicator is created: the client thread pool
120 // reads its configuration when the communicator creates it.
122 initData.properties = std::make_shared<Ice::Properties>(argc, argv, defaultProperties());
123
124 NodeOptions options;
125 options.communicator = Ice::initialize(std::move(initData));
126 options.nodeOwnsCommunicator = true;
127 return options;
128 }
129
130 std::shared_ptr<DataStormI::Instance> _instance;
131 std::shared_ptr<DataStormI::TopicFactory> _factory;
132 bool _ownsCommunicator{false};
133
134 template<typename, typename, typename> friend class Topic;
135 };
136}
137#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:77
void waitForShutdown() const noexcept
Waits for shutdown to be called.
The Topic class.
Definition DataStorm.h:297
Data-centric, broker-less publish/subscribe framework. C++ only.
Definition DataStorm.h:25
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:60
bool nodeOwnsCommunicator
Specifies whether or not the node owns the communicator.
Definition Node.h:40
Ice::CommunicatorPtr communicator
The Ice communicator used by the node.
Definition Node.h:35
std::function< void(std::function< void()> call)> customExecutor
An optional executor used to execute user callbacks.
Definition Node.h:45
std::optional< Ice::SSL::ServerAuthenticationOptions > serverAuthenticationOptions
The server authentication options used for SSL connections.
Definition Node.h:49
Options to configure a DataStorm node.
Definition Node.h:28
PropertiesPtr properties
The properties for the communicator.
Definition Initialize.h:31
Represents a set of options that you can specify when initializing a communicator.
Definition Initialize.h:28