neic-glass3  1.4.6
SiteList.h
Go to the documentation of this file.
1 /*****************************************
2  * This file is documented for Doxygen.
3  * If you modify this file please update
4  * the comments so that Doxygen will still
5  * be able to work.
6  ****************************************/
7 #ifndef SITELIST_H
8 #define SITELIST_H
9 
10 #include <threadbaseclass.h>
11 
12 #include <json.h>
13 #include <string>
14 #include <vector>
15 #include <memory>
16 #include <map>
17 #include <mutex>
18 #include <thread>
19 #include <atomic>
20 
21 namespace glasscore {
22 
23 // forward declarations
24 class CSite;
25 
41  public:
48  explicit CSiteList(int numThreads = 1, int sleepTime = 100,
49  int checkInterval = 60);
50 
56  ~CSiteList();
57 
62  void clear() override;
63 
79  bool receiveExternalMessage(std::shared_ptr<json::Object> com);
80 
92  bool addSiteFromJSON(std::shared_ptr<json::Object> com);
93 
104  bool addListOfSitesFromJSON(std::shared_ptr<json::Object> com);
105 
116  bool addSite(std::shared_ptr<CSite> site);
117 
123  int size() const;
124 
134  std::shared_ptr<CSite> getSite(std::string scnl);
135 
149  std::shared_ptr<CSite> getSite(std::string site, std::string comp,
150  std::string net, std::string loc);
151 
160  std::vector<std::shared_ptr<CSite>> getListOfSites();
161 
174  std::shared_ptr<json::Object> generateSiteListMessage(bool send = true);
175 
182  int getMaxHoursWithoutPicking() const;
183 
190  void setMaxHoursWithoutPicking(int hoursWithoutPicking);
191 
198  int getHoursBeforeLookingUp() const;
199 
208  void setHoursBeforeLookingUp(int hoursBeforeLookingUp);
209 
215  int getMaxPicksPerHour() const;
216 
223  void setMaxPicksPerHour(int maxPicksPerHour);
224 
229  int getLastUpdated() const;
230 
238  glass3::util::WorkState work() override;
239 
240  private:
244  std::vector<std::shared_ptr<CSite>> m_vSite;
245 
250  std::map<std::string, std::shared_ptr<CSite>> m_mSite;
251 
256  std::map<std::string, int> m_mLastTimeSiteLookedUp;
257 
265  mutable std::recursive_mutex m_SiteListMutex;
266 
271  std::atomic<double> m_tLastChecked;
272 
277  std::atomic<int> m_iHoursBeforeLookingUp;
278 
283  std::atomic<int> m_iMaxHoursWithoutPicking;
284 
289  std::atomic<int> m_iMaxPicksPerHour;
290 
295  std::atomic<int> m_tLastUpdated;
296 
300  std::atomic<int> m_tCreated;
301 
302  // constants
306  static const int k_nHoursToSeconds = 3600;
307 };
308 } // namespace glasscore
309 #endif // SITELIST_H
void setMaxPicksPerHour(int maxPicksPerHour)
Set the maximum picks per hour before a site is declared too noisy to use, a -1 disables this metric...
Definition: SiteList.cpp:717
glasscore site list class
Definition: SiteList.h:40
~CSiteList()
CSiteList destructor.
Definition: SiteList.cpp:32
int getMaxHoursWithoutPicking() const
Get the maximum hours without picking before a site is declared nonresponsive and unused...
Definition: SiteList.cpp:702
bool receiveExternalMessage(std::shared_ptr< json::Object > com)
CSiteList communication receiving function.
Definition: SiteList.cpp:58
int getMaxPicksPerHour() const
Get the maximum picks per hour before a site is declared too noisy to use, a -1 disables this metric...
Definition: SiteList.cpp:722
std::shared_ptr< CSite > getSite(std::string scnl)
Get site by scnl.
Definition: SiteList.cpp:306
int size() const
CSiteList Site count function.
Definition: SiteList.cpp:495
bool addListOfSitesFromJSON(std::shared_ptr< json::Object > com)
CSiteList add list of sites function.
Definition: SiteList.cpp:144
std::vector< std::shared_ptr< CSite > > getListOfSites()
Get current list of sites.
Definition: SiteList.cpp:429
WorkState
glass3::util::WorkState enumeration
Definition: workstate.h:25
void setHoursBeforeLookingUp(int hoursBeforeLookingUp)
Set the maximum hours between requesting site information from outside glasscore, a -1 disables this ...
Definition: SiteList.cpp:707
CSiteList(int numThreads=1, int sleepTime=100, int checkInterval=60)
CSiteList constructor.
Definition: SiteList.cpp:22
void setMaxHoursWithoutPicking(int hoursWithoutPicking)
Set the maximum hours without picking before a site is declared nonresponsive and unused...
Definition: SiteList.cpp:697
void clear() override
CSiteList clear function.
Definition: SiteList.cpp:36
glass3::util::WorkState work() override
SiteList work function.
Definition: SiteList.cpp:501
std::shared_ptr< json::Object > generateSiteListMessage(bool send=true)
Generate SiteList message.
Definition: SiteList.cpp:444
int getLastUpdated() const
Get last time in epoch seconds the site list was modified.
Definition: SiteList.cpp:727
The namespace containing the core algorithm.
Definition: Correlation.h:17
bool addSite(std::shared_ptr< CSite > site)
CSiteList add/update site function.
Definition: SiteList.cpp:258
int getHoursBeforeLookingUp() const
Get the maximum hours between requesting site information from outside glasscore, a -1 disables this ...
Definition: SiteList.cpp:712
glass3::util::ThreadBaseClass class
Definition: threadbaseclass.h:34
bool addSiteFromJSON(std::shared_ptr< json::Object > com)
CSiteList add/update site function.
Definition: SiteList.cpp:101