Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
ObjectAdapter.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_OBJECT_ADAPTER_H
4#define ICE_OBJECT_ADAPTER_H
5
6#include "CommunicatorF.h"
7#include "Endpoint.h"
8#include "FacetMap.h"
9#include "ObjectAdapterF.h"
10#include "Proxy.h"
11#include "ProxyFunctions.h"
12#include "ServantLocator.h"
13
14#include <memory>
15#include <optional>
16
17namespace Ice
18{
19 class LocatorPrx;
20
21 /// An object adapter is the main server-side Ice API. It has two main purposes:
22 /// - accept incoming connections from clients and dispatch requests received over these connections (see
23 /// #activate); and
24 /// - maintain a dispatch pipeline and servants that handle the requests (see #add, #addDefaultServant, and #use).
25 ///
26 /// An object adapter can dispatch "bidirectional requests"--requests it receives over an outgoing connection
27 /// instead of a more common incoming connection. It can also dispatch collocated requests (with no connection at
28 /// all).
29 /// @see Communicator::createObjectAdapter
30 /// @headerfile Ice/Ice.h
31 class ICE_API ObjectAdapter
32 {
33 public:
34 virtual ~ObjectAdapter();
35
36 /// Gets the name of this object adapter.
37 /// @return This object adapter's name.
38 [[nodiscard]] virtual const std::string& getName() const noexcept = 0;
39
40 /// Gets the communicator that created this object adapter.
41 /// @return This object adapter's communicator.
42 [[nodiscard]] virtual CommunicatorPtr getCommunicator() const noexcept = 0;
43
44 /// Starts receiving and dispatching requests received over incoming connections.
45 /// @remark When this object adapter is an indirect object adapter configured with a locator proxy, this
46 /// function also registers the object adapter's published endpoints with this locator.
47 /// @see #deactivate
48 /// @see #getLocator
49 /// @see #getPublishedEndpoints
50 virtual void activate() = 0;
51
52 /// Stops reading requests from incoming connections. Outstanding dispatches are not affected. The object
53 /// adapter can be reactivated with #activate.
54 /// @remark This function is provided for backward compatibility with older versions of Ice. Don't use it in
55 /// new applications.
56 virtual void hold() = 0;
57
58 /// Waits until the object adapter is in the holding state (see #hold) and the dispatch of requests received
59 /// over incoming connection has completed.
60 /// @remark This function is provided for backward compatibility with older versions of Ice. Don't use it in
61 /// new applications.
62 virtual void waitForHold() = 0;
63
64 /// Deactivates this object adapter: stops accepting new connections from clients and closes gracefully all
65 /// incoming connections created by this object adapter once all outstanding dispatches have completed. If this
66 /// object adapter is indirect, this function also unregisters the object adapter from the locator
67 /// (see #activate).
68 /// This function does not cancel outstanding dispatches: it lets them execute until completion.
69 /// A deactivated object adapter cannot be reactivated again; it can only be destroyed.
70 /// @see #waitForDeactivate
71 /// @see Communicator#shutdown
72 virtual void deactivate() noexcept = 0;
73
74 /// Waits until #deactivate is called on this object adapter and all connections accepted by this object adapter
75 /// are closed. A connection is closed only after all outstanding dispatches on this connection have completed.
76 /// @see Communicator#waitForShutdown
77 virtual void waitForDeactivate() noexcept = 0;
78
79 /// Checks whether or not #deactivate was called on this object adapter.
80 /// @return `true` if #deactivate was called on this objet adapter, `false` otherwise.
81 [[nodiscard]] virtual bool isDeactivated() const noexcept = 0;
82
83 /// Destroys this object adapter and cleans up all resources associated with it. Once this function has
84 /// returned, you can recreate another object adapter with the same name.
85 /// @see Communicator#destroy
86 virtual void destroy() noexcept = 0;
87
88 /// Adds a middleware to the dispatch pipeline of this object adapter.
89 /// @param middlewareFactory The middleware factory that creates the new middleware when this object adapter
90 /// creates its dispatch pipeline. A middleware factory is a function that takes an ObjectPtr (the next element
91 /// in the dispatch pipeline) and returns a new ObjectPtr (the middleware you want to install in the pipeline).
92 /// @return This object adapter.
93 /// @remark All middleware must be installed before the first dispatch.
94 /// @remark The middleware are executed in the order they are installed.
95 virtual ObjectAdapterPtr use(std::function<ObjectPtr(ObjectPtr)> middlewareFactory) = 0;
96
97 /// Adds a servant to this object adapter's Active Servant Map (ASM). The ASM is a map {identity, facet} ->
98 /// servant.
99 /// @tparam Prx The type of the proxy to return.
100 /// @param servant The servant to add.
101 /// @param id The identity of the Ice object that is implemented by the servant.
102 /// @return A proxy for @p id created by this object adapter.
103 /// @throws AlreadyRegisteredException Thrown when a servant with the same identity is already registered.
104 /// @remark This function is equivalent to calling #addFacet with an empty facet.
105 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
106 Prx add(const ObjectPtr& servant, const Identity& id)
107 {
108 return uncheckedCast<Prx>(_add(servant, id));
109 }
110
111 /// Adds a servant to this object adapter's Active Servant Map (ASM), while specifying a facet. The ASM is a map
112 /// {identity, facet} -> servant.
113 /// @tparam Prx The type of the proxy to return.
114 /// @param servant The servant to add.
115 /// @param id The identity of the Ice object that is implemented by the servant.
116 /// @param facet The facet of the Ice object that is implemented by the servant.
117 /// @return A proxy for @p id and @p facet created by this object adapter.
118 /// @throws AlreadyRegisteredException Thrown when a servant with the same identity and facet is already
119 /// registered.
120 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
121 Prx addFacet(ObjectPtr servant, Identity id, std::string facet)
122 {
123 return uncheckedCast<Prx>(_addFacet(std::move(servant), std::move(id), std::move(facet)));
124 }
125
126 /// Adds a servant to this object adapter's Active Servant Map (ASM), using an automatically generated UUID as
127 /// its identity.
128 /// @tparam Prx The type of the proxy to return.
129 /// @param servant The servant to add.
130 /// @return A proxy with the generated UUID identity created by this object adapter.
131 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
132 [[nodiscard]] Prx addWithUUID(ObjectPtr servant)
133 {
134 return uncheckedCast<Prx>(_addWithUUID(std::move(servant)));
135 }
136
137 /// Adds a servant to this object adapter's Active Servant Map (ASM), using an automatically generated UUID as
138 /// its identity. Also specifies a facet.
139 /// @tparam Prx The type of the proxy to return.
140 /// @param servant The servant to add.
141 /// @param facet The facet of the Ice object that is implemented by the servant.
142 /// @return A proxy with the generated UUID identity and the specified facet.
143 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
144 [[nodiscard]] Prx addFacetWithUUID(ObjectPtr servant, std::string facet)
145 {
146 return uncheckedCast<Prx>(_addFacetWithUUID(std::move(servant), std::move(facet)));
147 }
148
149 /// Adds a default servant to handle requests for a specific category. When an object adapter dispatches an
150 /// incoming request, it tries to find a servant for the identity and facet carried by the request in the
151 /// following order:
152 /// - The object adapter tries to find a servant for the identity and facet in the Active Servant Map.
153 /// - If this fails, the object adapter tries to find a default servant for the category component of the
154 /// identity.
155 /// - If this fails, the object adapter tries to find a default servant for the empty category, regardless of
156 /// the category contained in the identity.
157 /// - If this fails, the object adapter tries to find a servant locator for the category component of the
158 /// identity. If there is no such servant locator, the object adapter tries to find a servant locator for the
159 /// empty category.
160 /// - If a servant locator is found, the object adapter tries to find a servant using this servant locator.
161 /// - If all the previous steps fail, the object adapter gives up and the caller receives an
162 /// ObjectNotExistException or a FacetNotExistException.
163 /// @param servant The default servant to add.
164 /// @param category The category for which the default servant is registered. The empty category means it
165 /// handles all categories.
166 virtual void addDefaultServant(ObjectPtr servant, std::string category) = 0;
167
168 /// Removes a servant from the object adapter's Active Servant Map.
169 /// @param id The identity of the Ice object that is implemented by the servant.
170 /// @return The removed servant.
171 /// @throws NotRegisteredException Thrown when no servant with the given identity is registered.
172 virtual ObjectPtr remove(const Identity& id) = 0;
173
174 /// Removes a servant from the object adapter's Active Servant Map, while specifying a facet.
175 /// @param id The identity of the Ice object that is implemented by the servant.
176 /// @param facet The facet. An empty facet means the default facet.
177 /// @return The removed servant.
178 /// @throws NotRegisteredException Thrown when no servant with the given identity and facet is registered.
179 virtual ObjectPtr removeFacet(const Identity& id, std::string_view facet) = 0;
180
181 /// Removes all facets with the given identity from the Active Servant Map. The function completely removes the
182 /// Ice object, including its default facet.
183 /// @param id The identity of the Ice object to be removed.
184 /// @return A collection containing all the facet names and servants of the removed Ice object.
185 /// @throws NotRegisteredException Thrown when no servant with the given identity is registered.
186 virtual FacetMap removeAllFacets(const Identity& id) = 0;
187
188 /// Removes the default servant for a specific category.
189 /// @param category The category of the default servant to remove.
190 /// @return The default servant.
191 /// @throws NotRegisteredException Thrown when no default servant is registered for the given category.
192 virtual ObjectPtr removeDefaultServant(std::string_view category) = 0;
193
194 /// Looks up a servant.
195 /// @param id The identity of an Ice object.
196 /// @return The servant that implements the Ice object with the given identity, or nullptr if no such servant
197 /// has been found.
198 /// @remark This function only tries to find the servant in the ASM and among the default servants. It does not
199 /// attempt to locate a servant using servant locators.
200 [[nodiscard]] virtual ObjectPtr find(const Identity& id) const = 0;
201
202 /// Looks up a servant with an identity and facet.
203 /// @param id The identity of an Ice object.
204 /// @param facet The facet of an Ice object. An empty facet means the default facet.
205 /// @remark This function only tries to find the servant in the ASM and among the default servants. It does not
206 /// attempt to locate a servant using servant locators.
207 [[nodiscard]] virtual ObjectPtr findFacet(const Identity& id, std::string_view facet) const = 0;
208
209 /// Finds all facets for a given identity in the Active Servant Map.
210 /// @param id The identity.
211 /// @return A collection containing all the facet names and servants that have been found. Can be empty.
212 [[nodiscard]] virtual FacetMap findAllFacets(const Identity& id) const = 0;
213
214 /// Looks up a servant with an identity and a facet. It's equivalent to calling #findFacet.
215 /// @param proxy The proxy that provides the identity and facet to search.
216 /// @return The servant that matches the identity and facet carried by @p proxy, or nullptr if no such servant
217 /// has been found.
218 [[nodiscard]] virtual ObjectPtr findByProxy(const ObjectPrx& proxy) const = 0;
219
220 /// Adds a ServantLocator to this object adapter for a specific category.
221 /// @param locator The servant locator to add.
222 /// @param category The category. The empty category means @p locator handles all categories.
223 /// @throws AlreadyRegisteredException Thrown when a servant locator with the same category is already
224 /// registered.
225 /// @see #addDefaultServant
226 virtual void addServantLocator(ServantLocatorPtr locator, std::string category) = 0;
227
228 /// Removes a ServantLocator from this object adapter.
229 /// @param category The category.
230 /// @return The servant locator.
231 /// @throws NotRegisteredException Thrown when no ServantLocator with the given category is registered.
232 virtual ServantLocatorPtr removeServantLocator(std::string_view category) = 0;
233
234 /// Finds a ServantLocator registered with this object adapter.
235 /// @param category The category.
236 /// @return The servant locator, or nullptr if not found.
237 [[nodiscard]] virtual ServantLocatorPtr findServantLocator(std::string_view category) const = 0;
238
239 /// Finds the default servant for a specific category.
240 /// @param category The category.
241 /// @return The default servant, or nullptr if not found.
242 [[nodiscard]] virtual ObjectPtr findDefaultServant(std::string_view category) const = 0;
243
244 /// Gets the dispatch pipeline of this object adapter.
245 /// @return The dispatch pipeline. The returned value is never nullptr.
246 [[nodiscard]] virtual const ObjectPtr& dispatchPipeline() const noexcept = 0;
247
248 /// Creates a proxy from an Ice identity. If this object adapter is configured with an adapter ID, the proxy
249 /// is an indirect proxy that refers to this adapter ID. If a replica group ID is also defined, the proxy is an
250 /// indirect proxy that refers to this replica group ID. Otherwise, the proxy is a direct proxy containing this
251 /// object adapter's published endpoints.
252 /// @tparam Prx The type of the proxy to return.
253 /// @param id An Ice identity.
254 /// @return A proxy with the given identity.
255 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
257 {
258 return uncheckedCast<Prx>(_createProxy(std::move(id)));
259 }
260
261 /// Creates a direct proxy from an Ice identity.
262 /// @tparam Prx The type of the proxy to return.
263 /// @param id An Ice identity.
264 /// @return A proxy with the given identity and this published endpoints of this object adapter.
265 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
267 {
268 return uncheckedCast<Prx>(_createDirectProxy(std::move(id)));
269 }
270
271 /// Creates an indirect proxy for an Ice identity.
272 /// @tparam Prx The type of the proxy to return.
273 /// @param id An Ice identity.
274 /// @return An indirect proxy with the given identity. If this object adapter is not configured with an adapter
275 /// ID or a replica group ID, the new proxy is a well-known proxy (i.e., an identity-only proxy).
276 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
278 {
279 return uncheckedCast<Prx>(_createIndirectProxy(std::move(id)));
280 }
281
282 /// Sets an Ice locator on this object adapter.
283 /// @param loc The locator used by this object adapter.
284 virtual void setLocator(std::optional<LocatorPrx> loc) = 0;
285
286 /// Gets the Ice locator used by this object adapter.
287 /// @return The locator used by this object adapter, or nullptr if no locator is used by this object adapter.
288 [[nodiscard]] virtual std::optional<LocatorPrx> getLocator() const noexcept = 0;
289
290 /// Gets the set of endpoints configured on this object adapter.
291 /// @return The set of endpoints.
292 /// @remark This function remains usable after the object adapter has been deactivated.
293 [[nodiscard]] virtual EndpointSeq getEndpoints() const = 0;
294
295 /// Gets the set of endpoints that proxies created by this object adapter will contain.
296 /// @return The set of published endpoints.
297 /// @remark This function remains usable after the object adapter has been deactivated.
298 [[nodiscard]] virtual EndpointSeq getPublishedEndpoints() const = 0;
299
300 /// Sets the endpoints that proxies created by this object adapter will contain.
301 /// @param newEndpoints The new set of endpoints that the object adapter will embed in proxies.
302 virtual void setPublishedEndpoints(EndpointSeq newEndpoints) = 0;
303
304 protected:
305 /// @cond INTERNAL
306 virtual ObjectPrx _add(ObjectPtr servant, Identity id) = 0;
307 virtual ObjectPrx _addFacet(ObjectPtr servant, Identity id, std::string facet) = 0;
308 virtual ObjectPrx _addWithUUID(ObjectPtr servant) = 0;
309 virtual ObjectPrx _addFacetWithUUID(ObjectPtr servant, std::string facet) = 0;
310 [[nodiscard]] virtual ObjectPrx _createProxy(Identity id) const = 0;
311 [[nodiscard]] virtual ObjectPrx _createDirectProxy(Identity id) const = 0;
312 [[nodiscard]] virtual ObjectPrx _createIndirectProxy(Identity id) const = 0;
313 /// @endcond
314 };
315}
316
317#endif
Client applications use the Locator object to resolve Ice indirect proxies.
Definition Locator.h:38
virtual void addServantLocator(ServantLocatorPtr locator, std::string category)=0
Adds a ServantLocator to this object adapter for a specific category.
virtual EndpointSeq getPublishedEndpoints() const =0
Gets the set of endpoints that proxies created by this object adapter will contain.
virtual ObjectPtr remove(const Identity &id)=0
Removes a servant from the object adapter's Active Servant Map.
virtual bool isDeactivated() const noexcept=0
Checks whether or not deactivate was called on this object adapter.
Prx addWithUUID(ObjectPtr servant)
Adds a servant to this object adapter's Active Servant Map (ASM), using an automatically generated UU...
virtual EndpointSeq getEndpoints() const =0
Gets the set of endpoints configured on this object adapter.
virtual CommunicatorPtr getCommunicator() const noexcept=0
Gets the communicator that created this object adapter.
virtual void activate()=0
Starts receiving and dispatching requests received over incoming connections.
virtual ServantLocatorPtr removeServantLocator(std::string_view category)=0
Removes a ServantLocator from this object adapter.
virtual ObjectPtr removeFacet(const Identity &id, std::string_view facet)=0
Removes a servant from the object adapter's Active Servant Map, while specifying a facet.
virtual const ObjectPtr & dispatchPipeline() const noexcept=0
Gets the dispatch pipeline of this object adapter.
virtual void setPublishedEndpoints(EndpointSeq newEndpoints)=0
Sets the endpoints that proxies created by this object adapter will contain.
virtual ObjectPtr removeDefaultServant(std::string_view category)=0
Removes the default servant for a specific category.
virtual void hold()=0
Stops reading requests from incoming connections.
virtual void deactivate() noexcept=0
Deactivates this object adapter: stops accepting new connections from clients and closes gracefully a...
Prx createProxy(Identity id)
Creates a proxy from an Ice identity.
Prx createIndirectProxy(Identity id)
Creates an indirect proxy for an Ice identity.
virtual void destroy() noexcept=0
Destroys this object adapter and cleans up all resources associated with it.
Prx addFacetWithUUID(ObjectPtr servant, std::string facet)
Adds a servant to this object adapter's Active Servant Map (ASM), using an automatically generated UU...
virtual void waitForHold()=0
Waits until the object adapter is in the holding state (see hold) and the dispatch of requests receiv...
Prx createDirectProxy(Identity id)
Creates a direct proxy from an Ice identity.
virtual const std::string & getName() const noexcept=0
Gets the name of this object adapter.
virtual ObjectPtr findFacet(const Identity &id, std::string_view facet) const =0
Looks up a servant with an identity and facet.
Prx addFacet(ObjectPtr servant, Identity id, std::string facet)
Adds a servant to this object adapter's Active Servant Map (ASM), while specifying a facet.
virtual FacetMap findAllFacets(const Identity &id) const =0
Finds all facets for a given identity in the Active Servant Map.
Prx add(const ObjectPtr &servant, const Identity &id)
Adds a servant to this object adapter's Active Servant Map (ASM).
virtual FacetMap removeAllFacets(const Identity &id)=0
Removes all facets with the given identity from the Active Servant Map.
virtual std::optional< LocatorPrx > getLocator() const noexcept=0
Gets the Ice locator used by this object adapter.
virtual ServantLocatorPtr findServantLocator(std::string_view category) const =0
Finds a ServantLocator registered with this object adapter.
virtual void setLocator(std::optional< LocatorPrx > loc)=0
Sets an Ice locator on this object adapter.
virtual void waitForDeactivate() noexcept=0
Waits until deactivate is called on this object adapter and all connections accepted by this object a...
virtual ObjectPtr findDefaultServant(std::string_view category) const =0
Finds the default servant for a specific category.
virtual ObjectPtr find(const Identity &id) const =0
Looks up a servant.
virtual ObjectPtr findByProxy(const ObjectPrx &proxy) const =0
Looks up a servant with an identity and a facet.
virtual void addDefaultServant(ObjectPtr servant, std::string category)=0
Adds a default servant to handle requests for a specific category.
virtual ObjectAdapterPtr use(std::function< ObjectPtr(ObjectPtr)> middlewareFactory)=0
Adds a middleware to the dispatch pipeline of this object adapter.
An object adapter is the main server-side Ice API.
The base class for all Ice proxies.
Definition Proxy.h:232
std::shared_ptr< Communicator > CommunicatorPtr
A shared pointer to a Communicator.
std::shared_ptr< ObjectAdapter > ObjectAdapterPtr
A shared pointer to an ObjectAdapter.
std::vector< EndpointPtr > EndpointSeq
A sequence of endpoints.
Definition EndpointF.h:41
Prx uncheckedCast(const ObjectPrx &proxy)
Creates a new proxy from an existing proxy.
std::shared_ptr< ServantLocator > ServantLocatorPtr
A shared pointer to a ServantLocator.
std::shared_ptr< Object > ObjectPtr
A shared pointer to an Object.
Definition ObjectF.h:13
std::map< std::string, ObjectPtr, std::less<> > FacetMap
A mapping from facet name to servant.
Definition FacetMap.h:13
The Ice RPC framework.
Definition SampleEvent.h:59
Represents the identity of an Ice object.
Definition Identity.h:40