Ice 3.9
C++ API Reference
Loading...
Searching...
No Matches
Instrumentation.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_INSTRUMENTATION_H
4#define ICE_INSTRUMENTATION_H
5
6#include "ConnectionF.h"
7#include "EndpointF.h"
8#include "Ice/Context.h"
9#include "ObjectAdapterF.h"
10
11#include <cstdint>
12#include <memory>
13#include <optional>
14
15#if defined(__clang__)
16# pragma clang diagnostic push
17# pragma clang diagnostic ignored "-Wweak-vtables"
18#endif
19
20namespace Ice
21{
22 struct Current;
23 class ObjectPrx;
24}
25
26/// Observers for objects created by the Ice runtime.
28{
29 class Observer;
30 class ThreadObserver;
32 class DispatchObserver;
34 class RemoteObserver;
37 class ObserverUpdater;
39
40 /// A shared pointer to an Observer.
41 using ObserverPtr = std::shared_ptr<Observer>;
42
43 /// A shared pointer to a ThreadObserver.
44 using ThreadObserverPtr = std::shared_ptr<ThreadObserver>;
45
46 /// A shared pointer to a ConnectionObserver.
47 using ConnectionObserverPtr = std::shared_ptr<ConnectionObserver>;
48
49 /// A shared pointer to a DispatchObserver.
50 using DispatchObserverPtr = std::shared_ptr<DispatchObserver>;
51
52 /// A shared pointer to a ChildInvocationObserver.
53 using ChildInvocationObserverPtr = std::shared_ptr<ChildInvocationObserver>;
54
55 /// A shared pointer to a RemoteObserver.
56 using RemoteObserverPtr = std::shared_ptr<RemoteObserver>;
57
58 /// A shared pointer to a CollocatedObserver.
59 using CollocatedObserverPtr = std::shared_ptr<CollocatedObserver>;
60
61 /// A shared pointer to an InvocationObserver.
62 using InvocationObserverPtr = std::shared_ptr<InvocationObserver>;
63
64 /// A shared pointer to an ObserverUpdater.
65 using ObserverUpdaterPtr = std::shared_ptr<ObserverUpdater>;
66
67 /// A shared pointer to a CommunicatorObserver.
68 using CommunicatorObserverPtr = std::shared_ptr<CommunicatorObserver>;
69
70 /// The thread state enumeration keeps track of the different possible states of Ice threads.
71 enum class ThreadState : std::uint8_t
72 {
73 /// The thread is idle.
75 /// The thread is in use performing reads or writes for Ice connections. This state is only for threads from an
76 /// Ice thread pool.
78 /// The thread is calling user code (servant implementation, AMI callbacks). This state is only for threads from
79 /// an Ice thread pool.
81 /// The thread is performing other internal activities (DNS lookups, timer callbacks, etc).
83 };
84
85 /// The state of an Ice connection.
86 enum class ConnectionState : std::uint8_t
87 {
88 /// The connection is being validated.
90
91 /// The connection is holding the reception of new messages.
93
94 /// The connection is active and can send and receive messages.
96
97 /// The connection is being gracefully shutdown and waits for the peer to close its end of the connection.
99
100 /// The connection is closed and waits for potential dispatch to be finished before being destroyed and detached
101 /// from the observer.
103 };
104
105 /// The base class for Ice observers.
106 /// @remark The Ice runtime calls observers from contexts where exceptions cannot be handled, such as destructors
107 /// and `noexcept` functions. Implementations of this interface and its derived interfaces must not throw
108 /// exceptions: a thrown exception can terminate the process.
109 /// @headerfile Ice/Ice.h
111 {
112 public:
113 virtual ~Observer() = default;
114
115 /// Notifies the observer that an instrumented object was created.
116 virtual void attach() = 0;
117
118 /// Notifies the observer that an instrumented object was destroyed.
119 virtual void detach() = 0;
120
121 /// Notifies the observer of a failure.
122 /// @param exceptionName The name of the exception.
123 virtual void failed(const std::string& exceptionName) = 0;
124 };
125
126 /// Represents an observer for Ice threads. This can be threads from the Ice thread pool or utility threads used by
127 /// the Ice core.
128 /// @headerfile Ice/Ice.h
129 class ThreadObserver : public virtual Observer
130 {
131 public:
132 /// Notifies the observer of a thread state change.
133 /// @param oldState The previous thread state.
134 /// @param newState The new thread state.
135 virtual void stateChanged(ThreadState oldState, ThreadState newState) = 0;
136 };
137
138 /// Represents an observer for Ice connections.
139 /// @headerfile Ice/Ice.h
140 class ConnectionObserver : public virtual Observer
141 {
142 public:
143 /// Notifies the observer of the number of bytes sent over the connection.
144 /// @param num The number of bytes sent.
145 virtual void sentBytes(int num) = 0;
146
147 /// Notifies the observer of the number of bytes received over the connection.
148 /// @param num The number of bytes received.
149 virtual void receivedBytes(int num) = 0;
150 };
151
152 /// Represents an observer for dispatches.
153 /// @headerfile Ice/Ice.h
154 class DispatchObserver : public virtual Observer
155 {
156 public:
157 /// Notifies the observer that the dispatch completed with a user exception.
158 virtual void userException() = 0;
159
160 /// Notifies the observer that a reply was sent.
161 /// @param size The size of the reply.
162 virtual void reply(int size) = 0;
163 };
164
165 /// Represents an observer for remote or collocated invocations.
166 /// @headerfile Ice/Ice.h
167 class ChildInvocationObserver : public virtual Observer
168 {
169 public:
170 /// Notifies the observer that a reply was received.
171 /// @param size The size of the reply.
172 virtual void reply(int size) = 0;
173 };
174
175 /// Represents an observer for remote invocations.
176 /// @headerfile Ice/Ice.h
178 {
179 };
180
181 /// Represents an observer for collocated invocations.
182 /// @headerfile Ice/Ice.h
184 {
185 };
186
187 /// Represents an observer for invocations on proxies. A proxy invocation can either result in a collocated or
188 /// remote invocation. If it results in a remote invocation, a sub-observer is requested for the remote invocation.
189 /// @headerfile Ice/Ice.h
190 class InvocationObserver : public virtual Observer
191 {
192 public:
193 /// Notifies the observer that an invocation was retried.
194 virtual void retried() = 0;
195
196 /// Notifies the observer that a user exception was received.
197 virtual void userException() = 0;
198
199 /// Gets a remote observer for this invocation.
200 /// @param con The connection information.
201 /// @param endpt The connection endpoint.
202 /// @param requestId The request ID.
203 /// @param size The size of the invocation.
204 /// @return The observer to instrument the remote invocation.
205 virtual RemoteObserverPtr
206 getRemoteObserver(const ConnectionInfoPtr& con, const EndpointPtr& endpt, int requestId, int size) = 0;
207
208 /// Gets a collocated observer for this invocation.
209 /// @param adapter The object adapter hosting the collocated Ice object.
210 /// @param requestId The request ID.
211 /// @param size The size of the invocation.
212 /// @return The observer to instrument the collocated invocation.
214 getCollocatedObserver(const ObjectAdapterPtr& adapter, int requestId, int size) = 0;
215 };
216
217 /// The observer updater interface. This interface is implemented by the Ice runtime and an instance of this
218 /// interface is provided by the Ice communicator on initialization to the CommunicatorObserver object set
219 /// with the communicator initialization data. The Ice communicator calls CommunicatorObserver::setObserverUpdater
220 /// to provide the observer updater. This interface can be used by add-ins implementing the CommunicatorObserver
221 /// interface to update the observers of connections and threads.
222 /// @headerfile Ice/Ice.h
224 {
225 public:
226 virtual ~ObserverUpdater() = default;
227
228 /// Updates connection observers associated with each of the Ice connections from the communicator and its
229 /// object adapters.
230 /// When called, this method goes through all the connections and for each connection
231 /// CommunicatorObserver::getConnectionObserver is called. The implementation of getConnectionObserver
232 /// has the possibility to return an updated observer if necessary.
233 virtual void updateConnectionObservers() = 0;
234
235 /// Updates thread observers associated with each of the Ice threads from the communicator and its object
236 /// adapters. When called, this method goes through all the threads and for each thread
237 /// CommunicatorObserver::getThreadObserver is called. The implementation of getThreadObserver has the
238 /// possibility to return an updated observer if necessary.
239 virtual void updateThreadObservers() = 0;
240 };
241
242 /// The communicator observer interface used by the Ice runtime to obtain and update observers for its observable
243 /// objects. This interface should be implemented by add-ins that wish to observe Ice objects in order to collect
244 /// statistics. An instance of this interface can be provided to the Ice runtime through the Ice communicator
245 /// initialization data.
246 /// @remark The Ice runtime calls this interface from contexts where exceptions cannot be handled, such as
247 /// `noexcept` functions. An implementation of this interface must not throw exceptions: a thrown exception can
248 /// terminate the process.
249 /// @headerfile Ice/Ice.h
251 {
252 public:
253 virtual ~CommunicatorObserver() = default;
254
255 /// Gets an observer for the given endpoint information and connector. The Ice runtime calls this method for
256 /// each connection establishment attempt.
257 /// @param endpt The endpoint.
258 /// @param connector The description of the connector. For IP transports, this is typically the IP address to
259 /// connect to.
260 /// @return The observer to instrument the connection establishment.
261 virtual ObserverPtr
262 getConnectionEstablishmentObserver(const EndpointPtr& endpt, const std::string& connector) = 0;
263
264 /// Gets an observer for the given endpoint information. The Ice runtime calls this method to resolve an
265 /// endpoint and obtain the list of connectors. For IP endpoints, this typically involves doing a DNS lookup to
266 /// obtain the IP addresses associated with the DNS name.
267 /// @param endpt The endpoint.
268 /// @return The observer to instrument the endpoint lookup.
270
271 /// Gets an observer for the given connection. The Ice runtime calls this method for each new connection and
272 /// for all the Ice communicator connections when ObserverUpdater::updateConnectionObservers is called.
273 /// @param c The connection information.
274 /// @param e The connection endpoint.
275 /// @param s The state of the connection.
276 /// @param o The old connection observer if one is already set or a nullptr reference otherwise.
277 /// @return The connection observer to instrument the connection.
279 const ConnectionInfoPtr& c,
280 const EndpointPtr& e,
282 const ConnectionObserverPtr& o) = 0;
283
284 /// Gets a thread observer for the given thread. The Ice runtime calls this method for each new thread and for
285 /// all the Ice communicator threads when ObserverUpdater::updateThreadObservers is called.
286 /// @param parent The parent of the thread.
287 /// @param id The ID of the thread to observe.
288 /// @param s The state of the thread.
289 /// @param o The old thread observer if one is already set or a null reference otherwise.
290 /// @return The thread observer to instrument the thread.
292 const std::string& parent,
293 const std::string& id,
294 ThreadState s,
295 const ThreadObserverPtr& o) = 0;
296
297 /// Gets an invocation observer for the given invocation. The Ice runtime calls this method for each new
298 /// invocation on a proxy.
299 /// @param prx The proxy used for the invocation.
300 /// @param operation The name of the operation.
301 /// @param ctx The context specified by the user.
302 /// @return The invocation observer to instrument the invocation.
304 getInvocationObserver(const std::optional<ObjectPrx>& prx, std::string_view operation, const Context& ctx) = 0;
305
306 /// Gets a dispatch observer for the given dispatch. The Ice runtime calls this method each time it receives an
307 /// incoming invocation to be dispatched for an Ice object.
308 /// @param c The current object as provided to the Ice servant dispatching the invocation.
309 /// @param size The size of the dispatch.
310 /// @return The dispatch observer to instrument the dispatch.
311 virtual DispatchObserverPtr getDispatchObserver(const Current& c, int size) = 0;
312
313 /// Sets the observer updater. The Ice runtime calls this method when the communicator is initialized. The
314 /// add-in implementing this interface can use this object to get the Ice runtime to re-obtain observers for
315 /// observed objects.
316 /// @param updater The observer updater object.
317 virtual void setObserverUpdater(const ObserverUpdaterPtr& updater) = 0;
318 };
319}
320
321#if defined(__clang__)
322# pragma clang diagnostic pop
323#endif
324
325#endif
virtual void reply(int size)=0
Notifies the observer that a reply was received.
Represents an observer for remote or collocated invocations.
Represents an observer for collocated invocations.
virtual void setObserverUpdater(const ObserverUpdaterPtr &updater)=0
Sets the observer updater.
virtual ObserverPtr getEndpointLookupObserver(const EndpointPtr &endpt)=0
Gets an observer for the given endpoint information.
virtual ThreadObserverPtr getThreadObserver(const std::string &parent, const std::string &id, ThreadState s, const ThreadObserverPtr &o)=0
Gets a thread observer for the given thread.
virtual ObserverPtr getConnectionEstablishmentObserver(const EndpointPtr &endpt, const std::string &connector)=0
Gets an observer for the given endpoint information and connector.
virtual DispatchObserverPtr getDispatchObserver(const Current &c, int size)=0
Gets a dispatch observer for the given dispatch.
virtual InvocationObserverPtr getInvocationObserver(const std::optional< ObjectPrx > &prx, std::string_view operation, const Context &ctx)=0
Gets an invocation observer for the given invocation.
virtual ConnectionObserverPtr getConnectionObserver(const ConnectionInfoPtr &c, const EndpointPtr &e, ConnectionState s, const ConnectionObserverPtr &o)=0
Gets an observer for the given connection.
The communicator observer interface used by the Ice runtime to obtain and update observers for its ob...
virtual void sentBytes(int num)=0
Notifies the observer of the number of bytes sent over the connection.
virtual void receivedBytes(int num)=0
Notifies the observer of the number of bytes received over the connection.
Represents an observer for Ice connections.
virtual void userException()=0
Notifies the observer that the dispatch completed with a user exception.
virtual void reply(int size)=0
Notifies the observer that a reply was sent.
Represents an observer for dispatches.
virtual CollocatedObserverPtr getCollocatedObserver(const ObjectAdapterPtr &adapter, int requestId, int size)=0
Gets a collocated observer for this invocation.
virtual void retried()=0
Notifies the observer that an invocation was retried.
virtual void userException()=0
Notifies the observer that a user exception was received.
virtual RemoteObserverPtr getRemoteObserver(const ConnectionInfoPtr &con, const EndpointPtr &endpt, int requestId, int size)=0
Gets a remote observer for this invocation.
Represents an observer for invocations on proxies.
virtual void updateConnectionObservers()=0
Updates connection observers associated with each of the Ice connections from the communicator and it...
virtual void updateThreadObservers()=0
Updates thread observers associated with each of the Ice threads from the communicator and its object...
The observer updater interface.
virtual void failed(const std::string &exceptionName)=0
Notifies the observer of a failure.
virtual void attach()=0
Notifies the observer that an instrumented object was created.
virtual void detach()=0
Notifies the observer that an instrumented object was destroyed.
The base class for Ice observers.
Represents an observer for remote invocations.
virtual void stateChanged(ThreadState oldState, ThreadState newState)=0
Notifies the observer of a thread state change.
Represents an observer for Ice threads.
The base class for all Ice proxies.
Definition Proxy.h:265
std::shared_ptr< CollocatedObserver > CollocatedObserverPtr
A shared pointer to a CollocatedObserver.
ConnectionState
The state of an Ice connection.
@ ConnectionStateHolding
The connection is holding the reception of new messages.
@ ConnectionStateActive
The connection is active and can send and receive messages.
@ ConnectionStateClosed
The connection is closed and waits for potential dispatch to be finished before being destroyed and d...
@ ConnectionStateValidating
The connection is being validated.
@ ConnectionStateClosing
The connection is being gracefully shutdown and waits for the peer to close its end of the connection...
std::shared_ptr< ConnectionObserver > ConnectionObserverPtr
A shared pointer to a ConnectionObserver.
std::shared_ptr< Observer > ObserverPtr
A shared pointer to an Observer.
std::shared_ptr< ThreadObserver > ThreadObserverPtr
A shared pointer to a ThreadObserver.
ThreadState
The thread state enumeration keeps track of the different possible states of Ice threads.
@ ThreadStateInUseForUser
The thread is calling user code (servant implementation, AMI callbacks).
@ ThreadStateInUseForOther
The thread is performing other internal activities (DNS lookups, timer callbacks, etc).
@ ThreadStateInUseForIO
The thread is in use performing reads or writes for Ice connections.
@ ThreadStateIdle
The thread is idle.
std::shared_ptr< ObserverUpdater > ObserverUpdaterPtr
A shared pointer to an ObserverUpdater.
std::shared_ptr< DispatchObserver > DispatchObserverPtr
A shared pointer to a DispatchObserver.
std::shared_ptr< RemoteObserver > RemoteObserverPtr
A shared pointer to a RemoteObserver.
std::shared_ptr< CommunicatorObserver > CommunicatorObserverPtr
A shared pointer to a CommunicatorObserver.
std::shared_ptr< InvocationObserver > InvocationObserverPtr
A shared pointer to an InvocationObserver.
std::shared_ptr< ChildInvocationObserver > ChildInvocationObserverPtr
A shared pointer to a ChildInvocationObserver.
Observers for objects created by the Ice runtime.
std::shared_ptr< ConnectionInfo > ConnectionInfoPtr
A shared pointer to a ConnectionInfo.
Definition ConnectionF.h:21
std::shared_ptr< ObjectAdapter > ObjectAdapterPtr
A shared pointer to an ObjectAdapter.
std::shared_ptr< Endpoint > EndpointPtr
A shared pointer to an Endpoint.
Definition EndpointF.h:20
std::map< std::string, std::string, std::less<> > Context
Represents additional information carried by an Ice request.
Definition Context.h:28
The Ice RPC framework.
Definition SampleEvent.h:60
Provides information about an incoming request being dispatched.
Definition Current.h:18