From ec6c09d995b9b4fec15dc960a94678ba325181c7 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 21 Sep 2013 17:11:17 -0700 Subject: [PATCH] Rename to Stoppable --- Builds/VisualStudio2012/RippleD.vcxproj | 8 +- .../VisualStudio2012/RippleD.vcxproj.filters | 24 +- src/ripple/frame/api/Service.h | 268 ------------------ .../frame/api/{Service.cpp => Stoppable.cpp} | 91 +++--- src/ripple/frame/api/Stoppable.h | 260 +++++++++++++++++ src/ripple/frame/ripple_frame.cpp | 2 +- src/ripple/frame/ripple_frame.h | 2 +- src/ripple/validators/api/Manager.h | 2 +- src/ripple/validators/impl/Manager.cpp | 14 +- src/ripple_app/ledger/InboundLedgers.cpp | 10 +- src/ripple_app/ledger/InboundLedgers.h | 6 +- src/ripple_app/ledger/LedgerMaster.h | 6 +- src/ripple_app/ledger/OrderBookDB.cpp | 4 +- src/ripple_app/ledger/OrderBookDB.h | 4 +- src/ripple_app/main/Application.cpp | 31 +- src/ripple_app/main/Application.h | 2 +- src/ripple_app/main/IoServicePool.cpp | 12 +- src/ripple_app/main/IoServicePool.h | 8 +- src/ripple_app/main/NodeStoreScheduler.cpp | 39 +++ ...chedulerService.h => NodeStoreScheduler.h} | 16 +- .../main/NodeStoreSchedulerService.cpp | 39 --- src/ripple_app/misc/NetworkOPs.cpp | 12 +- src/ripple_app/misc/NetworkOPs.h | 4 +- src/ripple_app/peers/PeerDoor.cpp | 10 +- src/ripple_app/peers/PeerDoor.h | 4 +- src/ripple_app/peers/Peers.cpp | 8 +- src/ripple_app/peers/Peers.h | 2 +- src/ripple_app/peers/UniqueNodeList.cpp | 12 +- src/ripple_app/peers/UniqueNodeList.h | 6 +- src/ripple_app/ripple_app.cpp | 4 +- src/ripple_app/rpc/RPCHandler.cpp | 2 +- src/ripple_app/websocket/WSDoor.cpp | 8 +- src/ripple_app/websocket/WSDoor.h | 4 +- src/ripple_core/functional/JobQueue.cpp | 30 +- src/ripple_core/functional/JobQueue.h | 6 +- src/ripple_net/basics/AsyncService.cpp | 6 +- src/ripple_net/basics/AsyncService.h | 10 +- src/ripple_net/basics/SNTPClient.cpp | 10 +- src/ripple_net/basics/SNTPClient.h | 4 +- src/ripple_net/rpc/InfoSub.cpp | 4 +- src/ripple_net/rpc/InfoSub.h | 4 +- 41 files changed, 488 insertions(+), 510 deletions(-) delete mode 100644 src/ripple/frame/api/Service.h rename src/ripple/frame/api/{Service.cpp => Stoppable.cpp} (59%) create mode 100644 src/ripple/frame/api/Stoppable.h create mode 100644 src/ripple_app/main/NodeStoreScheduler.cpp rename src/ripple_app/main/{NodeStoreSchedulerService.h => NodeStoreScheduler.h} (60%) delete mode 100644 src/ripple_app/main/NodeStoreSchedulerService.cpp diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index c20b8325cf..0de6606241 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -28,7 +28,7 @@ true true - + true true true @@ -249,7 +249,7 @@ true true - + true true true @@ -1500,7 +1500,7 @@ - + @@ -1560,7 +1560,7 @@ - + diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 178d7d7e80..e1c29bc6e6 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -924,9 +924,6 @@ [1] Ripple\frame - - [1] Ripple\frame\api - [2] Old Ripple\ripple_core\nodestore @@ -978,15 +975,18 @@ [2] Old Ripple\ripple_core\nodestore\impl - - [2] Old Ripple\ripple_app\main - [2] Old Ripple\ripple_app\node [1] Ripple\frame\api + + [2] Old Ripple\ripple_app\main + + + [1] Ripple\frame\api + @@ -1869,9 +1869,6 @@ [1] Ripple\frame - - [1] Ripple\frame\api - [2] Old Ripple\ripple_core\nodestore @@ -1938,9 +1935,6 @@ [2] Old Ripple\ripple_core\nodestore\impl - - [2] Old Ripple\ripple_app\main - [2] Old Ripple\ripple_core\nodestore\api @@ -1950,6 +1944,12 @@ [1] Ripple\frame\api + + [2] Old Ripple\ripple_app\main + + + [1] Ripple\frame\api + diff --git a/src/ripple/frame/api/Service.h b/src/ripple/frame/api/Service.h deleted file mode 100644 index c4c4f61e8b..0000000000 --- a/src/ripple/frame/api/Service.h +++ /dev/null @@ -1,268 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_FRAME_SERVICE_H_INCLUDED -#define RIPPLE_FRAME_SERVICE_H_INCLUDED - -#include "../../../beast/beast/utility/Journal.h" - -namespace ripple -{ - -using namespace beast; - -/** Abstraction for organizing partitioned support code. - - The main thing a service can do, is to stop. Once it stops it cannot be - reused, it can only be destroyed. This interface is used to coordinate - the complex activities required for a clean exit in the presence of - pending asynchronous i/o and multiple theads. - - This is the sequence of events involved in stopping a service: - - 1. serviceStopAsync() [optional] - - This notifies the Service and all its children that a stop is requested. - - 2. serviceStop () - - This first calls serviceStopAsync(), and then blocks on each Service - in the tree from the bottom up, until the Service indicates it has - stopped. This will usually be called from the main thread of execution - when some external signal indicates that the process should stop. - FOr example, an RPC 'stop' command, or a SIGINT POSIX signal. - - 3. onServiceStop () - - This is called for the root Service and all its children when a stop - is requested. Derived classes should cancel pending I/O and timers, - signal that threads should exit, queue cleanup jobs, and perform any - other necessary clean up in preparation for exit. - - 4. onServiceChildrenStopped () - - When all the children of a service have stopped, this will be called. - This informs the Service that there should not be any more dependents - making calls into the derived class member functions. A Service that - has no children will have this function called immediately. - - 5. serviceStopped () - - The derived class calls this function to inform the Service API that - it has completed the stop. This unblocks the caller of serviceStop(). - - For services which are only considered stopped when all of their children - have stopped, and their own internal logic indicates a stop, it will be - necessary to perform special actions in onServiceChildrenStopped(). The - funtion areServiceChildrenStopped() can be used after children have - stopped, but before the Service logic itself has stopped, to determine - if the stopped service logic is a true stop. - - Pseudo code for this process is as follows: - - @code - - // Returns `true` if derived logic has stopped. - // - // When the logic stops, logicProcessingStop() is no longer called. - // If children are still active we need to wait until we get a - // notification that the children have stopped. - // - bool logicHasStopped (); - - // Called when children have stopped - void onServiceChildrenStopped () - { - // We have stopped when the derived logic stops and children stop. - if (logicHasStopped) - serviceStopped(); - } - - // derived-specific logic that executes periodically - void logicProcessingStep () - { - // do the step - // ... - - // now see if we've stopped - if (logicHasStopped() && areServiceChildrenStopped()) - serviceStopped(); - } - - @endcode -*/ -class Service -{ -public: - /** Create a service. - Services are always created in a non-stopped state. - A service without a parent is a root service. - */ - /** @{ */ - explicit Service (char const* name); - Service (char const* name, Service* parent); - Service (char const* name, Service& parent); - /** @} */ - - /** Destroy the service. - Undefined behavior results if the service is not first stopped. - - In general, services are not allowed to be created and destroyed - dynamically. The set of services should be static at some point - after the initialization of the process. If you need a dynamic - service, consider having a static Service which marshals service - calls to a second custom interface. - */ - virtual ~Service (); - - /** Returns the name of the service. */ - char const* serviceName () const; - - /** Notify a root service and its children to stop, and block until stopped. - If the service was already notified, it is not notified again. - The call blocks until the service and all of its children have stopped. - - Thread safety: - Safe to call from any thread not associated with a Service. - This function may only be called once. - - @param stream An optional Journal stream on which to log progress. - */ - void serviceStop (Journal::Stream stream = Journal::Stream()); - - /** Notify a root service and children to stop, without waiting. - If the service was already notified, it is not notified again. - While this is safe to call more than once, only the first call - has any effect. - - Thread safety: - Safe to call from any thread at any time. - */ - void serviceStopAsync (); - - /** Returns `true` if the service should stop. - Call from the derived class to determine if a long-running - operation should be canceled. - - Note that this is not appropriate for either threads, or asynchronous - I/O. For threads, use the thread-specific facilities available to - inform the thread that it should exi. For asynchronous I/O, cancel - all pending operations inside the onServiceStop overide. - - Thread safety: - Safe to call from any thread at any time. - - @see onServiceStop - */ - bool isServiceStopping (); - - /** Returns `true` if the service has stopped. - - Thread safety: - Safe to call from any thread at any time. - */ - bool isServiceStopped (); - - /** Returns `true` if all children have stopped. - Children of services with no children are considered stopped if - the service has been notified. - - Thread safety: - Safe to call from any thread at any time. - */ - bool areServiceChildrenStopped (); - - /** Called by derived classes to indicate that the service has stopped. - The derived class must call this either after isServiceStopping - returns `true`, or when onServiceStop is called, or else a call - to serviceStop will never return. - - Thread safety: - Safe to call from any thread at any time. - */ - void serviceStopped (); - - /** Called when the stop notification is issued. - - The call is made on an unspecified, implementation-specific thread. - onServiceStop and onServiceChildrenStopped will never be called - concurrently, across all Service objects descended from the same root, - inclusive of the root. - - It is safe to call isServiceStopping, isServiceStopped, and - areServiceChildrenStopped from within this function; The values - returned will always be valid and never change during the callback. - - The default implementation simply calls serviceStopped(). This is - applicable when the Service has a trivial stop operation (or no - stop operation), and we are merely using the Service API to position - it as a dependency of some parent service. - - Thread safety: - May not block for long periods. - Guaranteed only to be called once. - Must be safe to call from any thread at any time. - */ - virtual void onServiceStop (); - - /** Called when all children of a service have stopped. - - The call is made on an unspecified, implementation-specific thread. - onServiceStop and onServiceChildrenStopped will never be called - concurrently, across all Service objects descended from the same root, - inclusive of the root. - - It is safe to call isServiceStopping, isServiceStopped, and - areServiceChildrenStopped from within this function; The values - returned will always be valid and never change during the callback. - - Thread safety: - May not block for long periods. - Guaranteed only to be called once. - Must be safe to call from any thread at any time. - */ - virtual void onServiceChildrenStopped (); - -private: - struct Child; - typedef LockFreeStack Children; - - struct Child : Children::Node - { - Child (Service* service_) : service (service_) - { - } - - Service* service; - }; - - void stopAsyncRecursive (); - void stopRecursive (Journal::Stream stream); - - char const* m_name; - bool m_root; - Child m_child; - Children m_children; - - // Flag that we called serviceStop. This is for diagnostics. - bool m_calledServiceStop; - - // Atomic flag to make sure we only call serviceStopAsync once. - Atomic m_calledStopAsync; - - // Flag that this service stopped. Never goes back to false. - bool volatile m_stopped; - - // Flag that all children have stopped (recursive). Never goes back to false. - bool volatile m_childrenStopped; - - // serviceStop() blocks on this event until serviceStopped() is called. - WaitableEvent m_stoppedEvent; -}; - -} - -#endif diff --git a/src/ripple/frame/api/Service.cpp b/src/ripple/frame/api/Stoppable.cpp similarity index 59% rename from src/ripple/frame/api/Service.cpp rename to src/ripple/frame/api/Stoppable.cpp index 75b2893b4b..e6be6d4c94 100644 --- a/src/ripple/frame/api/Service.cpp +++ b/src/ripple/frame/api/Stoppable.cpp @@ -7,48 +7,38 @@ namespace ripple { -Service::Service (char const* name) +Stoppable::Stoppable (char const* name, Stoppable& parent) : m_name (name) - , m_root (true) + , m_root (false) , m_child (this) - , m_calledServiceStop (false) + , m_calledStop (false) , m_stopped (false) , m_childrenStopped (false) { + // must not have had stop called + bassert (! parent.isStopping()); + + parent.m_children.push_front (&m_child); } -Service::Service (char const* name, Service* parent) +Stoppable::Stoppable (char const* name, Stoppable* parent) : m_name (name) - , m_root (parent != nullptr) + , m_root (parent == nullptr) , m_child (this) - , m_calledServiceStop (false) + , m_calledStop (false) , m_stopped (false) , m_childrenStopped (false) { if (parent != nullptr) { // must not have had stop called - bassert (! parent->isServiceStopping()); + bassert (! parent->isStopping()); parent->m_children.push_front (&m_child); } } -Service::Service (char const* name, Service& parent) - : m_name (name) - , m_root (false) - , m_child (this) - , m_calledServiceStop (false) - , m_stopped (false) - , m_childrenStopped (false) -{ - // must not have had stop called - bassert (! parent.isServiceStopping()); - - parent.m_children.push_front (&m_child); -} - -Service::~Service () +Stoppable::~Stoppable () { // must be stopped bassert (m_stopped); @@ -57,69 +47,64 @@ Service::~Service () bassert (m_childrenStopped); } -char const* Service::serviceName () const -{ - return m_name; -} - -void Service::serviceStop (Journal::Stream stream) +void Stoppable::stop (Journal::Stream stream) { // may only be called once - if (m_calledServiceStop) + if (m_calledStop) return; - m_calledServiceStop = true; + m_calledStop = true; - // must be called from a root service + // must be called from a root stoppable bassert (m_root); // send the notification - serviceStopAsync (); + stopAsync (); - // now block on the tree of Service objects from the leaves up. + // now block on the tree of Stoppable objects from the leaves up. stopRecursive (stream); } -void Service::serviceStopAsync () +void Stoppable::stopAsync () { - // must be called from a root service + // must be called from a root stoppable bassert (m_root); stopAsyncRecursive (); } -bool Service::isServiceStopping () +bool Stoppable::isStopping () { return m_calledStopAsync.get() != 0; } -bool Service::isServiceStopped () +bool Stoppable::isStopped () { return m_stopped; } -bool Service::areServiceChildrenStopped () +bool Stoppable::areChildrenStopped () { return m_childrenStopped; } -void Service::serviceStopped () +void Stoppable::stopped () { m_stoppedEvent.signal(); } -void Service::onServiceStop() +void Stoppable::onStop() { - serviceStopped(); + stopped(); } -void Service::onServiceChildrenStopped () +void Stoppable::onChildrenStopped () { } //------------------------------------------------------------------------------ -void Service::stopAsyncRecursive () +void Stoppable::stopAsyncRecursive () { // make sure we only do this once if (m_root) @@ -136,27 +121,27 @@ void Service::stopAsyncRecursive () m_calledStopAsync.set (1); } - // notify this service - onServiceStop (); + // notify this stoppable + onStop (); // notify children for (Children::const_iterator iter (m_children.cbegin ()); iter != m_children.cend(); ++iter) { - iter->service->stopAsyncRecursive(); + iter->stoppable->stopAsyncRecursive(); } } -void Service::stopRecursive (Journal::Stream stream) +void Stoppable::stopRecursive (Journal::Stream stream) { - // Block on each child recursively. Thinking of the Service + // Block on each child recursively. Thinking of the Stoppable // hierarchy as a tree with the root at the top, we will block // first on leaves, and then at each successivly higher level. // for (Children::const_iterator iter (m_children.cbegin ()); iter != m_children.cend(); ++iter) { - iter->service->stopRecursive (stream); + iter->stoppable->stopRecursive (stream); } // Once we get here, we either have no children, or all of @@ -165,19 +150,19 @@ void Service::stopRecursive (Journal::Stream stream) m_childrenStopped = true; // Notify derived class that children have stopped. - onServiceChildrenStopped (); + onChildrenStopped (); - // Block until this service stops. First we do a timed wait of 1 second, and + // Block until this stoppable stops. First we do a timed wait of 1 second, and // if that times out we report to the Journal and then do an infinite wait. // bool const timedOut (! m_stoppedEvent.wait (1 * 1000)); // milliseconds if (timedOut) { - stream << "Service: Waiting for '" << serviceName() << "' to stop"; + stream << "Waiting for '" << m_name << "' to stop"; m_stoppedEvent.wait (); } - // once we get here, we know the service has stopped. + // once we get here, we know the stoppable has stopped. m_stopped = true; } diff --git a/src/ripple/frame/api/Stoppable.h b/src/ripple/frame/api/Stoppable.h new file mode 100644 index 0000000000..dac6e1e85e --- /dev/null +++ b/src/ripple/frame/api/Stoppable.h @@ -0,0 +1,260 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_FRAME_STOPPABLE_H_INCLUDED +#define RIPPLE_FRAME_STOPPABLE_H_INCLUDED + +#include "../../../beast/beast/utility/Journal.h" + +namespace ripple +{ + +using namespace beast; + +/** Provides an interface for stopping. + + This is the sequence of events involved in stopping: + + 1. stopAsync() [optional] + + This notifies the root Stoppable and all its children that a stop is + requested. + + 2. stop() + + This first calls stopAsync(), and then blocks on each child Stoppable in + the in the tree from the bottom up, until the Stoppable indicates it has + stopped. This will usually be called from the main thread of execution + when some external signal indicates that the process should stop. For + example, an RPC 'stop' command, or a SIGINT POSIX signal. + + 3. onStop() + + This override is called for the root Stoppable and all its children when + stopAsync() is called. Derived classes should cancel pending I/O and + timers, signal that threads should exit, queue cleanup jobs, and perform + any other necessary final actions in preparation for exit. + + 4. onChildrenStopped() + + This override is called when all the children have stopped. This informs + the Stoppable that there should not be any more dependents making calls + into its member functions. A Stoppable that has no children will still + have this function called. + + 5. stopped() + + The derived class calls this function to inform the Stoppable API that + it has completed the stop. This unblocks the caller of stop(). + + For stoppables which are only considered stopped when all of their + children have stopped, and their own internal logic indicates a stop, it + will be necessary to perform special actions in onChildrenStopped(). The + funtion areChildrenStopped() can be used after children have stopped, + but before the Stoppable logic itself has stopped, to determine if the + stoppable's logic is a true stop. + + Pseudo code for this process is as follows: + + @code + + // Returns `true` if derived logic has stopped. + // + // When the logic stops, logicProcessingStop() is no longer called. + // If children are still active we need to wait until we get a + // notification that the children have stopped. + // + bool logicHasStopped (); + + // Called when children have stopped + void onChildrenStopped () + { + // We have stopped when the derived logic stops and children stop. + if (logicHasStopped) + stopped(); + } + + // derived-specific logic that executes periodically + void logicProcessingStep () + { + // process + // ... + + // now see if we've stopped + if (logicHasStopped() && areChildrenStopped()) + stopped(); + } + + @endcode + + Derived class that manage one or more threads should typically notify + those threads in onStop that they should exit. In the thread function, + when the last thread is about to exit it would call stopped(). + + @note A Stoppable may not be restarted. +*/ +class Stoppable +{ +public: + /** Create the stoppable. + A stoppable without a parent is a root stoppable. + @param name A name used in log output. + @param parent Optional parent of this stoppable. + */ + /** @{ */ + Stoppable (char const* name, Stoppable& parent); + explicit Stoppable (char const* name, Stoppable* parent = nullptr); + /** @} */ + + /** Destroy the stoppable. + Undefined behavior results if the object is not stopped first. + Stoppable objects should not be created and destroyed dynamically during + the process lifetime. Rather, the set of stoppables should be static and + well-defined after initialization. If the set of domain-specific objects + which need to stop is dynamic, use a single parent Stoppable to manage + those objects. For example, make an HTTP server implementation a + Stoppable, rather than each of its active connections. + */ + virtual ~Stoppable (); + + /** Notify a root stoppable and children to stop, and block until stopped. + Has no effect if the stoppable was already notified. + This blocks until the stoppable and all of its children have stopped. + @param stream An optional Journal::Stream on which to log progress. + + Thread safety: + Safe to call from any thread not associated with a Stoppable. + */ + void stop (Journal::Stream stream = Journal::Stream()); + + /** Notify a root stoppable and children to stop, without waiting. + Has no effect if the stoppable was already notified. + + Thread safety: + Safe to call from any thread at any time. + */ + void stopAsync (); + + /** Returns `true` if the stoppable should stop. + Call from the derived class to determine if a long-running operation + should be canceled. This is not appropriate for either threads, or + asynchronous I/O. For threads, use the thread-specific facilities + available to inform the thread that it should exit. For asynchronous + I/O, cancel all pending operations inside the onStop override. + @see onStop + + Thread safety: + Safe to call from any thread at any time. + */ + bool isStopping (); + + /** Returns `true` if the stoppable has completed its stop. + Thread safety: + Safe to call from any thread at any time. + */ + bool isStopped (); + + /** Returns `true` if all children have stopped. + For stoppables without children, this returns `true` immediately + after a stop notification is received. + + Thread safety: + Safe to call from any thread at any time. + */ + bool areChildrenStopped (); + + /** Called by derived classes to indicate that the stoppable has stopped. + The derived class must call this either after isStopping returns `true`, + or when onStop is called, or else the call to stop will never unblock. + + Thread safety: + Safe to call from any thread at any time. + */ + void stopped (); + + /** Override called when the stop notification is issued. + + The call is made on an unspecified, implementation-specific thread. + onStop and onChildrenStopped will never be called concurrently, across + all Stoppable objects descended from the same root, inclusive of the + root. + + It is safe to call isStopping, isStopped, and areChildrenStopped from + within this function; The values returned will always be valid and never + change during the callback. + + The default implementation simply calls stopped(). This is applicable + when the Stoppable has a trivial stop operation (or no stop operation), + and we are merely using the Stoppable API to position it as a dependency + of some parent service. + + Thread safety: + May not block for long periods. + Guaranteed only to be called once. + Must be safe to call from any thread at any time. + */ + virtual void onStop (); + + /** Override called when all children have stopped. + + The call is made on an unspecified, implementation-specific thread. + onStop and onChildrenStopped will never be called concurrently, across + all Stoppable objects descended from the same root, inclusive of the + root. + + It is safe to call isStopping, isStopped, and areChildrenStopped from + within this function; The values returned will always be valid and never + change during the callback. + + The default implementation does nothing. + + Thread safety: + May not block for long periods. + Guaranteed only to be called once. + Must be safe to call from any thread at any time. + */ + virtual void onChildrenStopped (); + +private: + struct Child; + typedef LockFreeStack Children; + + struct Child : Children::Node + { + Child (Stoppable* stoppable_) : stoppable (stoppable_) + { + } + + Stoppable* stoppable; + }; + + void stopAsyncRecursive (); + void stopRecursive (Journal::Stream stream); + + char const* m_name; + bool m_root; + Child m_child; + Children m_children; + + // Flag that we called stop. This is for diagnostics. + bool m_calledStop; + + // Atomic flag to make sure we only call stopAsync once. + Atomic m_calledStopAsync; + + // Flag that this service stopped. Never goes back to false. + bool volatile m_stopped; + + // Flag that all children have stopped (recursive). Never goes back to false. + bool volatile m_childrenStopped; + + // stop() blocks on this event until stopped() is called. + WaitableEvent m_stoppedEvent; +}; + +} + +#endif diff --git a/src/ripple/frame/ripple_frame.cpp b/src/ripple/frame/ripple_frame.cpp index ca3d298ade..8e362e5b4e 100644 --- a/src/ripple/frame/ripple_frame.cpp +++ b/src/ripple/frame/ripple_frame.cpp @@ -14,4 +14,4 @@ #include "ripple_frame.h" #include "api/RPCService.cpp" -#include "api/Service.cpp" +#include "api/Stoppable.cpp" diff --git a/src/ripple/frame/ripple_frame.h b/src/ripple/frame/ripple_frame.h index c484d023da..c1dcd00522 100644 --- a/src/ripple/frame/ripple_frame.h +++ b/src/ripple/frame/ripple_frame.h @@ -11,7 +11,7 @@ #include "../json/ripple_json.h" +#include "api/Stoppable.h" #include "api/RPCService.h" -#include "api/Service.h" #endif diff --git a/src/ripple/validators/api/Manager.h b/src/ripple/validators/api/Manager.h index 60ddfc539f..7a5618dc32 100644 --- a/src/ripple/validators/api/Manager.h +++ b/src/ripple/validators/api/Manager.h @@ -22,7 +22,7 @@ class Manager : public RPCService public: /** Create a new Manager object. */ - static Manager* New (Service& parent, Journal journal); + static Manager* New (Stoppable& parent, Journal journal); /** Destroy the object. diff --git a/src/ripple/validators/impl/Manager.cpp b/src/ripple/validators/impl/Manager.cpp index 927738eada..7daad67fc7 100644 --- a/src/ripple/validators/impl/Manager.cpp +++ b/src/ripple/validators/impl/Manager.cpp @@ -89,14 +89,14 @@ namespace Validators class ManagerImp : public Manager - , public Service + , public Stoppable , public ThreadWithCallQueue::EntryPoints , public DeadlineTimer::Listener , public LeakChecked { public: - ManagerImp (Service& parent, Journal journal) - : Service ("Validators::Manager", parent) + ManagerImp (Stoppable& parent, Journal journal) + : Stoppable ("Validators::Manager", parent) , m_store (journal) , m_logic (m_store, journal) , m_journal (journal) @@ -115,10 +115,10 @@ public: //-------------------------------------------------------------------------- // - // Service + // Stoppable // - void onServiceStop () + void onStop () { m_thread.stop (false); } @@ -262,7 +262,7 @@ public: void threadExit () { // must come last - serviceStopped (); + stopped (); } bool threadIdle () @@ -302,7 +302,7 @@ private: //------------------------------------------------------------------------------ -Validators::Manager* Validators::Manager::New (Service& parent, Journal journal) +Validators::Manager* Validators::Manager::New (Stoppable& parent, Journal journal) { return new Validators::ManagerImp (parent, journal); } diff --git a/src/ripple_app/ledger/InboundLedgers.cpp b/src/ripple_app/ledger/InboundLedgers.cpp index 3d5c1c8329..ad0b4d65cc 100644 --- a/src/ripple_app/ledger/InboundLedgers.cpp +++ b/src/ripple_app/ledger/InboundLedgers.cpp @@ -6,8 +6,8 @@ typedef std::pair u256_acq_pair; -InboundLedgers::InboundLedgers (Service& parent) - : Service ("InboundLedgers", parent) +InboundLedgers::InboundLedgers (Stoppable& parent) + : Stoppable ("InboundLedgers", parent) , mLock (this, "InboundLedger", __FILE__, __LINE__) , mRecentFailures ("LedgerAcquireRecentFailures", 0, kReacquireIntervalSeconds) { @@ -21,7 +21,7 @@ InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 s { ScopedLockType sl (mLock, __FILE__, __LINE__); - if (! isServiceStopping ()) + if (! isStopping ()) { boost::unordered_map::iterator it = mLedgers.find (hash); if (it != mLedgers.end ()) @@ -352,12 +352,12 @@ Json::Value InboundLedgers::getInfo() return ret; } -void InboundLedgers::onServiceStop () +void InboundLedgers::onStop () { ScopedLockType lock (mLock, __FILE__, __LINE__); mLedgers.clear(); mRecentFailures.clear(); - serviceStopped(); + stopped(); } diff --git a/src/ripple_app/ledger/InboundLedgers.h b/src/ripple_app/ledger/InboundLedgers.h index 7b050e80a7..3d450f6665 100644 --- a/src/ripple_app/ledger/InboundLedgers.h +++ b/src/ripple_app/ledger/InboundLedgers.h @@ -14,14 +14,14 @@ // VFALCO TODO Rename to InboundLedgers // VFALCO TODO Create abstract interface class InboundLedgers - : public Service + : public Stoppable , public LeakChecked { public: // How long before we try again to acquire the same ledger static const int kReacquireIntervalSeconds = 300; - explicit InboundLedgers (Service& parent); + explicit InboundLedgers (Stoppable& parent); // VFALCO TODO Should this be called findOrAdd ? // @@ -62,7 +62,7 @@ public: void gotFetchPack (Job&); void sweep (); - void onServiceStop (); + void onStop (); private: typedef boost::unordered_map MapType; diff --git a/src/ripple_app/ledger/LedgerMaster.h b/src/ripple_app/ledger/LedgerMaster.h index 73fdbef31e..ac70560c21 100644 --- a/src/ripple_app/ledger/LedgerMaster.h +++ b/src/ripple_app/ledger/LedgerMaster.h @@ -15,7 +15,7 @@ // It sounds like this holds all the ledgers... // class LedgerMaster - : public Service + : public Stoppable , public LeakChecked { public: @@ -25,8 +25,8 @@ public: typedef RippleRecursiveMutex LockType; typedef LockType::ScopedLockType ScopedLockType; - explicit LedgerMaster (Service& parent) - : Service ("LedgerMaster", parent) + explicit LedgerMaster (Stoppable& parent) + : Stoppable ("LedgerMaster", parent) , mLock (this, "LedgerMaster", __FILE__, __LINE__) , mHeldTransactions (uint256 ()) , mMinValidations (0) diff --git a/src/ripple_app/ledger/OrderBookDB.cpp b/src/ripple_app/ledger/OrderBookDB.cpp index cccbdf581a..065d1241a0 100644 --- a/src/ripple_app/ledger/OrderBookDB.cpp +++ b/src/ripple_app/ledger/OrderBookDB.cpp @@ -6,8 +6,8 @@ SETUP_LOG (OrderBookDB) -OrderBookDB::OrderBookDB (Service& parent) - : Service ("OrderBookDB", parent) +OrderBookDB::OrderBookDB (Stoppable& parent) + : Stoppable ("OrderBookDB", parent) , mLock (this, "OrderBookDB", __FILE__, __LINE__) , mSeq (0) { diff --git a/src/ripple_app/ledger/OrderBookDB.h b/src/ripple_app/ledger/OrderBookDB.h index 81e0246a79..257addc1c1 100644 --- a/src/ripple_app/ledger/OrderBookDB.h +++ b/src/ripple_app/ledger/OrderBookDB.h @@ -46,11 +46,11 @@ private: //------------------------------------------------------------------------------ class OrderBookDB - : public Service + : public Stoppable , public LeakChecked { public: - explicit OrderBookDB (Service& parent); + explicit OrderBookDB (Stoppable& parent); void setup (Ledger::ref ledger); void update (Ledger::pointer ledger); diff --git a/src/ripple_app/main/Application.cpp b/src/ripple_app/main/Application.cpp index 647a1bfc9c..03c54265bf 100644 --- a/src/ripple_app/main/Application.cpp +++ b/src/ripple_app/main/Application.cpp @@ -31,7 +31,7 @@ template <> char const* LogPartition::getPartitionName () // VFALCO TODO Move the function definitions into the class declaration class ApplicationImp : public Application - , public Service + , public Stoppable , public DeadlineTimer::Listener , LeakChecked , PeerFinder::Callback @@ -49,7 +49,7 @@ public: //-------------------------------------------------------------------------- ApplicationImp () - : Service ("Application") + : Stoppable ("Application") , m_journal (LogJournal::get ()) , m_tempNodeCache ("NodeCache", 16384, 90) , m_sleCache ("LedgerEntryCache", 4096, 120) @@ -58,7 +58,7 @@ public: LogJournal::get ())) // The JobQueue has to come pretty early since - // almost everything is a Service child of the JobQueue. + // almost everything is a Stoppable child of the JobQueue. // , m_jobQueue (JobQueue::New (*this, LogJournal::get ())) @@ -130,7 +130,7 @@ public: ~ApplicationImp () { - serviceStop(); + stop(); //stop (); // Why is this needed here? @@ -429,7 +429,8 @@ public: if (!loadOldLedger (getConfig ().START_LEDGER, getConfig ().START_UP == Config::REPLAY)) { - getApp().stop (); + // wtf? + getApp().signalStop (); exit (-1); } } @@ -618,10 +619,10 @@ public: //-------------------------------------------------------------------------- // - // Service + // Stoppable // Called to indicate shutdown. - void onServiceStop () + void onStop () { m_sweepTimer.cancel(); @@ -630,7 +631,7 @@ public: mValidations->flush (); mShutdown = false; - serviceStopped (); + stopped (); } // @@ -667,7 +668,7 @@ public: #endif // Stop the server. When this returns, all - // Service objects should be stopped. + // Stoppable objects should be stopped. doStop (); @@ -697,10 +698,10 @@ public: m_journal.info << "Received shutdown request"; StopSustain (); - serviceStop (m_journal.warning); + stop (m_journal.warning); } - void stop () + void signalStop () { // Unblock the main thread (which is sitting in run()). // @@ -720,7 +721,7 @@ public: if (space.available < (512 * 1024 * 1024)) { m_journal.fatal << "Remaining free disk space is less than 512MB"; - getApp().stop (); + getApp().signalStop (); } m_jobQueue->addJob(jtSWEEP, "sweep", @@ -781,7 +782,7 @@ private: Journal m_journal; Application::LockType m_masterMutex; - // These are not Service-derived + // These are not Stoppable-derived NodeCache m_tempNodeCache; SLECache m_sleCache; LocalCredentials m_localCredentials; @@ -789,7 +790,7 @@ private: ScopedPointer m_rpcServiceManager; - // These are Service-related + // These are Stoppable-related ScopedPointer m_jobQueue; IoServicePool m_mainIoPool; OrderBookDB m_orderBookDB; @@ -797,7 +798,7 @@ private: ScopedPointer m_networkOPs; ScopedPointer m_deprecatedUNL; RPCServerHandler m_rpcServerHandler; - NodeStoreSchedulerService m_nodeStoreScheduler; + NodeStoreScheduler m_nodeStoreScheduler; ScopedPointer m_nodeStore; ScopedPointer m_sntpClient; InboundLedgers m_inboundLedgers; diff --git a/src/ripple_app/main/Application.h b/src/ripple_app/main/Application.h index ec054bcb88..6249521b7b 100644 --- a/src/ripple_app/main/Application.h +++ b/src/ripple_app/main/Application.h @@ -118,7 +118,7 @@ public: virtual bool running () = 0; virtual void setup () = 0; virtual void run () = 0; - virtual void stop () = 0; + virtual void signalStop () = 0; }; extern Application& getApp (); diff --git a/src/ripple_app/main/IoServicePool.cpp b/src/ripple_app/main/IoServicePool.cpp index 607aab9cff..f19fd08810 100644 --- a/src/ripple_app/main/IoServicePool.cpp +++ b/src/ripple_app/main/IoServicePool.cpp @@ -43,8 +43,8 @@ private: //------------------------------------------------------------------------------ -IoServicePool::IoServicePool (Service& parent, String const& name, int numberOfThreads) - : Service (name.toStdString().c_str(), parent) +IoServicePool::IoServicePool (Stoppable& parent, String const& name, int numberOfThreads) + : Stoppable (name.toStdString().c_str(), parent) , m_name (name) , m_service (numberOfThreads) , m_work (boost::ref (m_service)) @@ -76,7 +76,7 @@ IoServicePool::operator boost::asio::io_service& () return m_service; } -void IoServicePool::onServiceStop () +void IoServicePool::onStop () { // VFALCO NOTE This is a hack! We should gracefully // cancel all pending I/O, and delete the work @@ -86,7 +86,7 @@ void IoServicePool::onServiceStop () m_service.stop (); } -void IoServicePool::onServiceChildrenStopped () +void IoServicePool::onChildrenStopped () { } @@ -95,7 +95,7 @@ void IoServicePool::onServiceChildrenStopped () void IoServicePool::onThreadExit() { // service must be stopping for threads to exit. - bassert (isServiceStopping()); + bassert (isStopping()); // must have at least count 1 bassert (m_threadsRunning.get() > 0); @@ -103,6 +103,6 @@ void IoServicePool::onThreadExit() if (--m_threadsRunning == 0) { // last thread just exited - serviceStopped (); + stopped (); } } diff --git a/src/ripple_app/main/IoServicePool.h b/src/ripple_app/main/IoServicePool.h index 5ddbe3c97b..0249d19d48 100644 --- a/src/ripple_app/main/IoServicePool.h +++ b/src/ripple_app/main/IoServicePool.h @@ -8,17 +8,17 @@ #define RIPPLE_APP_IOSERVICEPOOL_H_INCLUDED /** An io_service with an associated group of threads. */ -class IoServicePool : public Service +class IoServicePool : public Stoppable { public: - IoServicePool (Service& parent, String const& name, int numberOfThreads); + IoServicePool (Stoppable& parent, String const& name, int numberOfThreads); ~IoServicePool (); boost::asio::io_service& getService (); operator boost::asio::io_service& (); - void onServiceStop (); - void onServiceChildrenStopped (); + void onStop (); + void onChildrenStopped (); private: class ServiceThread; diff --git a/src/ripple_app/main/NodeStoreScheduler.cpp b/src/ripple_app/main/NodeStoreScheduler.cpp new file mode 100644 index 0000000000..181b24fda9 --- /dev/null +++ b/src/ripple_app/main/NodeStoreScheduler.cpp @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +NodeStoreScheduler::NodeStoreScheduler (Stoppable& parent, JobQueue& jobQueue) + : Stoppable ("NodeStoreScheduler", parent) + , m_jobQueue (jobQueue) + , m_taskCount (1) // start it off at 1 +{ +} + +void NodeStoreScheduler::onStop () +{ + if (--m_taskCount == 0) + stopped(); +} + +void NodeStoreScheduler::onChildrenStopped () +{ +} + +void NodeStoreScheduler::scheduleTask (NodeStore::Task& task) +{ + ++m_taskCount; + m_jobQueue.addJob ( + jtWRITE, + "NodeObject::store", + BIND_TYPE (&NodeStoreScheduler::doTask, + this, boost::ref(task), P_1)); +} + +void NodeStoreScheduler::doTask (NodeStore::Task& task, Job&) +{ + task.performScheduledTask (); + if ((--m_taskCount == 0) && isStopping()) + stopped(); +} diff --git a/src/ripple_app/main/NodeStoreSchedulerService.h b/src/ripple_app/main/NodeStoreScheduler.h similarity index 60% rename from src/ripple_app/main/NodeStoreSchedulerService.h rename to src/ripple_app/main/NodeStoreScheduler.h index c9e30a9121..4843f3ec32 100644 --- a/src/ripple_app/main/NodeStoreSchedulerService.h +++ b/src/ripple_app/main/NodeStoreScheduler.h @@ -4,19 +4,19 @@ */ //============================================================================== -#ifndef RIPPLE_APP_NODESTORESCHEDULERSERVICE_H_INCLUDED -#define RIPPLE_APP_NODESTORESCHEDULERSERVICE_H_INCLUDED +#ifndef RIPPLE_APP_NODESTORESCHEDULER_H_INCLUDED +#define RIPPLE_APP_NODESTORESCHEDULER_H_INCLUDED -/** A NodeStore::Scheduler which uses the JobQueue and implements the Service API. */ -class NodeStoreSchedulerService +/** A NodeStore::Scheduler which uses the JobQueue and implements the Stoppable API. */ +class NodeStoreScheduler : public NodeStore::Scheduler - , public Service + , public Stoppable { public: - NodeStoreSchedulerService (Service& parent, JobQueue& jobQueue); + NodeStoreScheduler (Stoppable& parent, JobQueue& jobQueue); - void onServiceStop (); - void onServiceChildrenStopped (); + void onStop (); + void onChildrenStopped (); void scheduleTask (NodeStore::Task& task); private: diff --git a/src/ripple_app/main/NodeStoreSchedulerService.cpp b/src/ripple_app/main/NodeStoreSchedulerService.cpp deleted file mode 100644 index 83ff0068f0..0000000000 --- a/src/ripple_app/main/NodeStoreSchedulerService.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -NodeStoreSchedulerService::NodeStoreSchedulerService (Service& parent, JobQueue& jobQueue) - : Service ("NodeStoreSchedulerService", parent) - , m_jobQueue (jobQueue) - , m_taskCount (1) // start it off at 1 -{ -} - -void NodeStoreSchedulerService::onServiceStop () -{ - if (--m_taskCount == 0) - serviceStopped(); -} - -void NodeStoreSchedulerService::onServiceChildrenStopped () -{ -} - -void NodeStoreSchedulerService::scheduleTask (NodeStore::Task& task) -{ - ++m_taskCount; - m_jobQueue.addJob ( - jtWRITE, - "NodeObject::store", - BIND_TYPE (&NodeStoreSchedulerService::doTask, - this, boost::ref(task), P_1)); -} - -void NodeStoreSchedulerService::doTask (NodeStore::Task& task, Job&) -{ - task.performScheduledTask (); - if ((--m_taskCount == 0) && isServiceStopping()) - serviceStopped(); -} diff --git a/src/ripple_app/misc/NetworkOPs.cpp b/src/ripple_app/misc/NetworkOPs.cpp index 73846da4ce..25adb14fa9 100644 --- a/src/ripple_app/misc/NetworkOPs.cpp +++ b/src/ripple_app/misc/NetworkOPs.cpp @@ -20,7 +20,7 @@ public: public: // VFALCO TODO Make LedgerMaster a SharedPtr or a reference. // - NetworkOPsImp (LedgerMaster& ledgerMaster, Service& parent, Journal journal) + NetworkOPsImp (LedgerMaster& ledgerMaster, Stoppable& parent, Journal journal) : NetworkOPs (parent) , m_journal (journal) , mLock (this, "NetOPs", __FILE__, __LINE__) @@ -360,14 +360,14 @@ public: //-------------------------------------------------------------------------- // - // Service + // Stoppable - void onServiceStop () + void onStop () { m_heartbeatTimer.cancel(); m_clusterTimer.cancel(); - serviceStopped (); + stopped (); } private: @@ -3075,7 +3075,7 @@ void NetworkOPsImp::missingNodeInLedger (uint32 seq) //------------------------------------------------------------------------------ -NetworkOPs::NetworkOPs (Service& parent) +NetworkOPs::NetworkOPs (Stoppable& parent) : InfoSub::Source ("NetworkOPs", parent) { } @@ -3083,7 +3083,7 @@ NetworkOPs::NetworkOPs (Service& parent) //------------------------------------------------------------------------------ NetworkOPs* NetworkOPs::New (LedgerMaster& ledgerMaster, - Service& parent, Journal journal) + Stoppable& parent, Journal journal) { ScopedPointer object (new NetworkOPsImp ( ledgerMaster, parent, journal)); diff --git a/src/ripple_app/misc/NetworkOPs.h b/src/ripple_app/misc/NetworkOPs.h index 41ef2e1ca0..0fda852a8b 100644 --- a/src/ripple_app/misc/NetworkOPs.h +++ b/src/ripple_app/misc/NetworkOPs.h @@ -40,7 +40,7 @@ class NetworkOPs : public InfoSub::Source { protected: - explicit NetworkOPs (Service& parent); + explicit NetworkOPs (Stoppable& parent); public: enum Fault @@ -68,7 +68,7 @@ public: // VFALCO TODO Make LedgerMaster a SharedPtr or a reference. // static NetworkOPs* New (LedgerMaster& ledgerMaster, - Service& parent, Journal journal); + Stoppable& parent, Journal journal); virtual ~NetworkOPs () { } diff --git a/src/ripple_app/peers/PeerDoor.cpp b/src/ripple_app/peers/PeerDoor.cpp index 3d3d8dbf2e..74eb4ffdae 100644 --- a/src/ripple_app/peers/PeerDoor.cpp +++ b/src/ripple_app/peers/PeerDoor.cpp @@ -11,7 +11,7 @@ class PeerDoorImp , public LeakChecked { public: - PeerDoorImp (Service& parent, Kind kind, std::string const& ip, int port, + PeerDoorImp (Stoppable& parent, Kind kind, std::string const& ip, int port, boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context) : PeerDoor (parent) , m_kind (kind) @@ -93,7 +93,7 @@ public: //-------------------------------------------------------------------------- - void onServiceStop () + void onStop () { { boost::system::error_code ec; @@ -105,7 +105,7 @@ public: mAcceptor.cancel (ec); } - serviceStopped (); + stopped (); } private: @@ -117,14 +117,14 @@ private: //------------------------------------------------------------------------------ -PeerDoor::PeerDoor (Service& parent) +PeerDoor::PeerDoor (Stoppable& parent) : AsyncService ("PeerDoor", parent) { } //------------------------------------------------------------------------------ -PeerDoor* PeerDoor::New (Service& parent, Kind kind, std::string const& ip, int port, +PeerDoor* PeerDoor::New (Stoppable& parent, Kind kind, std::string const& ip, int port, boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context) { return new PeerDoorImp (parent, kind, ip, port, io_service, ssl_context); diff --git a/src/ripple_app/peers/PeerDoor.h b/src/ripple_app/peers/PeerDoor.h index 597b4cb590..c89982c466 100644 --- a/src/ripple_app/peers/PeerDoor.h +++ b/src/ripple_app/peers/PeerDoor.h @@ -11,7 +11,7 @@ class PeerDoor : public AsyncService { protected: - explicit PeerDoor (Service& parent); + explicit PeerDoor (Stoppable& parent); public: virtual ~PeerDoor () { } @@ -22,7 +22,7 @@ public: sslAndPROXYRequired }; - static PeerDoor* New (Service& parent, Kind kind, std::string const& ip, int port, + static PeerDoor* New (Stoppable& parent, Kind kind, std::string const& ip, int port, boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context); //virtual boost::asio::ssl::context& getSSLContext () = 0; diff --git a/src/ripple_app/peers/Peers.cpp b/src/ripple_app/peers/Peers.cpp index b3e778488b..c97f48593c 100644 --- a/src/ripple_app/peers/Peers.cpp +++ b/src/ripple_app/peers/Peers.cpp @@ -8,7 +8,7 @@ SETUP_LOG (Peers) class PeersImp : public Peers - , public Service + , public Stoppable , public LeakChecked { public: @@ -19,10 +19,10 @@ public: policyIntervalSeconds = 5 }; - PeersImp (Service& parent, + PeersImp (Stoppable& parent, boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context) - : Service ("Peers", parent) + : Stoppable ("Peers", parent) , m_io_service (io_service) , m_ssl_context (ssl_context) , mPeerLock (this, "PeersImp", __FILE__, __LINE__) @@ -911,7 +911,7 @@ void PeersImp::scanRefresh () //------------------------------------------------------------------------------ -Peers* Peers::New (Service& parent, +Peers* Peers::New (Stoppable& parent, boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context) { diff --git a/src/ripple_app/peers/Peers.h b/src/ripple_app/peers/Peers.h index 5021f9f001..93ec05f395 100644 --- a/src/ripple_app/peers/Peers.h +++ b/src/ripple_app/peers/Peers.h @@ -12,7 +12,7 @@ class Peers { public: - static Peers* New (Service& parent, + static Peers* New (Stoppable& parent, boost::asio::io_service& io_service, boost::asio::ssl::context& context); diff --git a/src/ripple_app/peers/UniqueNodeList.cpp b/src/ripple_app/peers/UniqueNodeList.cpp index 4b6e07a94f..0dadeb9cbc 100644 --- a/src/ripple_app/peers/UniqueNodeList.cpp +++ b/src/ripple_app/peers/UniqueNodeList.cpp @@ -89,7 +89,7 @@ private: typedef boost::unordered_map, score> epScore; public: - explicit UniqueNodeListImp (Service& parent) + explicit UniqueNodeListImp (Stoppable& parent) : UniqueNodeList (parent) , mFetchLock (this, "Fetch", __FILE__, __LINE__) , mUNLLock (this, "UNL", __FILE__, __LINE__) @@ -101,12 +101,12 @@ public: //-------------------------------------------------------------------------- - void onServiceStop () + void onStop () { m_fetchTimer.cancel (); m_scoreTimer.cancel (); - serviceStopped (); + stopped (); } //-------------------------------------------------------------------------- @@ -2084,14 +2084,14 @@ private: //------------------------------------------------------------------------------ -UniqueNodeList::UniqueNodeList (Service& parent) - : Service ("UniqueNodeList", parent) +UniqueNodeList::UniqueNodeList (Stoppable& parent) + : Stoppable ("UniqueNodeList", parent) { } //------------------------------------------------------------------------------ -UniqueNodeList* UniqueNodeList::New (Service& parent) +UniqueNodeList* UniqueNodeList::New (Stoppable& parent) { return new UniqueNodeListImp (parent); } diff --git a/src/ripple_app/peers/UniqueNodeList.h b/src/ripple_app/peers/UniqueNodeList.h index 257e45cb31..63085e0dd4 100644 --- a/src/ripple_app/peers/UniqueNodeList.h +++ b/src/ripple_app/peers/UniqueNodeList.h @@ -7,10 +7,10 @@ #ifndef RIPPLE_UNIQUENODELIST_H_INCLUDED #define RIPPLE_UNIQUENODELIST_H_INCLUDED -class UniqueNodeList : public Service +class UniqueNodeList : public Stoppable { protected: - explicit UniqueNodeList (Service& parent); + explicit UniqueNodeList (Stoppable& parent); public: enum ValidatorSource @@ -29,7 +29,7 @@ public: public: // VFALCO TODO make this not use boost::asio... - static UniqueNodeList* New (Service& parent); + static UniqueNodeList* New (Stoppable& parent); virtual ~UniqueNodeList () { } diff --git a/src/ripple_app/ripple_app.cpp b/src/ripple_app/ripple_app.cpp index 8922bd6525..25ae98f931 100644 --- a/src/ripple_app/ripple_app.cpp +++ b/src/ripple_app/ripple_app.cpp @@ -30,8 +30,8 @@ namespace ripple // Application // -# include "main/NodeStoreSchedulerService.h" -#include "main/NodeStoreSchedulerService.cpp" +# include "main/NodeStoreScheduler.h" +#include "main/NodeStoreScheduler.cpp" # include "main/IoServicePool.h" #include "main/IoServicePool.cpp" diff --git a/src/ripple_app/rpc/RPCHandler.cpp b/src/ripple_app/rpc/RPCHandler.cpp index 106e03472a..c60c1c2ce7 100644 --- a/src/ripple_app/rpc/RPCHandler.cpp +++ b/src/ripple_app/rpc/RPCHandler.cpp @@ -2739,7 +2739,7 @@ Json::Value RPCHandler::doSMS (Json::Value params, LoadType* loadType, Applicati } Json::Value RPCHandler::doStop (Json::Value, LoadType* loadType, Application::ScopedLockType& masterLockHolder) { - getApp().stop (); + getApp().signalStop (); return SYSTEM_NAME " server stopping"; } diff --git a/src/ripple_app/websocket/WSDoor.cpp b/src/ripple_app/websocket/WSDoor.cpp index 0b28e5f3d9..da5c2a5e84 100644 --- a/src/ripple_app/websocket/WSDoor.cpp +++ b/src/ripple_app/websocket/WSDoor.cpp @@ -95,10 +95,10 @@ private: m_endpoint = nullptr; } - serviceStopped (); + stopped (); } - void onServiceStop () + void onStop () { { ScopedLockType lock (m_endpointLock, __FILE__, __LINE__); @@ -129,8 +129,8 @@ private: //------------------------------------------------------------------------------ -WSDoor::WSDoor (Service& parent) - : Service ("WSDoor", parent) +WSDoor::WSDoor (Stoppable& parent) + : Stoppable ("WSDoor", parent) { } diff --git a/src/ripple_app/websocket/WSDoor.h b/src/ripple_app/websocket/WSDoor.h index 61bd39308e..166a52fe2e 100644 --- a/src/ripple_app/websocket/WSDoor.h +++ b/src/ripple_app/websocket/WSDoor.h @@ -8,10 +8,10 @@ #define RIPPLE_WSDOOR_RIPPLEHEADER /** Handles accepting incoming WebSocket connections. */ -class WSDoor : public Service +class WSDoor : public Stoppable { protected: - explicit WSDoor (Service& parent); + explicit WSDoor (Stoppable& parent); public: virtual ~WSDoor () { } diff --git a/src/ripple_core/functional/JobQueue.cpp b/src/ripple_core/functional/JobQueue.cpp index f0a09d1759..7704bd017b 100644 --- a/src/ripple_core/functional/JobQueue.cpp +++ b/src/ripple_core/functional/JobQueue.cpp @@ -54,13 +54,13 @@ public: //-------------------------------------------------------------------------- - JobQueueImp (Service& parent, Journal journal) + JobQueueImp (Stoppable& parent, Journal journal) : JobQueue ("JobQueue", parent) , m_journal (journal) , m_lastJob (0) , m_processCount (0) , m_workers (*this, "JobQueue", 0) - , m_cancelCallback (boost::bind (&Service::isServiceStopping, this)) + , m_cancelCallback (boost::bind (&Stoppable::isStopping, this)) { { ScopedLock lock (m_mutex); @@ -107,13 +107,13 @@ public: // do not add jobs to a queue with no threads bassert (type == jtCLIENT || m_workers.getNumberOfThreads () > 0); - // If this goes off it means that a child didn't follow the Service API rules. - bassert (! isServiceStopped() && ! areServiceChildrenStopped()); + // If this goes off it means that a child didn't follow the Stoppable API rules. + bassert (! isStopped() && ! areChildrenStopped()); // Don't even add it to the queue if we're stopping // and the job type is marked for skipOnStop. // - if (isServiceStopping() && skipOnStop (type)) + if (isStopping() && skipOnStop (type)) { m_journal.debug << "Skipping addJob ('" << name << "')"; @@ -331,16 +331,16 @@ private: // We are stopped when all of the following are true: // // 1. A stop notification was received - // 2. All Service children have stopped + // 2. All Stoppable children have stopped // 3. There are no executing calls to processTask // 4. There are no remaining Jobs in the job set // - if (isServiceStopping() && - areServiceChildrenStopped() && + if (isStopping() && + areChildrenStopped() && (m_processCount == 0) && m_jobSet.empty()) { - serviceStopped(); + stopped(); } } @@ -500,7 +500,7 @@ private: // Skip the job if we are stopping and the // skipOnStop flag is set for the job type // - if (!isServiceStopping() || !skipOnStop (type)) + if (!isStopping() || !skipOnStop (type)) { Thread::setCurrentThreadName (name); m_journal.trace << "Doing " << name << " job"; @@ -633,7 +633,7 @@ private: //-------------------------------------------------------------------------- - void onServiceStop () + void onStop () { // VFALCO NOTE I wanted to remove all the jobs that are skippable // but then the Workers count of tasks to process @@ -685,7 +685,7 @@ private: */ } - void onServiceChildrenStopped () + void onChildrenStopped () { ScopedLock lock (m_mutex); @@ -695,14 +695,14 @@ private: //------------------------------------------------------------------------------ -JobQueue::JobQueue (char const* name, Service& parent) - : Service (name, parent) +JobQueue::JobQueue (char const* name, Stoppable& parent) + : Stoppable (name, parent) { } //------------------------------------------------------------------------------ -JobQueue* JobQueue::New (Service& parent, Journal journal) +JobQueue* JobQueue::New (Stoppable& parent, Journal journal) { return new JobQueueImp (parent, journal); } diff --git a/src/ripple_core/functional/JobQueue.h b/src/ripple_core/functional/JobQueue.h index 83352b9653..202b466918 100644 --- a/src/ripple_core/functional/JobQueue.h +++ b/src/ripple_core/functional/JobQueue.h @@ -7,13 +7,13 @@ #ifndef RIPPLE_CORE_JOBQUEUE_H_INCLUDED #define RIPPLE_CORE_JOBQUEUE_H_INCLUDED -class JobQueue : public Service +class JobQueue : public Stoppable { protected: - JobQueue (char const* name, Service& parent); + JobQueue (char const* name, Stoppable& parent); public: - static JobQueue* New (Service& parent, Journal journal); + static JobQueue* New (Stoppable& parent, Journal journal); virtual ~JobQueue () { } diff --git a/src/ripple_net/basics/AsyncService.cpp b/src/ripple_net/basics/AsyncService.cpp index 7a7a4255f8..41f3fa2dd0 100644 --- a/src/ripple_net/basics/AsyncService.cpp +++ b/src/ripple_net/basics/AsyncService.cpp @@ -4,8 +4,8 @@ */ //============================================================================== -AsyncService::AsyncService (char const* name, Service& parent) - : Service (name, parent) +AsyncService::AsyncService (char const* name, Stoppable& parent) + : Stoppable (name, parent) { } @@ -37,5 +37,5 @@ bool AsyncService::serviceCountIoComplete (boost::system::error_code const& ec) void AsyncService::onServiceIoComplete () { - //serviceStopped(); + //stopped(); } diff --git a/src/ripple_net/basics/AsyncService.h b/src/ripple_net/basics/AsyncService.h index 5813770d62..9140585148 100644 --- a/src/ripple_net/basics/AsyncService.h +++ b/src/ripple_net/basics/AsyncService.h @@ -7,12 +7,12 @@ #ifndef RIPPLE_NET_ASYNCSERVICE_H_INCLUDED #define RIPPLE_NET_ASYNCSERVICE_H_INCLUDED -/** Service subclass that helps with managing asynchronous stopping. */ -class AsyncService : public Service +/** Stoppable subclass that helps with managing asynchronous stopping. */ +class AsyncService : public Stoppable { public: /** Create the service with the specified name and parent. */ - AsyncService (char const* name, Service& parent); + AsyncService (char const* name, Stoppable& parent); ~AsyncService (); @@ -40,8 +40,8 @@ public: bool serviceCountIoComplete (boost::system::error_code const& ec); /** Called after a stop notification when all pending I/O is complete. - The default implementation calls serviceStopped. - @see serviceStopped + The default implementation calls stopped. + @see stopped */ virtual void onServiceIoComplete (); diff --git a/src/ripple_net/basics/SNTPClient.cpp b/src/ripple_net/basics/SNTPClient.cpp index 5932241155..12d56f7e90 100644 --- a/src/ripple_net/basics/SNTPClient.cpp +++ b/src/ripple_net/basics/SNTPClient.cpp @@ -61,7 +61,7 @@ public: //-------------------------------------------------------------------------- - explicit SNTPClientImp (Service& parent) + explicit SNTPClientImp (Stoppable& parent) : SNTPClient (parent) , Thread ("SNTPClient") , mLock (this, "SNTPClient", __FILE__, __LINE__) @@ -97,10 +97,10 @@ public: { m_io_service.run (); - serviceStopped (); + stopped (); } - void onServiceStop () + void onStop () { // HACK! m_io_service.stop (); @@ -345,14 +345,14 @@ private: //------------------------------------------------------------------------------ -SNTPClient::SNTPClient (Service& parent) +SNTPClient::SNTPClient (Stoppable& parent) : AsyncService ("SNTPClient", parent) { } //------------------------------------------------------------------------------ -SNTPClient* SNTPClient::New (Service& parent) +SNTPClient* SNTPClient::New (Stoppable& parent) { return new SNTPClientImp (parent); } diff --git a/src/ripple_net/basics/SNTPClient.h b/src/ripple_net/basics/SNTPClient.h index 98ee8228da..559147f44a 100644 --- a/src/ripple_net/basics/SNTPClient.h +++ b/src/ripple_net/basics/SNTPClient.h @@ -10,10 +10,10 @@ class SNTPClient : public AsyncService { protected: - explicit SNTPClient (Service& parent); + explicit SNTPClient (Stoppable& parent); public: - static SNTPClient* New (Service& parent); + static SNTPClient* New (Stoppable& parent); virtual ~SNTPClient() { } virtual void init (std::vector const& servers) = 0; virtual void addServer (std::string const& mServer) = 0; diff --git a/src/ripple_net/rpc/InfoSub.cpp b/src/ripple_net/rpc/InfoSub.cpp index 4e5ac39df3..43f49ed9ff 100644 --- a/src/ripple_net/rpc/InfoSub.cpp +++ b/src/ripple_net/rpc/InfoSub.cpp @@ -17,8 +17,8 @@ //------------------------------------------------------------------------------ -InfoSub::Source::Source (char const* name, Service& parent) - : Service (name, parent) +InfoSub::Source::Source (char const* name, Stoppable& parent) + : Stoppable (name, parent) { } diff --git a/src/ripple_net/rpc/InfoSub.h b/src/ripple_net/rpc/InfoSub.h index 5007344764..f8db0ecdad 100644 --- a/src/ripple_net/rpc/InfoSub.h +++ b/src/ripple_net/rpc/InfoSub.h @@ -30,10 +30,10 @@ public: public: /** Abstracts the source of subscription data. */ - class Source : public Service + class Source : public Stoppable { protected: - Source (char const* name, Service& parent); + Source (char const* name, Stoppable& parent); public: // VFALCO TODO Rename the 'rt' parameters to something meaningful.