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  onStart() override;
87 
88  void
89  onStop() override;
90 
91 private:
92  void
93  run();
94 
95 private:
98 
100  std::mutex mutex_; // Guards deadLock_, armed_, and stop_.
101 
102  std::chrono::steady_clock::time_point
103  deadLock_; // Detect server deadlocks.
104  bool armed_;
105  bool stop_;
106 
109  Application& app,
110  Stoppable& parent,
111  beast::Journal journal);
112 };
113 
115 make_LoadManager(Application& app, Stoppable& parent, beast::Journal journal);
116 
117 } // namespace ripple
118 
119 #endif
ripple::Application
Definition: Application.h:101
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:216
ripple::LoadManager::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: LoadManager.cpp:90
ripple::LoadManager::journal_
const beast::Journal journal_
Definition: LoadManager.h:97
ripple::LoadManager::app_
Application & app_
Definition: LoadManager.h:96
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
thread
ripple::LoadManager::mutex_
std::mutex mutex_
Definition: LoadManager.h:100
ripple::LoadManager::~LoadManager
~LoadManager()
Destroy the manager.
Definition: LoadManager.cpp:46
ripple::LoadManager::thread_
std::thread thread_
Definition: LoadManager.h:99
ripple::LoadManager::armed_
bool armed_
Definition: LoadManager.h:104
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:81
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:216
ripple::LoadManager::LoadManager
LoadManager()=delete
ripple::LoadManager::run
void run()
Definition: LoadManager.cpp:107
mutex
ripple::LoadManager::stop_
bool stop_
Definition: LoadManager.h:105
std::unique_ptr
STL class.
ripple::LoadManager::deadLock_
std::chrono::steady_clock::time_point deadLock_
Definition: LoadManager.h:103