rippled
LoadManager.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_APP_MAIN_LOADMANAGER_H_INCLUDED
21 #define RIPPLE_APP_MAIN_LOADMANAGER_H_INCLUDED
22 
23 #include <ripple/core/Stoppable.h>
24 #include <memory>
25 #include <mutex>
26 #include <thread>
27 
28 namespace ripple {
29 
30 class Application;
31 
43 class LoadManager : public Stoppable
44 {
45  LoadManager(Application& app, Stoppable& parent, beast::Journal journal);
46 
47 public:
48  LoadManager() = delete;
49  LoadManager(LoadManager const&) = delete;
51  operator=(LoadManager const&) = delete;
52 
57  ~LoadManager();
58 
67  // VFALCO NOTE it seems that the deadlock detector has an "armed" state
68  // to prevent it from going off during program startup if
69  // there's a lengthy initialization operation taking place?
70  //
71  void
73 
79  void
81 
82  //--------------------------------------------------------------------------
83 
84  // Stoppable members
85  void
86  onPrepare() override;
87 
88  void
89  onStart() override;
90 
91  void
92  onStop() override;
93 
94 private:
95  void
96  run();
97 
98 private:
101 
103  std::mutex mutex_; // Guards deadLock_, armed_, and stop_.
104 
105  std::chrono::steady_clock::time_point
106  deadLock_; // Detect server deadlocks.
107  bool armed_;
108  bool stop_;
109 
112  Application& app,
113  Stoppable& parent,
114  beast::Journal journal);
115 };
116 
118 make_LoadManager(Application& app, Stoppable& parent, beast::Journal journal);
119 
120 } // namespace ripple
121 
122 #endif
ripple::Application
Definition: Application.h:97
ripple::LoadManager::activateDeadlockDetector
void activateDeadlockDetector()
Turn on deadlock detection.
Definition: LoadManager.cpp:63
ripple::LoadManager
Manages load sources.
Definition: LoadManager.h:43
ripple::make_LoadManager
std::unique_ptr< LoadManager > make_LoadManager(Application &app, Stoppable &parent, beast::Journal journal)
Definition: LoadManager.cpp:221
ripple::LoadManager::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: LoadManager.cpp:95
ripple::LoadManager::journal_
const beast::Journal journal_
Definition: LoadManager.h:100
ripple::LoadManager::app_
Application & app_
Definition: LoadManager.h:99
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
thread
ripple::LoadManager::mutex_
std::mutex mutex_
Definition: LoadManager.h:103
ripple::LoadManager::~LoadManager
~LoadManager()
Destroy the manager.
Definition: LoadManager.cpp:46
ripple::LoadManager::thread_
std::thread thread_
Definition: LoadManager.h:102
ripple::LoadManager::armed_
bool armed_
Definition: LoadManager.h:107
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
memory
ripple::LoadManager::operator=
LoadManager & operator=(LoadManager const &)=delete
ripple::LoadManager::resetDeadlockDetector
void resetDeadlockDetector()
Reset the deadlock detection timer.
Definition: LoadManager.cpp:71
ripple::LoadManager::onStart
void onStart() override
Override called during start.
Definition: LoadManager.cpp:86
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LoadManager::make_LoadManager
friend std::unique_ptr< LoadManager > make_LoadManager(Application &app, Stoppable &parent, beast::Journal journal)
Definition: LoadManager.cpp:221
ripple::LoadManager::LoadManager
LoadManager()=delete
ripple::LoadManager::run
void run()
Definition: LoadManager.cpp:112
mutex
ripple::LoadManager::stop_
bool stop_
Definition: LoadManager.h:108
std::unique_ptr
STL class.
ripple::LoadManager::onPrepare
void onPrepare() override
Override called during preparation.
Definition: LoadManager.cpp:81
ripple::LoadManager::deadLock_
std::chrono::steady_clock::time_point deadLock_
Definition: LoadManager.h:106