CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/EventFilter/StorageManager/interface/RegistrationInfoBase.h

Go to the documentation of this file.
00001 // $Id: RegistrationInfoBase.h,v 1.7 2011/03/07 15:31:32 mommsen Exp $
00003 
00004 #ifndef EventFilter_StorageManager_RegistrationInfoBase_h
00005 #define EventFilter_StorageManager_RegistrationInfoBase_h
00006 
00007 #include <string>
00008 
00009 #include <boost/shared_ptr.hpp>
00010 
00011 #include "EventFilter/StorageManager/interface/Configuration.h"
00012 #include "EventFilter/StorageManager/interface/ConsumerID.h"
00013 #include "EventFilter/StorageManager/interface/EnquingPolicyTag.h"
00014 #include "EventFilter/StorageManager/interface/QueueID.h"
00015 #include "EventFilter/StorageManager/interface/Utils.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 
00019 namespace stor {
00020 
00021   class EventDistributor;
00022 
00032   class RegistrationInfoBase
00033   {
00034 
00035   public:
00036     
00037     RegistrationInfoBase
00038     (
00039       const std::string& consumerName,
00040       const std::string& remoteHost,
00041       const int& queueSize,
00042       const enquing_policy::PolicyTag& queuePolicy,
00043       const utils::Duration_t& secondsToStale
00044     );
00045 
00046     RegistrationInfoBase
00047     (
00048       const edm::ParameterSet& pset,
00049       const std::string& remoteHost,
00050       const EventServingParams& eventServingParams,
00051       const bool useEventServingParams
00052     );
00053 
00058     virtual ~RegistrationInfoBase() {};
00059 
00063     void consumerContact();
00064 
00069     void registerMe(EventDistributor* dist);
00070 
00074     void eventType(std::ostream&) const;
00075 
00079     edm::ParameterSet getPSet() const;
00080 
00084     void queueInfo(std::ostream&) const;
00085 
00086     // Setters:
00087     void setMinEventRequestInterval(const utils::Duration_t& interval) { minEventRequestInterval_ = interval; }
00088 
00089     // Accessors
00090     bool isValid() const { return consumerId_.isValid(); }
00091     const QueueID& queueId() const { return queueId_; }
00092     const enquing_policy::PolicyTag& queuePolicy() const { return queuePolicy_; }
00093     const std::string& consumerName() const { return consumerName_; }
00094     const std::string& remoteHost() const { return remoteHost_; }
00095     const std::string& sourceURL() const { return sourceURL_; }
00096     const ConsumerID& consumerId() const { return consumerId_; }
00097     const int& queueSize() const { return queueSize_; }
00098     const int& maxConnectTries() const { return maxConnectTries_; }
00099     const int& connectTrySleepTime() const { return connectTrySleepTime_; }
00100     const int& retryInterval() const { return retryInterval_; }
00101     const utils::Duration_t& minEventRequestInterval() const { return minEventRequestInterval_; }
00102     const utils::Duration_t& secondsToStale() const { return secondsToStale_; }
00103     bool isStale(const utils::TimePoint_t&) const;
00104     double lastContactSecondsAgo(const utils::TimePoint_t&) const;
00105 
00106     // Setters
00107     void setQueueId(const QueueID& id) { queueId_ = id; }
00108     void setSourceURL(const std::string& url) { sourceURL_ = url; }
00109     void setConsumerId(const ConsumerID& id) { consumerId_ = id; }
00110 
00111     // Comparison:
00112     virtual bool operator<(const RegistrationInfoBase&) const;
00113     virtual bool operator==(const RegistrationInfoBase&) const;
00114     virtual bool operator!=(const RegistrationInfoBase&) const;
00115 
00116 
00117   protected:
00118 
00119     virtual void do_registerMe(EventDistributor*) = 0;
00120     virtual void do_eventType(std::ostream&) const = 0;
00121     virtual void do_appendToPSet(edm::ParameterSet&) const = 0;
00122 
00123 
00124   private:
00125 
00126     const std::string                remoteHost_;
00127     std::string                      consumerName_;
00128     std::string                      sourceURL_;
00129     int                              queueSize_;
00130     enquing_policy::PolicyTag        queuePolicy_;
00131     utils::Duration_t                secondsToStale_;
00132     int                              maxConnectTries_;
00133     int                              connectTrySleepTime_;
00134     int                              retryInterval_;
00135     utils::Duration_t                minEventRequestInterval_;
00136     QueueID                          queueId_;
00137     ConsumerID                       consumerId_;
00138     utils::TimePoint_t               lastConsumerContact_;
00139   };
00140 
00141   typedef boost::shared_ptr<RegistrationInfoBase> RegPtr;
00142 
00143 
00144   inline
00145   void RegistrationInfoBase::consumerContact()
00146   {
00147     lastConsumerContact_ = utils::getCurrentTime();
00148   }
00149 
00150   inline
00151   void RegistrationInfoBase::registerMe(EventDistributor* dist)
00152   {
00153     do_registerMe(dist);
00154   }
00155 
00156   inline
00157   void RegistrationInfoBase::eventType(std::ostream& os) const
00158   {
00159     do_eventType(os);
00160   }
00161 
00162   inline
00163   bool RegistrationInfoBase::isStale(const utils::TimePoint_t& now) const
00164   {
00165     return ( now > lastConsumerContact_ + secondsToStale() );
00166   }
00167 
00168   inline
00169   double RegistrationInfoBase::lastContactSecondsAgo(const utils::TimePoint_t& now) const
00170   {
00171     return utils::durationToSeconds( now - lastConsumerContact_ );
00172   }
00173 
00174   std::ostream& operator<<(std::ostream& os, 
00175                            RegistrationInfoBase const& ri);
00176 
00177 } // namespace stor
00178 
00179 #endif // EventFilter_StorageManager_RegistrationInfoBase_h
00180 
00181