// // Copyright (c) ZeroC, Inc. All rights reserved. // #ifndef ICE_INSTRUMENTATION_I_H #define ICE_INSTRUMENTATION_I_H #include #include namespace IceInternal { template class ObserverWithDelegateT : public IceMX::ObserverT, public virtual O { public: typedef O ObserverType; typedef typename ICE_INTERNAL_HANDLE ObserverPtrType; virtual void attach() { IceMX::ObserverT::attach(); if(_delegate) { _delegate->attach(); } } virtual void detach() { IceMX::ObserverT::detach(); if(_delegate) { _delegate->detach(); } } virtual void failed(const std::string& exceptionName) { IceMX::ObserverT::failed(exceptionName); if(_delegate) { _delegate->failed(exceptionName); } } ObserverPtrType getDelegate() const { return _delegate; } void setDelegate(ObserverPtrType delegate) { _delegate = delegate; } template ObserverPtrType getObserverWithDelegate(const std::string& mapName, const IceMX::MetricsHelperT& helper, const ObserverPtrType& del) { ICE_INTERNAL_HANDLE obsv = IceMX::ObserverT::template getObserver(mapName, helper); if(obsv) { obsv->setDelegate(del); return obsv; } return del; } protected: ObserverPtrType _delegate; }; template class ObserverFactoryWithDelegateT : public IceMX::ObserverFactoryT { public: ObserverFactoryWithDelegateT(const IceInternal::MetricsAdminIPtr& metrics, const std::string& name) : IceMX::ObserverFactoryT(metrics, name) { } template ObserverPtrType getObserverWithDelegate(const IceMX::MetricsHelperT& helper, const ObserverPtrType& del) { ICE_INTERNAL_HANDLE obsv = IceMX::ObserverFactoryT::getObserver(helper); if(obsv) { obsv->setDelegate(del); return obsv; } return del; } template ObserverPtrType getObserverWithDelegate(const IceMX::MetricsHelperT& helper, const ObserverPtrType& del, const ObserverPtrType& old) { ICE_INTERNAL_HANDLE obsv = IceMX::ObserverFactoryT::getObserver(helper, old); if(obsv) { obsv->setDelegate(del); return obsv; } return del; } }; template void addEndpointAttributes(typename Helper::Attributes& attrs) { attrs.add("endpoint", &Helper::getEndpoint); attrs.add("endpointType", &Helper::getEndpointInfo, &Ice::EndpointInfo::type); attrs.add("endpointIsDatagram", &Helper::getEndpointInfo, &Ice::EndpointInfo::datagram); attrs.add("endpointIsSecure", &Helper::getEndpointInfo, &Ice::EndpointInfo::secure); attrs.add("endpointTimeout", &Helper::getEndpointInfo, &Ice::EndpointInfo::timeout); attrs.add("endpointCompress", &Helper::getEndpointInfo, &Ice::EndpointInfo::compress); attrs.add("endpointHost", &Helper::getEndpointInfo, &Ice::IPEndpointInfo::host); attrs.add("endpointPort", &Helper::getEndpointInfo, &Ice::IPEndpointInfo::port); } template void addConnectionAttributes(typename Helper::Attributes& attrs) { attrs.add("incoming", &Helper::getConnectionInfo, &Ice::ConnectionInfo::incoming); attrs.add("adapterName", &Helper::getConnectionInfo, &Ice::ConnectionInfo::adapterName); attrs.add("connectionId", &Helper::getConnectionInfo, &Ice::ConnectionInfo::connectionId); attrs.add("localHost", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::localAddress); attrs.add("localPort", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::localPort); attrs.add("remoteHost", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::remoteAddress); attrs.add("remotePort", &Helper::getConnectionInfo, &Ice::IPConnectionInfo::remotePort); attrs.add("mcastHost", &Helper::getConnectionInfo, &Ice::UDPConnectionInfo::mcastAddress); attrs.add("mcastPort", &Helper::getConnectionInfo, &Ice::UDPConnectionInfo::mcastPort); addEndpointAttributes(attrs); } class ConnectionObserverI : public ObserverWithDelegateT { public: virtual void sentBytes(Ice::Int); virtual void receivedBytes(Ice::Int); }; class ThreadObserverI : public ObserverWithDelegateT { public: virtual void stateChanged(Ice::Instrumentation::ThreadState, Ice::Instrumentation::ThreadState); }; class DispatchObserverI : public ObserverWithDelegateT { public: virtual void userException(); virtual void reply(Ice::Int); }; class RemoteObserverI : public ObserverWithDelegateT { public: virtual void reply(Ice::Int); }; class CollocatedObserverI : public ObserverWithDelegateT { public: virtual void reply(Ice::Int); }; class InvocationObserverI : public ObserverWithDelegateT { public: virtual void retried(); virtual void userException(); virtual Ice::Instrumentation::RemoteObserverPtr getRemoteObserver(const Ice::ConnectionInfoPtr&, const Ice::EndpointPtr&, Ice::Int, Ice::Int); virtual Ice::Instrumentation::CollocatedObserverPtr getCollocatedObserver(const Ice::ObjectAdapterPtr&, Ice::Int, Ice::Int); }; typedef ObserverWithDelegateT ObserverI; class ICE_API CommunicatorObserverI : public Ice::Instrumentation::CommunicatorObserver { public: CommunicatorObserverI(const Ice::InitializationData&); virtual void setObserverUpdater(const Ice::Instrumentation::ObserverUpdaterPtr&); virtual Ice::Instrumentation::ObserverPtr getConnectionEstablishmentObserver(const Ice::EndpointPtr&, const std::string&); virtual Ice::Instrumentation::ObserverPtr getEndpointLookupObserver(const Ice::EndpointPtr&); virtual Ice::Instrumentation::ConnectionObserverPtr getConnectionObserver(const Ice::ConnectionInfoPtr&, const Ice::EndpointPtr&, Ice::Instrumentation::ConnectionState, const Ice::Instrumentation::ConnectionObserverPtr&); virtual Ice::Instrumentation::ThreadObserverPtr getThreadObserver(const std::string&, const std::string&, Ice::Instrumentation::ThreadState, const Ice::Instrumentation::ThreadObserverPtr&); virtual Ice::Instrumentation::InvocationObserverPtr getInvocationObserver(const Ice::ObjectPrxPtr&, const std::string&, const Ice::Context&); virtual Ice::Instrumentation::DispatchObserverPtr getDispatchObserver(const Ice::Current&, Ice::Int); const IceInternal::MetricsAdminIPtr& getFacet() const; void destroy(); private: IceInternal::MetricsAdminIPtr _metrics; const Ice::Instrumentation::CommunicatorObserverPtr _delegate; ObserverFactoryWithDelegateT _connections; ObserverFactoryWithDelegateT _dispatch; ObserverFactoryWithDelegateT _invocations; ObserverFactoryWithDelegateT _threads; ObserverFactoryWithDelegateT _connects; ObserverFactoryWithDelegateT _endpointLookups; }; ICE_DEFINE_PTR(CommunicatorObserverIPtr, CommunicatorObserverI); }; #endif