Ice 3.8
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 point 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 /// Represents the base class for Ice observers.
106 /// @headerfile Ice/Ice.h
108 {
109 public:
110 virtual ~Observer() = default;
111
112 /// Notifies the observer that an instrumented object was created.
113 virtual void attach() = 0;
114
115 /// Notifies the observer that an instrumented object was destroyed.
116 virtual void detach() = 0;
117
118 /// Notifies the observer of a failure.
119 /// @param exceptionName The name of the exception.
120 virtual void failed(const std::string& exceptionName) = 0;
121 };
122
123 /// Represents an observer for Ice threads. This can be threads from the Ice thread pool or utility threads used by
124 /// the Ice core.
125 /// @headerfile Ice/Ice.h
126 class ThreadObserver : public virtual Observer
127 {
128 public:
129 /// Notifies the observer of a thread state change.
130 /// @param oldState The previous thread state.
131 /// @param newState The new thread state.
132 virtual void stateChanged(ThreadState oldState, ThreadState newState) = 0;
133 };
134
135 /// Represents an observer for Ice connections.
136 /// @headerfile Ice/Ice.h
137 class ConnectionObserver : public virtual Observer
138 {
139 public:
140 /// Notifies the observer of the number of bytes sent over the connection.
141 /// @param num The number of bytes sent.
142 virtual void sentBytes(int num) = 0;
143
144 /// Notifies the observer of the number of bytes received over the connection.
145 /// @param num The number of bytes received.
146 virtual void receivedBytes(int num) = 0;
147 };
148
149 /// Represents an observer for dispatches.
150 /// @headerfile Ice/Ice.h
151 class DispatchObserver : public virtual Observer
152 {
153 public:
154 /// Notifies the observer that the dispatch completed with a user exception.
155 virtual void userException() = 0;
156
157 /// Notifies the observer that a reply was sent.
158 /// @param size The size of the reply.
159 virtual void reply(int size) = 0;
160 };
161
162 /// Represents an observer for remote or collocated invocations.
163 /// @headerfile Ice/Ice.h
164 class ChildInvocationObserver : public virtual Observer
165 {
166 public:
167 /// Notifies the observer that a reply was received.
168 /// @param size The size of the reply.
169 virtual void reply(int size) = 0;
170 };
171
172 /// Represents an observer for remote invocations.
173 /// @headerfile Ice/Ice.h
175 {
176 };
177
178 /// Represents an observer for collocated invocations.
179 /// @headerfile Ice/Ice.h
181 {
182 };
183
184 /// Represents an observer for invocations on proxies. A proxy invocation can either result in a collocated or
185 /// remote invocation. If it results in a remote invocation, a sub-observer is requested for the remote invocation.
186 /// @headerfile Ice/Ice.h
187 class InvocationObserver : public virtual Observer
188 {
189 public:
190 /// Notifies the observer that an invocation was retried.
191 virtual void retried() = 0;
192
193 /// Notifies the observer that a user exception was received.
194 virtual void userException() = 0;
195
196 /// Gets a remote observer for this invocation.
197 /// @param con The connection information.
198 /// @param endpt The connection endpoint.
199 /// @param requestId The request ID.
200 /// @param size The size of the invocation.
201 /// @return The observer to instrument the remote invocation.
202 virtual RemoteObserverPtr
203 getRemoteObserver(const ConnectionInfoPtr& con, const EndpointPtr& endpt, int requestId, int size) = 0;
204
205 /// Gets a collocated observer for this invocation.
206 /// @param adapter The object adapter hosting the collocated Ice object.
207 /// @param requestId The request ID.
208 /// @param size The size of the invocation.
209 /// @return The observer to instrument the collocated invocation.
211 getCollocatedObserver(const ObjectAdapterPtr& adapter, int requestId, int size) = 0;
212 };
213
214 /// The observer updater interface. This interface is implemented by the Ice runtime and an instance of this
215 /// interface is provided by the Ice communicator on initialization to the CommunicatorObserver object set
216 /// with the communicator initialization data. The Ice communicator calls CommunicatorObserver::setObserverUpdater
217 /// to provide the observer updater. This interface can be used by add-ins implementing the CommunicatorObserver
218 /// interface to update the observers of connections and threads.
219 /// @headerfile Ice/Ice.h
221 {
222 public:
223 virtual ~ObserverUpdater() = default;
224
225 /// Updates connection observers associated with each of the Ice connection from the communicator and its object
226 /// adapters.
227 /// When called, this method goes through all the connections and for each connection
228 /// CommunicatorObserver::getConnectionObserver is called. The implementation of getConnectionObserver
229 /// has the possibility to return an updated observer if necessary.
230 virtual void updateConnectionObservers() = 0;
231
232 /// Updates thread observers associated with each of the Ice thread from the communicator and its object
233 /// adapters. When called, this method goes through all the threads and for each thread
234 /// CommunicatorObserver::getThreadObserver is called. The implementation of getThreadObserver has the
235 /// possibility to return an updated observer if necessary.
236 virtual void updateThreadObservers() = 0;
237 };
238
239 /// The communicator observer interface used by the Ice runtime to obtain and update observers for its observable
240 /// objects. This interface should be implemented by add-ins that wish to observe Ice objects in order to collect
241 /// statistics. An instance of this interface can be provided to the Ice run-time through the Ice communicator
242 /// initialization data.
243 /// @headerfile Ice/Ice.h
245 {
246 public:
247 virtual ~CommunicatorObserver() = default;
248
249 /// Gets an observer for the given endpoint information and connector. The Ice runtime calls this method for
250 /// each connection establishment attempt.
251 /// @param endpt The endpoint.
252 /// @param connector The description of the connector. For IP transports, this is typically the IP address to
253 /// connect to.
254 /// @return The observer to instrument the connection establishment.
255 virtual ObserverPtr
256 getConnectionEstablishmentObserver(const EndpointPtr& endpt, const std::string& connector) = 0;
257
258 /// Gets an observer for the given endpoint information. The Ice runtime calls this method to resolve an
259 /// endpoint and obtain the list of connectors. For IP endpoints, this typically involves doing a DNS lookup to
260 /// obtain the IP addresses associated with the DNS name.
261 /// @param endpt The endpoint.
262 /// @return The observer to instrument the endpoint lookup.
264
265 /// Gets an observer for the given connection. The Ice run-time calls this method for each new connection and
266 /// for all the Ice communicator connections when ObserverUpdater::updateConnectionObservers is called.
267 /// @param c The connection information.
268 /// @param e The connection endpoint.
269 /// @param s The state of the connection.
270 /// @param o The old connection observer if one is already set or a nullptr reference otherwise.
271 /// @return The connection observer to instrument the connection.
273 const ConnectionInfoPtr& c,
274 const EndpointPtr& e,
276 const ConnectionObserverPtr& o) = 0;
277
278 /// Gets a thread observer for the given thread. The Ice runtime calls this method for each new thread and for
279 /// all the Ice communicator threads when ObserverUpdater::updateThreadObservers is called.
280 /// @param parent The parent of the thread.
281 /// @param id The ID of the thread to observe.
282 /// @param s The state of the thread.
283 /// @param o The old thread observer if one is already set or a null reference otherwise.
284 /// @return The thread observer to instrument the thread.
286 const std::string& parent,
287 const std::string& id,
288 ThreadState s,
289 const ThreadObserverPtr& o) = 0;
290
291 /// Gets an invocation observer for the given invocation. The Ice runtime calls this method for each new
292 /// invocation on a proxy.
293 /// @param prx The proxy used for the invocation.
294 /// @param operation The name of the operation.
295 /// @param ctx The context specified by the user.
296 /// @return The invocation observer to instrument the invocation.
298 getInvocationObserver(const std::optional<ObjectPrx>& prx, std::string_view operation, const Context& ctx) = 0;
299
300 /// Gets a dispatch observer for the given dispatch. The Ice runtime calls this method each time it receives an
301 /// incoming invocation to be dispatched for an Ice object.
302 /// @param c The current object as provided to the Ice servant dispatching the invocation.
303 /// @param size The size of the dispatch.
304 /// @return The dispatch observer to instrument the dispatch.
305 virtual DispatchObserverPtr getDispatchObserver(const Current& c, int size) = 0;
306
307 /// Sets the observer updater. The Ice runtime calls this method when the communicator is initialized. The
308 /// add-in implementing this interface can use this object to get the Ice run-time to re-obtain observers for
309 /// observed objects.
310 /// @param updater The observer updater object.
311 virtual void setObserverUpdater(const ObserverUpdaterPtr& updater) = 0;
312 };
313}
314
315#if defined(__clang__)
316# pragma clang diagnostic pop
317#endif
318
319#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 connection from the communicator and its...
virtual void updateThreadObservers()=0
Updates thread observers associated with each of the Ice thread 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.
Represents 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:232
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 point 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:59
Provides information about an incoming request being dispatched.
Definition Current.h:18