Rename to Stoppable

This commit is contained in:
Vinnie Falco
2013-09-21 17:11:17 -07:00
parent ec6ee6f3bd
commit ec6c09d995
41 changed files with 488 additions and 510 deletions

View File

@@ -28,7 +28,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\frame\api\Service.cpp">
<ClCompile Include="..\..\src\ripple\frame\api\Stoppable.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -249,7 +249,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple_app\main\NodeStoreSchedulerService.cpp">
<ClCompile Include="..\..\src\ripple_app\main\NodeStoreScheduler.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -1500,7 +1500,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ripple\frame\api\RPCService.h" />
<ClInclude Include="..\..\src\ripple\frame\api\Service.h" />
<ClInclude Include="..\..\src\ripple\frame\api\Stoppable.h" />
<ClInclude Include="..\..\src\ripple\frame\ripple_frame.h" />
<ClInclude Include="..\..\src\ripple\json\api\json_config.h" />
<ClInclude Include="..\..\src\ripple\json\api\json_features.h" />
@@ -1560,7 +1560,7 @@
<ClInclude Include="..\..\src\ripple_app\ledger\LedgerHistory.h" />
<ClInclude Include="..\..\src\ripple_app\ledger\SerializedValidation.h" />
<ClInclude Include="..\..\src\ripple_app\main\IoServicePool.h" />
<ClInclude Include="..\..\src\ripple_app\main\NodeStoreSchedulerService.h" />
<ClInclude Include="..\..\src\ripple_app\main\NodeStoreScheduler.h" />
<ClInclude Include="..\..\src\ripple_app\main\ParameterTable.h" />
<ClInclude Include="..\..\src\ripple_app\main\Application.h" />
<ClInclude Include="..\..\src\ripple_app\main\FatalErrorReporter.h" />

View File

@@ -924,9 +924,6 @@
<ClCompile Include="..\..\src\ripple\frame\ripple_frame.cpp">
<Filter>[1] Ripple\frame</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\frame\api\Service.cpp">
<Filter>[1] Ripple\frame\api</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_core\nodestore\NodeStore.cpp">
<Filter>[2] Old Ripple\ripple_core\nodestore</Filter>
</ClCompile>
@@ -978,15 +975,18 @@
<ClCompile Include="..\..\src\ripple_core\nodestore\impl\DummyScheduler.cpp">
<Filter>[2] Old Ripple\ripple_core\nodestore\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_app\main\NodeStoreSchedulerService.cpp">
<Filter>[2] Old Ripple\ripple_app\main</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_app\node\SqliteFactory.cpp">
<Filter>[2] Old Ripple\ripple_app\node</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\frame\api\RPCService.cpp">
<Filter>[1] Ripple\frame\api</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_app\main\NodeStoreScheduler.cpp">
<Filter>[2] Old Ripple\ripple_app\main</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\frame\api\Stoppable.cpp">
<Filter>[1] Ripple\frame\api</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ripple_basics\containers\KeyCache.h">
@@ -1869,9 +1869,6 @@
<ClInclude Include="..\..\src\ripple\frame\ripple_frame.h">
<Filter>[1] Ripple\frame</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\frame\api\Service.h">
<Filter>[1] Ripple\frame\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_core\nodestore\NodeStore.h">
<Filter>[2] Old Ripple\ripple_core\nodestore</Filter>
</ClInclude>
@@ -1938,9 +1935,6 @@
<ClInclude Include="..\..\src\ripple_core\nodestore\impl\DatabaseImp.h">
<Filter>[2] Old Ripple\ripple_core\nodestore\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_app\main\NodeStoreSchedulerService.h">
<Filter>[2] Old Ripple\ripple_app\main</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_core\nodestore\api\Task.h">
<Filter>[2] Old Ripple\ripple_core\nodestore\api</Filter>
</ClInclude>
@@ -1950,6 +1944,12 @@
<ClInclude Include="..\..\src\ripple\frame\api\RPCService.h">
<Filter>[1] Ripple\frame\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_app\main\NodeStoreScheduler.h">
<Filter>[2] Old Ripple\ripple_app\main</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\frame\api\Stoppable.h">
<Filter>[1] Ripple\frame\api</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto">

View File

@@ -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 <Child> 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 <int> 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

View File

@@ -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;
}

View File

@@ -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 <Child> 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 <int> 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

View File

@@ -14,4 +14,4 @@
#include "ripple_frame.h"
#include "api/RPCService.cpp"
#include "api/Service.cpp"
#include "api/Stoppable.cpp"

View File

@@ -11,7 +11,7 @@
#include "../json/ripple_json.h"
#include "api/Stoppable.h"
#include "api/RPCService.h"
#include "api/Service.h"
#endif

View File

@@ -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.

View File

@@ -89,14 +89,14 @@ namespace Validators
class ManagerImp
: public Manager
, public Service
, public Stoppable
, public ThreadWithCallQueue::EntryPoints
, public DeadlineTimer::Listener
, public LeakChecked <ManagerImp>
{
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);
}

View File

@@ -6,8 +6,8 @@
typedef std::pair<uint256, InboundLedger::pointer> 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<uint256, InboundLedger::pointer>::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();
}

View File

@@ -14,14 +14,14 @@
// VFALCO TODO Rename to InboundLedgers
// VFALCO TODO Create abstract interface
class InboundLedgers
: public Service
: public Stoppable
, public LeakChecked <InboundLedger>
{
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 <uint256, InboundLedger::pointer> MapType;

View File

@@ -15,7 +15,7 @@
// It sounds like this holds all the ledgers...
//
class LedgerMaster
: public Service
: public Stoppable
, public LeakChecked <LedgerMaster>
{
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)

View File

@@ -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)
{

View File

@@ -46,11 +46,11 @@ private:
//------------------------------------------------------------------------------
class OrderBookDB
: public Service
: public Stoppable
, public LeakChecked <OrderBookDB>
{
public:
explicit OrderBookDB (Service& parent);
explicit OrderBookDB (Stoppable& parent);
void setup (Ledger::ref ledger);
void update (Ledger::pointer ledger);

View File

@@ -31,7 +31,7 @@ template <> char const* LogPartition::getPartitionName <RPCServiceManagerLog> ()
// VFALCO TODO Move the function definitions into the class declaration
class ApplicationImp
: public Application
, public Service
, public Stoppable
, public DeadlineTimer::Listener
, LeakChecked <ApplicationImp>
, PeerFinder::Callback
@@ -49,7 +49,7 @@ public:
//--------------------------------------------------------------------------
ApplicationImp ()
: Service ("Application")
: Stoppable ("Application")
, m_journal (LogJournal::get <ApplicationLog> ())
, m_tempNodeCache ("NodeCache", 16384, 90)
, m_sleCache ("LedgerEntryCache", 4096, 120)
@@ -58,7 +58,7 @@ public:
LogJournal::get <RPCServiceManagerLog> ()))
// 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 <JobQueueLog> ()))
@@ -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 <RPCService::Manager> m_rpcServiceManager;
// These are Service-related
// These are Stoppable-related
ScopedPointer <JobQueue> m_jobQueue;
IoServicePool m_mainIoPool;
OrderBookDB m_orderBookDB;
@@ -797,7 +798,7 @@ private:
ScopedPointer <NetworkOPs> m_networkOPs;
ScopedPointer <UniqueNodeList> m_deprecatedUNL;
RPCServerHandler m_rpcServerHandler;
NodeStoreSchedulerService m_nodeStoreScheduler;
NodeStoreScheduler m_nodeStoreScheduler;
ScopedPointer <NodeStore::Database> m_nodeStore;
ScopedPointer <SNTPClient> m_sntpClient;
InboundLedgers m_inboundLedgers;

View File

@@ -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 ();

View File

@@ -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 ();
}
}

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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:

View File

@@ -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();
}

View File

@@ -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 <NetworkOPs> object (new NetworkOPsImp (
ledgerMaster, parent, journal));

View File

@@ -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 () { }

View File

@@ -11,7 +11,7 @@ class PeerDoorImp
, public LeakChecked <PeerDoorImp>
{
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);

View File

@@ -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;

View File

@@ -8,7 +8,7 @@ SETUP_LOG (Peers)
class PeersImp
: public Peers
, public Service
, public Stoppable
, public LeakChecked <PeersImp>
{
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)
{

View File

@@ -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);

View File

@@ -89,7 +89,7 @@ private:
typedef boost::unordered_map<std::pair< std::string, int>, 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);
}

View File

@@ -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 () { }

View File

@@ -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"

View File

@@ -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";
}

View File

@@ -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)
{
}

View File

@@ -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 () { }

View File

@@ -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);
}

View File

@@ -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 () { }

View File

@@ -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();
}

View File

@@ -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 ();

View File

@@ -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);
}

View File

@@ -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 <std::string> const& servers) = 0;
virtual void addServer (std::string const& mServer) = 0;

View File

@@ -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)
{
}

View File

@@ -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.