Refactor Application shutdown using new Service, AsyncService interfaces

This commit is contained in:
Vinnie Falco
2013-09-17 17:32:54 -07:00
parent 97e961a048
commit 89b1859929
57 changed files with 2690 additions and 1602 deletions

View File

@@ -4,94 +4,53 @@
*/
//==============================================================================
#ifndef RIPPLE_JOBQUEUE_H_INCLUDED
#define RIPPLE_JOBQUEUE_H_INCLUDED
#ifndef RIPPLE_CORE_JOBQUEUE_H_INCLUDED
#define RIPPLE_CORE_JOBQUEUE_H_INCLUDED
class JobQueue : private Workers::Callback
class JobQueue : public Service
{
protected:
JobQueue (char const* name, Service& parent);
public:
// Statistics on a particular JobType
struct Count
{
Count () noexcept;
explicit Count (JobType type) noexcept;
static JobQueue* New (Service& parent, Journal journal);
JobType type; // The type of Job these counts reflect
int waiting; // The number waiting
int running; // How many are running
int deferred; // Number of jobs we didn't signal due to limits
};
typedef std::map <JobType, Count> JobCounts;
//--------------------------------------------------------------------------
JobQueue ();
~JobQueue ();
virtual ~JobQueue () { }
// VFALCO TODO make convenience functions that allow the caller to not
// have to call bind.
//
void addJob (JobType type, const std::string& name, const FUNCTION_TYPE<void (Job&)>& job);
virtual void addJob (JobType type, const std::string& name, const FUNCTION_TYPE<void (Job&)>& job) = 0;
int getJobCount (JobType t); // Jobs waiting at this priority
// Jobs waiting at this priority
virtual int getJobCount (JobType t) = 0;
int getJobCountTotal (JobType t); // Jobs waiting plus running at this priority
// Jobs waiting plus running at this priority
virtual int getJobCountTotal (JobType t) = 0;
int getJobCountGE (JobType t); // All waiting jobs at or greater than this priority
// All waiting jobs at or greater than this priority
virtual int getJobCountGE (JobType t) = 0;
std::vector< std::pair<JobType, std::pair<int, int> > > getJobCounts (); // jobs waiting, threads doing
// jobs waiting, threads doing
virtual std::vector< std::pair<JobType, std::pair<int, int> > > getJobCounts () = 0;
void shutdown ();
virtual void shutdown () = 0;
void setThreadCount (int c, bool const standaloneMode);
virtual void setThreadCount (int c, bool const standaloneMode) = 0;
// VFALCO TODO Rename these to newLoadEventMeasurement or something similar
// since they create the object.
//
LoadEvent::pointer getLoadEvent (JobType t, const std::string& name)
{
return boost::make_shared<LoadEvent> (boost::ref (mJobLoads[t]), name, true);
}
virtual LoadEvent::pointer getLoadEvent (JobType t, const std::string& name) = 0;
// VFALCO TODO Why do we need two versions, one which returns a shared
// pointer and the other which returns an autoptr?
//
LoadEvent::autoptr getLoadEventAP (JobType t, const std::string& name)
{
return LoadEvent::autoptr (new LoadEvent (mJobLoads[t], name, true));
}
virtual LoadEvent::autoptr getLoadEventAP (JobType t, const std::string& name) = 0;
bool isOverloaded ();
virtual bool isOverloaded () = 0;
Json::Value getJson (int c = 0);
private:
typedef std::set <Job> JobSet;
struct State
{
State ();
uint64 lastJob;
JobSet jobSet;
JobCounts jobCounts;
};
void queueJob (Job const& job, ScopedLock const& lock);
void getNextJob (Job& job, ScopedLock const& lock);
void finishJob (Job const& job);
void processTask ();
static int getJobLimit (JobType type);
private:
typedef CriticalSection::ScopedLockType ScopedLock;
CriticalSection m_mutex;
State m_state;
Workers m_workers;
LoadMonitor mJobLoads [NUM_JOB_TYPES];
virtual Json::Value getJson (int c = 0) = 0;
};
#endif