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;
50  LoadManager& operator=(LoadManager const&) = delete;
51 
56  ~LoadManager ();
57 
66  // VFALCO NOTE it seems that the deadlock detector has an "armed" state
67  // to prevent it from going off during program startup if
68  // there's a lengthy initialization operation taking place?
69  //
71 
77  void resetDeadlockDetector ();
78 
79  //--------------------------------------------------------------------------
80 
81  // Stoppable members
82  void onPrepare () override;
83 
84  void onStart () override;
85 
86  void onStop () override;
87 
88 private:
89  void run ();
90 
91 private:
94 
96  std::mutex mutex_; // Guards deadLock_, armed_, and stop_.
97 
98  std::chrono::steady_clock::time_point deadLock_; // Detect server deadlocks.
99  bool armed_;
100  bool stop_;
101 
102  friend
104  make_LoadManager(Application& app, Stoppable& parent, beast::Journal journal);
105 };
106 
109  Application& app, Stoppable& parent, beast::Journal journal);
110 
111 } // ripple
112 
113 #endif
ripple::Application
Definition: Application.h:85
ripple::LoadManager::activateDeadlockDetector
void activateDeadlockDetector()
Turn on deadlock detection.
Definition: LoadManager.cpp:60
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:213
ripple::LoadManager::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: LoadManager.cpp:88
ripple::LoadManager::journal_
const beast::Journal journal_
Definition: LoadManager.h:93
ripple::LoadManager::app_
Application & app_
Definition: LoadManager.h:92
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
thread
ripple::LoadManager::mutex_
std::mutex mutex_
Definition: LoadManager.h:96
ripple::LoadManager::~LoadManager
~LoadManager()
Destroy the manager.
Definition: LoadManager.cpp:44
ripple::LoadManager::thread_
std::thread thread_
Definition: LoadManager.h:95
ripple::LoadManager::armed_
bool armed_
Definition: LoadManager.h:99
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
memory
ripple::LoadManager::operator=
LoadManager & operator=(LoadManager const &)=delete
ripple::LoadManager::resetDeadlockDetector
void resetDeadlockDetector()
Reset the deadlock detection timer.
Definition: LoadManager.cpp:67
ripple::LoadManager::onStart
void onStart() override
Override called during start.
Definition: LoadManager.cpp:80
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:213
ripple::LoadManager::LoadManager
LoadManager()=delete
ripple::LoadManager::run
void run()
Definition: LoadManager.cpp:104
mutex
ripple::LoadManager::stop_
bool stop_
Definition: LoadManager.h:100
std::unique_ptr
STL class.
ripple::LoadManager::onPrepare
void onPrepare() override
Override called during preparation.
Definition: LoadManager.cpp:76
ripple::LoadManager::deadLock_
std::chrono::steady_clock::time_point deadLock_
Definition: LoadManager.h:98