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