InstrumentationI.h
Go to the documentation of this file.
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
9 
10 #ifndef ICE_INSTRUMENTATION_I_H
11 #define ICE_INSTRUMENTATION_I_H
12 
13 #include <Ice/MetricsObserverI.h>
14 #include <Ice/Connection.h>
15 
16 namespace IceInternal
17 {
18 
19  template<typename T, typename O> class ObserverWithDelegateT : public IceMX::ObserverT<T>, public virtual O
20  {
21  public:
22 
23  typedef O ObserverType;
24  typedef typename ICE_INTERNAL_HANDLE<O> ObserverPtrType;
25  virtual void
27  {
28  IceMX::ObserverT<T>::attach();
29  if (_delegate)
30  {
31  _delegate->attach();
32  }
33  }
34 
35  virtual void
37  {
38  IceMX::ObserverT<T>::detach();
39  if (_delegate)
40  {
41  _delegate->detach();
42  }
43  }
44 
45  virtual void
46  failed(const std::string& exceptionName)
47  {
48  IceMX::ObserverT<T>::failed(exceptionName);
49  if (_delegate)
50  {
51  _delegate->failed(exceptionName);
52  }
53  }
54 
56  getDelegate() const
57  {
58  return _delegate;
59  }
60 
61  void
63  {
64  _delegate = delegate;
65  }
66 
67  template<typename ObserverImpl, typename ObserverMetricsType, typename ObserverPtrType> ObserverPtrType
68  getObserverWithDelegate(const std::string& mapName, const IceMX::MetricsHelperT<ObserverMetricsType>& helper,
69  const ObserverPtrType& del)
70  {
71  ICE_INTERNAL_HANDLE<ObserverImpl> obsv = IceMX::ObserverT<T>::template getObserver<ObserverImpl>(mapName,
72  helper);
73  if (obsv)
74  {
75  obsv->setDelegate(del);
76  return obsv;
77  }
78  return del;
79  }
80 
81  protected:
82 
84  };
85 
86  template<typename T> class ObserverFactoryWithDelegateT : public IceMX::ObserverFactoryT<T>
87  {
88  public:
89 
90  ObserverFactoryWithDelegateT(const IceInternal::MetricsAdminIPtr& metrics, const std::string& name) :
91  IceMX::ObserverFactoryT<T>(metrics, name)
92  {
93  }
94 
95  template<typename ObserverMetricsType, typename ObserverPtrType> ObserverPtrType
96  getObserverWithDelegate(const IceMX::MetricsHelperT<ObserverMetricsType>& helper, const ObserverPtrType& del)
97  {
98  ICE_INTERNAL_HANDLE<T> obsv = IceMX::ObserverFactoryT<T>::getObserver(helper);
99  if (obsv)
100  {
101  obsv->setDelegate(del);
102  return obsv;
103  }
104  return del;
105  }
106 
107  template<typename ObserverMetricsType, typename ObserverPtrType> ObserverPtrType
108  getObserverWithDelegate(const IceMX::MetricsHelperT<ObserverMetricsType>& helper, const ObserverPtrType& del,
109  const ObserverPtrType& old)
110  {
111  ICE_INTERNAL_HANDLE<T> obsv = IceMX::ObserverFactoryT<T>::getObserver(helper, old);
112  if (obsv)
113  {
114  obsv->setDelegate(del);
115  return obsv;
116  }
117  return del;
118  }
119  };
120 
121  template<typename Helper>
122  void addEndpointAttributes(typename Helper::Attributes& attrs)
123  {
124  attrs.add("endpoint", &Helper::getEndpoint);
125 
126  attrs.add("endpointType", &Helper::getEndpointInfo, &Ice::EndpointInfo::type);
127  attrs.add("endpointIsDatagram", &Helper::getEndpointInfo, &Ice::EndpointInfo::datagram);
128  attrs.add("endpointIsSecure", &Helper::getEndpointInfo, &Ice::EndpointInfo::secure);
129  attrs.add("endpointTimeout", &Helper::getEndpointInfo, &Ice::EndpointInfo::timeout);
130  attrs.add("endpointCompress", &Helper::getEndpointInfo, &Ice::EndpointInfo::compress);
131 
132  attrs.add("endpointHost", &Helper::getEndpointInfo, &Ice::IPEndpointInfo::host);
133  attrs.add("endpointPort", &Helper::getEndpointInfo, &Ice::IPEndpointInfo::port);
134  }
135 
136  template<typename Helper>
137  void addConnectionAttributes(typename Helper::Attributes& attrs)
138  {
139  attrs.add("incoming", &Helper::getConnectionInfo, &Ice::ConnectionInfo::incoming);
140  attrs.add("adapterName", &Helper::getConnectionInfo, &Ice::ConnectionInfo::adapterName);
141  attrs.add("connectionId", &Helper::getConnectionInfo, &Ice::ConnectionInfo::connectionId);
142 
143  attrs.add("localHost", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::localAddress);
144  attrs.add("localPort", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::localPort);
145  attrs.add("remoteHost", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::remoteAddress);
146  attrs.add("remotePort", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::remotePort);
147 
148  attrs.add("mcastHost", &Helper::getConnectionInfo, &Ice::UDPConnectionInfo::mcastAddress);
149  attrs.add("mcastPort", &Helper::getConnectionInfo, &Ice::UDPConnectionInfo::mcastPort);
150 
151  addEndpointAttributes<Helper>(attrs);
152  }
153 
154  class ConnectionObserverI : public ObserverWithDelegateT<IceMX::ConnectionMetrics,
155  Ice::Instrumentation::ConnectionObserver>
156  {
157  public:
158 
159  virtual void sentBytes(Ice::Int);
160  virtual void receivedBytes(Ice::Int);
161  };
162 
163  class ThreadObserverI : public ObserverWithDelegateT<IceMX::ThreadMetrics, Ice::Instrumentation::ThreadObserver>
164  {
165  public:
166 
167  virtual void stateChanged(Ice::Instrumentation::ThreadState, Ice::Instrumentation::ThreadState);
168  };
169 
170  class DispatchObserverI : public ObserverWithDelegateT<IceMX::DispatchMetrics, Ice::Instrumentation::DispatchObserver>
171  {
172  public:
173 
174  virtual void userException();
175 
176  virtual void reply(Ice::Int);
177  };
178 
179  class RemoteObserverI : public ObserverWithDelegateT<IceMX::RemoteMetrics, Ice::Instrumentation::RemoteObserver>
180  {
181  public:
182 
183  virtual void reply(Ice::Int);
184  };
185 
186  class CollocatedObserverI : public ObserverWithDelegateT<IceMX::CollocatedMetrics,
187  Ice::Instrumentation::CollocatedObserver>
188  {
189  public:
190 
191  virtual void reply(Ice::Int);
192  };
193 
194  class InvocationObserverI : public ObserverWithDelegateT<IceMX::InvocationMetrics,
195  Ice::Instrumentation::InvocationObserver>
196  {
197  public:
198 
199  virtual void retried();
200 
201  virtual void userException();
202 
203  virtual Ice::Instrumentation::RemoteObserverPtr
204  getRemoteObserver(const Ice::ConnectionInfoPtr&, const Ice::EndpointPtr&, Ice::Int, Ice::Int);
205 
206  virtual Ice::Instrumentation::CollocatedObserverPtr
208  };
209 
211 
212  class ICE_API CommunicatorObserverI : public Ice::Instrumentation::CommunicatorObserver
213  {
214  public:
215 
216  CommunicatorObserverI(const Ice::InitializationData&);
217 
218  virtual void setObserverUpdater(const Ice::Instrumentation::ObserverUpdaterPtr&);
219 
220  virtual Ice::Instrumentation::ObserverPtr getConnectionEstablishmentObserver(const Ice::EndpointPtr&,
221  const std::string&);
222 
223  virtual Ice::Instrumentation::ObserverPtr getEndpointLookupObserver(const Ice::EndpointPtr&);
224 
225  virtual Ice::Instrumentation::ConnectionObserverPtr
226  getConnectionObserver(const Ice::ConnectionInfoPtr&,
227  const Ice::EndpointPtr&,
228  Ice::Instrumentation::ConnectionState,
229  const Ice::Instrumentation::ConnectionObserverPtr&);
230 
231  virtual Ice::Instrumentation::ThreadObserverPtr getThreadObserver(const std::string&, const std::string&,
232  Ice::Instrumentation::ThreadState,
233  const Ice::Instrumentation::ThreadObserverPtr&);
234 
235  virtual Ice::Instrumentation::InvocationObserverPtr getInvocationObserver(const Ice::ObjectPrxPtr&,
236  const std::string&,
237  const Ice::Context&);
238 
239  virtual Ice::Instrumentation::DispatchObserverPtr getDispatchObserver(const Ice::Current&, Ice::Int);
240 
241  const IceInternal::MetricsAdminIPtr& getFacet() const;
242 
243  void destroy();
244 
245  private:
246 
247  IceInternal::MetricsAdminIPtr _metrics;
248  const Ice::Instrumentation::CommunicatorObserverPtr _delegate;
249 
256  };
257  ICE_DEFINE_PTR(CommunicatorObserverIPtr, CommunicatorObserverI);
258 
259 }
260 
261 #endif
IceInternal::ConnectionObserverI
Definition: InstrumentationI.h:154
IceInternal::DispatchObserverI::reply
virtual void reply(Ice::Int)
IceInternal::ObserverI
ObserverWithDelegateT< IceMX::Metrics, Ice::Instrumentation::Observer > ObserverI
Definition: InstrumentationI.h:210
IceInternal::ObserverWithDelegateT::detach
virtual void detach()
Definition: InstrumentationI.h:36
IceInternal::ObserverFactoryWithDelegateT::ObserverFactoryWithDelegateT
ObserverFactoryWithDelegateT(const IceInternal::MetricsAdminIPtr &metrics, const std::string &name)
Definition: InstrumentationI.h:90
IceInternal::ThreadObserverI
Definition: InstrumentationI.h:163
IceInternal::ObserverWithDelegateT::ObserverType
O ObserverType
Definition: InstrumentationI.h:23
IceInternal::ObserverWithDelegateT::failed
virtual void failed(const std::string &exceptionName)
Definition: InstrumentationI.h:46
IceInternal::DispatchObserverI
Definition: InstrumentationI.h:170
IceInternal::CommunicatorObserverI
Definition: InstrumentationI.h:212
IceInternal::RemoteObserverI::reply
virtual void reply(Ice::Int)
IceInternal::ObserverWithDelegateT::ObserverPtrType
ICE_INTERNAL_HANDLE< O > ObserverPtrType
Definition: InstrumentationI.h:24
IceInternal::ObserverFactoryWithDelegateT::getObserverWithDelegate
ObserverPtrType getObserverWithDelegate(const IceMX::MetricsHelperT< ObserverMetricsType > &helper, const ObserverPtrType &del, const ObserverPtrType &old)
Definition: InstrumentationI.h:108
IceInternal::Handle< ::Ice::ObjectAdapter >
IceInternal::ObserverWithDelegateT::attach
virtual void attach()
Definition: InstrumentationI.h:26
IceStorm::Instrumentation::ObserverUpdaterPtr
::IceInternal::Handle< ::IceStorm::Instrumentation::ObserverUpdater > ObserverUpdaterPtr
Definition: Instrumentation.h:190
IceInternal::ObserverWithDelegateT::getDelegate
ObserverPtrType getDelegate() const
Definition: InstrumentationI.h:56
IceInternal::RemoteObserverI
Definition: InstrumentationI.h:179
IceInternal::ConnectionObserverI::receivedBytes
virtual void receivedBytes(Ice::Int)
IceInternal::addEndpointAttributes
void addEndpointAttributes(typename Helper::Attributes &attrs)
Definition: InstrumentationI.h:122
IceInternal::addConnectionAttributes
void addConnectionAttributes(typename Helper::Attributes &attrs)
Definition: InstrumentationI.h:137
IceInternal::CollocatedObserverI
Definition: InstrumentationI.h:186
IceInternal::InvocationObserverI::retried
virtual void retried()
IceInternal::DispatchObserverI::userException
virtual void userException()
IceInternal::ThreadObserverI::stateChanged
virtual void stateChanged(Ice::Instrumentation::ThreadState, Ice::Instrumentation::ThreadState)
IceInternal::CollocatedObserverI::reply
virtual void reply(Ice::Int)
IceInternal
Definition: InstrumentationI.h:16
IceInternal::ObserverWithDelegateT::setDelegate
void setDelegate(ObserverPtrType delegate)
Definition: InstrumentationI.h:62
IceInternal::ObserverWithDelegateT
Definition: InstrumentationI.h:19
IceInternal::ObserverWithDelegateT::getObserverWithDelegate
ObserverPtrType getObserverWithDelegate(const std::string &mapName, const IceMX::MetricsHelperT< ObserverMetricsType > &helper, const ObserverPtrType &del)
Definition: InstrumentationI.h:68
IceInternal::InvocationObserverI
Definition: InstrumentationI.h:194
IceInternal::InvocationObserverI::getCollocatedObserver
virtual Ice::Instrumentation::CollocatedObserverPtr getCollocatedObserver(const Ice::ObjectAdapterPtr &, Ice::Int, Ice::Int)
IceInternal::InvocationObserverI::userException
virtual void userException()
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
IceInternal::ObserverFactoryWithDelegateT
Definition: InstrumentationI.h:86
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
IceInternal::ObserverWithDelegateT::_delegate
ObserverPtrType _delegate
Definition: InstrumentationI.h:83
IceInternal::ObserverFactoryWithDelegateT::getObserverWithDelegate
ObserverPtrType getObserverWithDelegate(const IceMX::MetricsHelperT< ObserverMetricsType > &helper, const ObserverPtrType &del)
Definition: InstrumentationI.h:96
IceInternal::InvocationObserverI::getRemoteObserver
virtual Ice::Instrumentation::RemoteObserverPtr getRemoteObserver(const Ice::ConnectionInfoPtr &, const Ice::EndpointPtr &, Ice::Int, Ice::Int)
IceInternal::ConnectionObserverI::sentBytes
virtual void sentBytes(Ice::Int)
IceInternal::ICE_DEFINE_PTR
ICE_DEFINE_PTR(CommunicatorObserverIPtr, CommunicatorObserverI)