mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
Rename to Stoppable
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</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)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">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)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</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)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
@@ -1500,7 +1500,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\ripple\frame\api\RPCService.h" />
|
<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\frame\ripple_frame.h" />
|
||||||
<ClInclude Include="..\..\src\ripple\json\api\json_config.h" />
|
<ClInclude Include="..\..\src\ripple\json\api\json_config.h" />
|
||||||
<ClInclude Include="..\..\src\ripple\json\api\json_features.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\LedgerHistory.h" />
|
||||||
<ClInclude Include="..\..\src\ripple_app\ledger\SerializedValidation.h" />
|
<ClInclude Include="..\..\src\ripple_app\ledger\SerializedValidation.h" />
|
||||||
<ClInclude Include="..\..\src\ripple_app\main\IoServicePool.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\ParameterTable.h" />
|
||||||
<ClInclude Include="..\..\src\ripple_app\main\Application.h" />
|
<ClInclude Include="..\..\src\ripple_app\main\Application.h" />
|
||||||
<ClInclude Include="..\..\src\ripple_app\main\FatalErrorReporter.h" />
|
<ClInclude Include="..\..\src\ripple_app\main\FatalErrorReporter.h" />
|
||||||
|
|||||||
@@ -924,9 +924,6 @@
|
|||||||
<ClCompile Include="..\..\src\ripple\frame\ripple_frame.cpp">
|
<ClCompile Include="..\..\src\ripple\frame\ripple_frame.cpp">
|
||||||
<Filter>[1] Ripple\frame</Filter>
|
<Filter>[1] Ripple\frame</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\ripple\frame\api\Service.cpp">
|
|
||||||
<Filter>[1] Ripple\frame\api</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\ripple_core\nodestore\NodeStore.cpp">
|
<ClCompile Include="..\..\src\ripple_core\nodestore\NodeStore.cpp">
|
||||||
<Filter>[2] Old Ripple\ripple_core\nodestore</Filter>
|
<Filter>[2] Old Ripple\ripple_core\nodestore</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -978,15 +975,18 @@
|
|||||||
<ClCompile Include="..\..\src\ripple_core\nodestore\impl\DummyScheduler.cpp">
|
<ClCompile Include="..\..\src\ripple_core\nodestore\impl\DummyScheduler.cpp">
|
||||||
<Filter>[2] Old Ripple\ripple_core\nodestore\impl</Filter>
|
<Filter>[2] Old Ripple\ripple_core\nodestore\impl</Filter>
|
||||||
</ClCompile>
|
</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">
|
<ClCompile Include="..\..\src\ripple_app\node\SqliteFactory.cpp">
|
||||||
<Filter>[2] Old Ripple\ripple_app\node</Filter>
|
<Filter>[2] Old Ripple\ripple_app\node</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\ripple\frame\api\RPCService.cpp">
|
<ClCompile Include="..\..\src\ripple\frame\api\RPCService.cpp">
|
||||||
<Filter>[1] Ripple\frame\api</Filter>
|
<Filter>[1] Ripple\frame\api</Filter>
|
||||||
</ClCompile>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\ripple_basics\containers\KeyCache.h">
|
<ClInclude Include="..\..\src\ripple_basics\containers\KeyCache.h">
|
||||||
@@ -1869,9 +1869,6 @@
|
|||||||
<ClInclude Include="..\..\src\ripple\frame\ripple_frame.h">
|
<ClInclude Include="..\..\src\ripple\frame\ripple_frame.h">
|
||||||
<Filter>[1] Ripple\frame</Filter>
|
<Filter>[1] Ripple\frame</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\ripple\frame\api\Service.h">
|
|
||||||
<Filter>[1] Ripple\frame\api</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\ripple_core\nodestore\NodeStore.h">
|
<ClInclude Include="..\..\src\ripple_core\nodestore\NodeStore.h">
|
||||||
<Filter>[2] Old Ripple\ripple_core\nodestore</Filter>
|
<Filter>[2] Old Ripple\ripple_core\nodestore</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -1938,9 +1935,6 @@
|
|||||||
<ClInclude Include="..\..\src\ripple_core\nodestore\impl\DatabaseImp.h">
|
<ClInclude Include="..\..\src\ripple_core\nodestore\impl\DatabaseImp.h">
|
||||||
<Filter>[2] Old Ripple\ripple_core\nodestore\impl</Filter>
|
<Filter>[2] Old Ripple\ripple_core\nodestore\impl</Filter>
|
||||||
</ClInclude>
|
</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">
|
<ClInclude Include="..\..\src\ripple_core\nodestore\api\Task.h">
|
||||||
<Filter>[2] Old Ripple\ripple_core\nodestore\api</Filter>
|
<Filter>[2] Old Ripple\ripple_core\nodestore\api</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -1950,6 +1944,12 @@
|
|||||||
<ClInclude Include="..\..\src\ripple\frame\api\RPCService.h">
|
<ClInclude Include="..\..\src\ripple\frame\api\RPCService.h">
|
||||||
<Filter>[1] Ripple\frame\api</Filter>
|
<Filter>[1] Ripple\frame\api</Filter>
|
||||||
</ClInclude>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto">
|
<CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto">
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -7,48 +7,38 @@
|
|||||||
namespace ripple
|
namespace ripple
|
||||||
{
|
{
|
||||||
|
|
||||||
Service::Service (char const* name)
|
Stoppable::Stoppable (char const* name, Stoppable& parent)
|
||||||
: m_name (name)
|
: m_name (name)
|
||||||
, m_root (true)
|
, m_root (false)
|
||||||
, m_child (this)
|
, m_child (this)
|
||||||
, m_calledServiceStop (false)
|
, m_calledStop (false)
|
||||||
, m_stopped (false)
|
, m_stopped (false)
|
||||||
, m_childrenStopped (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_name (name)
|
||||||
, m_root (parent != nullptr)
|
, m_root (parent == nullptr)
|
||||||
, m_child (this)
|
, m_child (this)
|
||||||
, m_calledServiceStop (false)
|
, m_calledStop (false)
|
||||||
, m_stopped (false)
|
, m_stopped (false)
|
||||||
, m_childrenStopped (false)
|
, m_childrenStopped (false)
|
||||||
{
|
{
|
||||||
if (parent != nullptr)
|
if (parent != nullptr)
|
||||||
{
|
{
|
||||||
// must not have had stop called
|
// must not have had stop called
|
||||||
bassert (! parent->isServiceStopping());
|
bassert (! parent->isStopping());
|
||||||
|
|
||||||
parent->m_children.push_front (&m_child);
|
parent->m_children.push_front (&m_child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Service::Service (char const* name, Service& parent)
|
Stoppable::~Stoppable ()
|
||||||
: 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 ()
|
|
||||||
{
|
{
|
||||||
// must be stopped
|
// must be stopped
|
||||||
bassert (m_stopped);
|
bassert (m_stopped);
|
||||||
@@ -57,69 +47,64 @@ Service::~Service ()
|
|||||||
bassert (m_childrenStopped);
|
bassert (m_childrenStopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* Service::serviceName () const
|
void Stoppable::stop (Journal::Stream stream)
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Service::serviceStop (Journal::Stream stream)
|
|
||||||
{
|
{
|
||||||
// may only be called once
|
// may only be called once
|
||||||
if (m_calledServiceStop)
|
if (m_calledStop)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_calledServiceStop = true;
|
m_calledStop = true;
|
||||||
|
|
||||||
// must be called from a root service
|
// must be called from a root stoppable
|
||||||
bassert (m_root);
|
bassert (m_root);
|
||||||
|
|
||||||
// send the notification
|
// 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);
|
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);
|
bassert (m_root);
|
||||||
|
|
||||||
stopAsyncRecursive ();
|
stopAsyncRecursive ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Service::isServiceStopping ()
|
bool Stoppable::isStopping ()
|
||||||
{
|
{
|
||||||
return m_calledStopAsync.get() != 0;
|
return m_calledStopAsync.get() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Service::isServiceStopped ()
|
bool Stoppable::isStopped ()
|
||||||
{
|
{
|
||||||
return m_stopped;
|
return m_stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Service::areServiceChildrenStopped ()
|
bool Stoppable::areChildrenStopped ()
|
||||||
{
|
{
|
||||||
return m_childrenStopped;
|
return m_childrenStopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::serviceStopped ()
|
void Stoppable::stopped ()
|
||||||
{
|
{
|
||||||
m_stoppedEvent.signal();
|
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
|
// make sure we only do this once
|
||||||
if (m_root)
|
if (m_root)
|
||||||
@@ -136,27 +121,27 @@ void Service::stopAsyncRecursive ()
|
|||||||
m_calledStopAsync.set (1);
|
m_calledStopAsync.set (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify this service
|
// notify this stoppable
|
||||||
onServiceStop ();
|
onStop ();
|
||||||
|
|
||||||
// notify children
|
// notify children
|
||||||
for (Children::const_iterator iter (m_children.cbegin ());
|
for (Children::const_iterator iter (m_children.cbegin ());
|
||||||
iter != m_children.cend(); ++iter)
|
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
|
// hierarchy as a tree with the root at the top, we will block
|
||||||
// first on leaves, and then at each successivly higher level.
|
// first on leaves, and then at each successivly higher level.
|
||||||
//
|
//
|
||||||
for (Children::const_iterator iter (m_children.cbegin ());
|
for (Children::const_iterator iter (m_children.cbegin ());
|
||||||
iter != m_children.cend(); ++iter)
|
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
|
// 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;
|
m_childrenStopped = true;
|
||||||
|
|
||||||
// Notify derived class that children have stopped.
|
// 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.
|
// if that times out we report to the Journal and then do an infinite wait.
|
||||||
//
|
//
|
||||||
bool const timedOut (! m_stoppedEvent.wait (1 * 1000)); // milliseconds
|
bool const timedOut (! m_stoppedEvent.wait (1 * 1000)); // milliseconds
|
||||||
if (timedOut)
|
if (timedOut)
|
||||||
{
|
{
|
||||||
stream << "Service: Waiting for '" << serviceName() << "' to stop";
|
stream << "Waiting for '" << m_name << "' to stop";
|
||||||
m_stoppedEvent.wait ();
|
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;
|
m_stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
260
src/ripple/frame/api/Stoppable.h
Normal file
260
src/ripple/frame/api/Stoppable.h
Normal 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
|
||||||
@@ -14,4 +14,4 @@
|
|||||||
#include "ripple_frame.h"
|
#include "ripple_frame.h"
|
||||||
|
|
||||||
#include "api/RPCService.cpp"
|
#include "api/RPCService.cpp"
|
||||||
#include "api/Service.cpp"
|
#include "api/Stoppable.cpp"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "../json/ripple_json.h"
|
#include "../json/ripple_json.h"
|
||||||
|
|
||||||
|
#include "api/Stoppable.h"
|
||||||
#include "api/RPCService.h"
|
#include "api/RPCService.h"
|
||||||
#include "api/Service.h"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Manager : public RPCService
|
|||||||
public:
|
public:
|
||||||
/** Create a new Manager object.
|
/** Create a new Manager object.
|
||||||
*/
|
*/
|
||||||
static Manager* New (Service& parent, Journal journal);
|
static Manager* New (Stoppable& parent, Journal journal);
|
||||||
|
|
||||||
/** Destroy the object.
|
/** Destroy the object.
|
||||||
|
|
||||||
|
|||||||
@@ -89,14 +89,14 @@ namespace Validators
|
|||||||
|
|
||||||
class ManagerImp
|
class ManagerImp
|
||||||
: public Manager
|
: public Manager
|
||||||
, public Service
|
, public Stoppable
|
||||||
, public ThreadWithCallQueue::EntryPoints
|
, public ThreadWithCallQueue::EntryPoints
|
||||||
, public DeadlineTimer::Listener
|
, public DeadlineTimer::Listener
|
||||||
, public LeakChecked <ManagerImp>
|
, public LeakChecked <ManagerImp>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ManagerImp (Service& parent, Journal journal)
|
ManagerImp (Stoppable& parent, Journal journal)
|
||||||
: Service ("Validators::Manager", parent)
|
: Stoppable ("Validators::Manager", parent)
|
||||||
, m_store (journal)
|
, m_store (journal)
|
||||||
, m_logic (m_store, journal)
|
, m_logic (m_store, journal)
|
||||||
, m_journal (journal)
|
, m_journal (journal)
|
||||||
@@ -115,10 +115,10 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Service
|
// Stoppable
|
||||||
//
|
//
|
||||||
|
|
||||||
void onServiceStop ()
|
void onStop ()
|
||||||
{
|
{
|
||||||
m_thread.stop (false);
|
m_thread.stop (false);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ public:
|
|||||||
void threadExit ()
|
void threadExit ()
|
||||||
{
|
{
|
||||||
// must come last
|
// must come last
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool threadIdle ()
|
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);
|
return new Validators::ManagerImp (parent, journal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair;
|
typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair;
|
||||||
|
|
||||||
InboundLedgers::InboundLedgers (Service& parent)
|
InboundLedgers::InboundLedgers (Stoppable& parent)
|
||||||
: Service ("InboundLedgers", parent)
|
: Stoppable ("InboundLedgers", parent)
|
||||||
, mLock (this, "InboundLedger", __FILE__, __LINE__)
|
, mLock (this, "InboundLedger", __FILE__, __LINE__)
|
||||||
, mRecentFailures ("LedgerAcquireRecentFailures", 0, kReacquireIntervalSeconds)
|
, mRecentFailures ("LedgerAcquireRecentFailures", 0, kReacquireIntervalSeconds)
|
||||||
{
|
{
|
||||||
@@ -21,7 +21,7 @@ InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 s
|
|||||||
{
|
{
|
||||||
ScopedLockType sl (mLock, __FILE__, __LINE__);
|
ScopedLockType sl (mLock, __FILE__, __LINE__);
|
||||||
|
|
||||||
if (! isServiceStopping ())
|
if (! isStopping ())
|
||||||
{
|
{
|
||||||
boost::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
|
boost::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
|
||||||
if (it != mLedgers.end ())
|
if (it != mLedgers.end ())
|
||||||
@@ -352,12 +352,12 @@ Json::Value InboundLedgers::getInfo()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InboundLedgers::onServiceStop ()
|
void InboundLedgers::onStop ()
|
||||||
{
|
{
|
||||||
ScopedLockType lock (mLock, __FILE__, __LINE__);
|
ScopedLockType lock (mLock, __FILE__, __LINE__);
|
||||||
|
|
||||||
mLedgers.clear();
|
mLedgers.clear();
|
||||||
mRecentFailures.clear();
|
mRecentFailures.clear();
|
||||||
|
|
||||||
serviceStopped();
|
stopped();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,14 @@
|
|||||||
// VFALCO TODO Rename to InboundLedgers
|
// VFALCO TODO Rename to InboundLedgers
|
||||||
// VFALCO TODO Create abstract interface
|
// VFALCO TODO Create abstract interface
|
||||||
class InboundLedgers
|
class InboundLedgers
|
||||||
: public Service
|
: public Stoppable
|
||||||
, public LeakChecked <InboundLedger>
|
, public LeakChecked <InboundLedger>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// How long before we try again to acquire the same ledger
|
// How long before we try again to acquire the same ledger
|
||||||
static const int kReacquireIntervalSeconds = 300;
|
static const int kReacquireIntervalSeconds = 300;
|
||||||
|
|
||||||
explicit InboundLedgers (Service& parent);
|
explicit InboundLedgers (Stoppable& parent);
|
||||||
|
|
||||||
// VFALCO TODO Should this be called findOrAdd ?
|
// VFALCO TODO Should this be called findOrAdd ?
|
||||||
//
|
//
|
||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
void gotFetchPack (Job&);
|
void gotFetchPack (Job&);
|
||||||
void sweep ();
|
void sweep ();
|
||||||
|
|
||||||
void onServiceStop ();
|
void onStop ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef boost::unordered_map <uint256, InboundLedger::pointer> MapType;
|
typedef boost::unordered_map <uint256, InboundLedger::pointer> MapType;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
// It sounds like this holds all the ledgers...
|
// It sounds like this holds all the ledgers...
|
||||||
//
|
//
|
||||||
class LedgerMaster
|
class LedgerMaster
|
||||||
: public Service
|
: public Stoppable
|
||||||
, public LeakChecked <LedgerMaster>
|
, public LeakChecked <LedgerMaster>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -25,8 +25,8 @@ public:
|
|||||||
typedef RippleRecursiveMutex LockType;
|
typedef RippleRecursiveMutex LockType;
|
||||||
typedef LockType::ScopedLockType ScopedLockType;
|
typedef LockType::ScopedLockType ScopedLockType;
|
||||||
|
|
||||||
explicit LedgerMaster (Service& parent)
|
explicit LedgerMaster (Stoppable& parent)
|
||||||
: Service ("LedgerMaster", parent)
|
: Stoppable ("LedgerMaster", parent)
|
||||||
, mLock (this, "LedgerMaster", __FILE__, __LINE__)
|
, mLock (this, "LedgerMaster", __FILE__, __LINE__)
|
||||||
, mHeldTransactions (uint256 ())
|
, mHeldTransactions (uint256 ())
|
||||||
, mMinValidations (0)
|
, mMinValidations (0)
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
SETUP_LOG (OrderBookDB)
|
SETUP_LOG (OrderBookDB)
|
||||||
|
|
||||||
OrderBookDB::OrderBookDB (Service& parent)
|
OrderBookDB::OrderBookDB (Stoppable& parent)
|
||||||
: Service ("OrderBookDB", parent)
|
: Stoppable ("OrderBookDB", parent)
|
||||||
, mLock (this, "OrderBookDB", __FILE__, __LINE__)
|
, mLock (this, "OrderBookDB", __FILE__, __LINE__)
|
||||||
, mSeq (0)
|
, mSeq (0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,11 +46,11 @@ private:
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
class OrderBookDB
|
class OrderBookDB
|
||||||
: public Service
|
: public Stoppable
|
||||||
, public LeakChecked <OrderBookDB>
|
, public LeakChecked <OrderBookDB>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit OrderBookDB (Service& parent);
|
explicit OrderBookDB (Stoppable& parent);
|
||||||
|
|
||||||
void setup (Ledger::ref ledger);
|
void setup (Ledger::ref ledger);
|
||||||
void update (Ledger::pointer ledger);
|
void update (Ledger::pointer ledger);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ template <> char const* LogPartition::getPartitionName <RPCServiceManagerLog> ()
|
|||||||
// VFALCO TODO Move the function definitions into the class declaration
|
// VFALCO TODO Move the function definitions into the class declaration
|
||||||
class ApplicationImp
|
class ApplicationImp
|
||||||
: public Application
|
: public Application
|
||||||
, public Service
|
, public Stoppable
|
||||||
, public DeadlineTimer::Listener
|
, public DeadlineTimer::Listener
|
||||||
, LeakChecked <ApplicationImp>
|
, LeakChecked <ApplicationImp>
|
||||||
, PeerFinder::Callback
|
, PeerFinder::Callback
|
||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
ApplicationImp ()
|
ApplicationImp ()
|
||||||
: Service ("Application")
|
: Stoppable ("Application")
|
||||||
, m_journal (LogJournal::get <ApplicationLog> ())
|
, m_journal (LogJournal::get <ApplicationLog> ())
|
||||||
, m_tempNodeCache ("NodeCache", 16384, 90)
|
, m_tempNodeCache ("NodeCache", 16384, 90)
|
||||||
, m_sleCache ("LedgerEntryCache", 4096, 120)
|
, m_sleCache ("LedgerEntryCache", 4096, 120)
|
||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
LogJournal::get <RPCServiceManagerLog> ()))
|
LogJournal::get <RPCServiceManagerLog> ()))
|
||||||
|
|
||||||
// The JobQueue has to come pretty early since
|
// 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> ()))
|
, m_jobQueue (JobQueue::New (*this, LogJournal::get <JobQueueLog> ()))
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ public:
|
|||||||
|
|
||||||
~ApplicationImp ()
|
~ApplicationImp ()
|
||||||
{
|
{
|
||||||
serviceStop();
|
stop();
|
||||||
//stop ();
|
//stop ();
|
||||||
|
|
||||||
// Why is this needed here?
|
// Why is this needed here?
|
||||||
@@ -429,7 +429,8 @@ public:
|
|||||||
|
|
||||||
if (!loadOldLedger (getConfig ().START_LEDGER, getConfig ().START_UP == Config::REPLAY))
|
if (!loadOldLedger (getConfig ().START_LEDGER, getConfig ().START_UP == Config::REPLAY))
|
||||||
{
|
{
|
||||||
getApp().stop ();
|
// wtf?
|
||||||
|
getApp().signalStop ();
|
||||||
exit (-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -618,10 +619,10 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Service
|
// Stoppable
|
||||||
|
|
||||||
// Called to indicate shutdown.
|
// Called to indicate shutdown.
|
||||||
void onServiceStop ()
|
void onStop ()
|
||||||
{
|
{
|
||||||
m_sweepTimer.cancel();
|
m_sweepTimer.cancel();
|
||||||
|
|
||||||
@@ -630,7 +631,7 @@ public:
|
|||||||
mValidations->flush ();
|
mValidations->flush ();
|
||||||
mShutdown = false;
|
mShutdown = false;
|
||||||
|
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -667,7 +668,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Stop the server. When this returns, all
|
// Stop the server. When this returns, all
|
||||||
// Service objects should be stopped.
|
// Stoppable objects should be stopped.
|
||||||
|
|
||||||
doStop ();
|
doStop ();
|
||||||
|
|
||||||
@@ -697,10 +698,10 @@ public:
|
|||||||
m_journal.info << "Received shutdown request";
|
m_journal.info << "Received shutdown request";
|
||||||
StopSustain ();
|
StopSustain ();
|
||||||
|
|
||||||
serviceStop (m_journal.warning);
|
stop (m_journal.warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop ()
|
void signalStop ()
|
||||||
{
|
{
|
||||||
// Unblock the main thread (which is sitting in run()).
|
// Unblock the main thread (which is sitting in run()).
|
||||||
//
|
//
|
||||||
@@ -720,7 +721,7 @@ public:
|
|||||||
if (space.available < (512 * 1024 * 1024))
|
if (space.available < (512 * 1024 * 1024))
|
||||||
{
|
{
|
||||||
m_journal.fatal << "Remaining free disk space is less than 512MB";
|
m_journal.fatal << "Remaining free disk space is less than 512MB";
|
||||||
getApp().stop ();
|
getApp().signalStop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_jobQueue->addJob(jtSWEEP, "sweep",
|
m_jobQueue->addJob(jtSWEEP, "sweep",
|
||||||
@@ -781,7 +782,7 @@ private:
|
|||||||
Journal m_journal;
|
Journal m_journal;
|
||||||
Application::LockType m_masterMutex;
|
Application::LockType m_masterMutex;
|
||||||
|
|
||||||
// These are not Service-derived
|
// These are not Stoppable-derived
|
||||||
NodeCache m_tempNodeCache;
|
NodeCache m_tempNodeCache;
|
||||||
SLECache m_sleCache;
|
SLECache m_sleCache;
|
||||||
LocalCredentials m_localCredentials;
|
LocalCredentials m_localCredentials;
|
||||||
@@ -789,7 +790,7 @@ private:
|
|||||||
|
|
||||||
ScopedPointer <RPCService::Manager> m_rpcServiceManager;
|
ScopedPointer <RPCService::Manager> m_rpcServiceManager;
|
||||||
|
|
||||||
// These are Service-related
|
// These are Stoppable-related
|
||||||
ScopedPointer <JobQueue> m_jobQueue;
|
ScopedPointer <JobQueue> m_jobQueue;
|
||||||
IoServicePool m_mainIoPool;
|
IoServicePool m_mainIoPool;
|
||||||
OrderBookDB m_orderBookDB;
|
OrderBookDB m_orderBookDB;
|
||||||
@@ -797,7 +798,7 @@ private:
|
|||||||
ScopedPointer <NetworkOPs> m_networkOPs;
|
ScopedPointer <NetworkOPs> m_networkOPs;
|
||||||
ScopedPointer <UniqueNodeList> m_deprecatedUNL;
|
ScopedPointer <UniqueNodeList> m_deprecatedUNL;
|
||||||
RPCServerHandler m_rpcServerHandler;
|
RPCServerHandler m_rpcServerHandler;
|
||||||
NodeStoreSchedulerService m_nodeStoreScheduler;
|
NodeStoreScheduler m_nodeStoreScheduler;
|
||||||
ScopedPointer <NodeStore::Database> m_nodeStore;
|
ScopedPointer <NodeStore::Database> m_nodeStore;
|
||||||
ScopedPointer <SNTPClient> m_sntpClient;
|
ScopedPointer <SNTPClient> m_sntpClient;
|
||||||
InboundLedgers m_inboundLedgers;
|
InboundLedgers m_inboundLedgers;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public:
|
|||||||
virtual bool running () = 0;
|
virtual bool running () = 0;
|
||||||
virtual void setup () = 0;
|
virtual void setup () = 0;
|
||||||
virtual void run () = 0;
|
virtual void run () = 0;
|
||||||
virtual void stop () = 0;
|
virtual void signalStop () = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Application& getApp ();
|
extern Application& getApp ();
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ private:
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
IoServicePool::IoServicePool (Service& parent, String const& name, int numberOfThreads)
|
IoServicePool::IoServicePool (Stoppable& parent, String const& name, int numberOfThreads)
|
||||||
: Service (name.toStdString().c_str(), parent)
|
: Stoppable (name.toStdString().c_str(), parent)
|
||||||
, m_name (name)
|
, m_name (name)
|
||||||
, m_service (numberOfThreads)
|
, m_service (numberOfThreads)
|
||||||
, m_work (boost::ref (m_service))
|
, m_work (boost::ref (m_service))
|
||||||
@@ -76,7 +76,7 @@ IoServicePool::operator boost::asio::io_service& ()
|
|||||||
return m_service;
|
return m_service;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IoServicePool::onServiceStop ()
|
void IoServicePool::onStop ()
|
||||||
{
|
{
|
||||||
// VFALCO NOTE This is a hack! We should gracefully
|
// VFALCO NOTE This is a hack! We should gracefully
|
||||||
// cancel all pending I/O, and delete the work
|
// cancel all pending I/O, and delete the work
|
||||||
@@ -86,7 +86,7 @@ void IoServicePool::onServiceStop ()
|
|||||||
m_service.stop ();
|
m_service.stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IoServicePool::onServiceChildrenStopped ()
|
void IoServicePool::onChildrenStopped ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ void IoServicePool::onServiceChildrenStopped ()
|
|||||||
void IoServicePool::onThreadExit()
|
void IoServicePool::onThreadExit()
|
||||||
{
|
{
|
||||||
// service must be stopping for threads to exit.
|
// service must be stopping for threads to exit.
|
||||||
bassert (isServiceStopping());
|
bassert (isStopping());
|
||||||
|
|
||||||
// must have at least count 1
|
// must have at least count 1
|
||||||
bassert (m_threadsRunning.get() > 0);
|
bassert (m_threadsRunning.get() > 0);
|
||||||
@@ -103,6 +103,6 @@ void IoServicePool::onThreadExit()
|
|||||||
if (--m_threadsRunning == 0)
|
if (--m_threadsRunning == 0)
|
||||||
{
|
{
|
||||||
// last thread just exited
|
// last thread just exited
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,17 @@
|
|||||||
#define RIPPLE_APP_IOSERVICEPOOL_H_INCLUDED
|
#define RIPPLE_APP_IOSERVICEPOOL_H_INCLUDED
|
||||||
|
|
||||||
/** An io_service with an associated group of threads. */
|
/** An io_service with an associated group of threads. */
|
||||||
class IoServicePool : public Service
|
class IoServicePool : public Stoppable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IoServicePool (Service& parent, String const& name, int numberOfThreads);
|
IoServicePool (Stoppable& parent, String const& name, int numberOfThreads);
|
||||||
~IoServicePool ();
|
~IoServicePool ();
|
||||||
|
|
||||||
boost::asio::io_service& getService ();
|
boost::asio::io_service& getService ();
|
||||||
operator boost::asio::io_service& ();
|
operator boost::asio::io_service& ();
|
||||||
|
|
||||||
void onServiceStop ();
|
void onStop ();
|
||||||
void onServiceChildrenStopped ();
|
void onChildrenStopped ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class ServiceThread;
|
class ServiceThread;
|
||||||
|
|||||||
39
src/ripple_app/main/NodeStoreScheduler.cpp
Normal file
39
src/ripple_app/main/NodeStoreScheduler.cpp
Normal 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();
|
||||||
|
}
|
||||||
@@ -4,19 +4,19 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#ifndef RIPPLE_APP_NODESTORESCHEDULERSERVICE_H_INCLUDED
|
#ifndef RIPPLE_APP_NODESTORESCHEDULER_H_INCLUDED
|
||||||
#define RIPPLE_APP_NODESTORESCHEDULERSERVICE_H_INCLUDED
|
#define RIPPLE_APP_NODESTORESCHEDULER_H_INCLUDED
|
||||||
|
|
||||||
/** A NodeStore::Scheduler which uses the JobQueue and implements the Service API. */
|
/** A NodeStore::Scheduler which uses the JobQueue and implements the Stoppable API. */
|
||||||
class NodeStoreSchedulerService
|
class NodeStoreScheduler
|
||||||
: public NodeStore::Scheduler
|
: public NodeStore::Scheduler
|
||||||
, public Service
|
, public Stoppable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NodeStoreSchedulerService (Service& parent, JobQueue& jobQueue);
|
NodeStoreScheduler (Stoppable& parent, JobQueue& jobQueue);
|
||||||
|
|
||||||
void onServiceStop ();
|
void onStop ();
|
||||||
void onServiceChildrenStopped ();
|
void onChildrenStopped ();
|
||||||
void scheduleTask (NodeStore::Task& task);
|
void scheduleTask (NodeStore::Task& task);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
// VFALCO TODO Make LedgerMaster a SharedPtr or a reference.
|
// 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)
|
: NetworkOPs (parent)
|
||||||
, m_journal (journal)
|
, m_journal (journal)
|
||||||
, mLock (this, "NetOPs", __FILE__, __LINE__)
|
, mLock (this, "NetOPs", __FILE__, __LINE__)
|
||||||
@@ -360,14 +360,14 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Service
|
// Stoppable
|
||||||
|
|
||||||
void onServiceStop ()
|
void onStop ()
|
||||||
{
|
{
|
||||||
m_heartbeatTimer.cancel();
|
m_heartbeatTimer.cancel();
|
||||||
m_clusterTimer.cancel();
|
m_clusterTimer.cancel();
|
||||||
|
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -3075,7 +3075,7 @@ void NetworkOPsImp::missingNodeInLedger (uint32 seq)
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
NetworkOPs::NetworkOPs (Service& parent)
|
NetworkOPs::NetworkOPs (Stoppable& parent)
|
||||||
: InfoSub::Source ("NetworkOPs", parent)
|
: InfoSub::Source ("NetworkOPs", parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -3083,7 +3083,7 @@ NetworkOPs::NetworkOPs (Service& parent)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
NetworkOPs* NetworkOPs::New (LedgerMaster& ledgerMaster,
|
NetworkOPs* NetworkOPs::New (LedgerMaster& ledgerMaster,
|
||||||
Service& parent, Journal journal)
|
Stoppable& parent, Journal journal)
|
||||||
{
|
{
|
||||||
ScopedPointer <NetworkOPs> object (new NetworkOPsImp (
|
ScopedPointer <NetworkOPs> object (new NetworkOPsImp (
|
||||||
ledgerMaster, parent, journal));
|
ledgerMaster, parent, journal));
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class NetworkOPs
|
|||||||
: public InfoSub::Source
|
: public InfoSub::Source
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
explicit NetworkOPs (Service& parent);
|
explicit NetworkOPs (Stoppable& parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Fault
|
enum Fault
|
||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
// VFALCO TODO Make LedgerMaster a SharedPtr or a reference.
|
// VFALCO TODO Make LedgerMaster a SharedPtr or a reference.
|
||||||
//
|
//
|
||||||
static NetworkOPs* New (LedgerMaster& ledgerMaster,
|
static NetworkOPs* New (LedgerMaster& ledgerMaster,
|
||||||
Service& parent, Journal journal);
|
Stoppable& parent, Journal journal);
|
||||||
|
|
||||||
virtual ~NetworkOPs () { }
|
virtual ~NetworkOPs () { }
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class PeerDoorImp
|
|||||||
, public LeakChecked <PeerDoorImp>
|
, public LeakChecked <PeerDoorImp>
|
||||||
{
|
{
|
||||||
public:
|
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)
|
boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context)
|
||||||
: PeerDoor (parent)
|
: PeerDoor (parent)
|
||||||
, m_kind (kind)
|
, m_kind (kind)
|
||||||
@@ -93,7 +93,7 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void onServiceStop ()
|
void onStop ()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
@@ -105,7 +105,7 @@ public:
|
|||||||
mAcceptor.cancel (ec);
|
mAcceptor.cancel (ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -117,14 +117,14 @@ private:
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
PeerDoor::PeerDoor (Service& parent)
|
PeerDoor::PeerDoor (Stoppable& parent)
|
||||||
: AsyncService ("PeerDoor", 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)
|
boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context)
|
||||||
{
|
{
|
||||||
return new PeerDoorImp (parent, kind, ip, port, io_service, ssl_context);
|
return new PeerDoorImp (parent, kind, ip, port, io_service, ssl_context);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
class PeerDoor : public AsyncService
|
class PeerDoor : public AsyncService
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
explicit PeerDoor (Service& parent);
|
explicit PeerDoor (Stoppable& parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~PeerDoor () { }
|
virtual ~PeerDoor () { }
|
||||||
@@ -22,7 +22,7 @@ public:
|
|||||||
sslAndPROXYRequired
|
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);
|
boost::asio::io_service& io_service, boost::asio::ssl::context& ssl_context);
|
||||||
|
|
||||||
//virtual boost::asio::ssl::context& getSSLContext () = 0;
|
//virtual boost::asio::ssl::context& getSSLContext () = 0;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ SETUP_LOG (Peers)
|
|||||||
|
|
||||||
class PeersImp
|
class PeersImp
|
||||||
: public Peers
|
: public Peers
|
||||||
, public Service
|
, public Stoppable
|
||||||
, public LeakChecked <PeersImp>
|
, public LeakChecked <PeersImp>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,10 +19,10 @@ public:
|
|||||||
policyIntervalSeconds = 5
|
policyIntervalSeconds = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
PeersImp (Service& parent,
|
PeersImp (Stoppable& parent,
|
||||||
boost::asio::io_service& io_service,
|
boost::asio::io_service& io_service,
|
||||||
boost::asio::ssl::context& ssl_context)
|
boost::asio::ssl::context& ssl_context)
|
||||||
: Service ("Peers", parent)
|
: Stoppable ("Peers", parent)
|
||||||
, m_io_service (io_service)
|
, m_io_service (io_service)
|
||||||
, m_ssl_context (ssl_context)
|
, m_ssl_context (ssl_context)
|
||||||
, mPeerLock (this, "PeersImp", __FILE__, __LINE__)
|
, 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::io_service& io_service,
|
||||||
boost::asio::ssl::context& ssl_context)
|
boost::asio::ssl::context& ssl_context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
class Peers
|
class Peers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Peers* New (Service& parent,
|
static Peers* New (Stoppable& parent,
|
||||||
boost::asio::io_service& io_service,
|
boost::asio::io_service& io_service,
|
||||||
boost::asio::ssl::context& context);
|
boost::asio::ssl::context& context);
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ private:
|
|||||||
typedef boost::unordered_map<std::pair< std::string, int>, score> epScore;
|
typedef boost::unordered_map<std::pair< std::string, int>, score> epScore;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UniqueNodeListImp (Service& parent)
|
explicit UniqueNodeListImp (Stoppable& parent)
|
||||||
: UniqueNodeList (parent)
|
: UniqueNodeList (parent)
|
||||||
, mFetchLock (this, "Fetch", __FILE__, __LINE__)
|
, mFetchLock (this, "Fetch", __FILE__, __LINE__)
|
||||||
, mUNLLock (this, "UNL", __FILE__, __LINE__)
|
, mUNLLock (this, "UNL", __FILE__, __LINE__)
|
||||||
@@ -101,12 +101,12 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void onServiceStop ()
|
void onStop ()
|
||||||
{
|
{
|
||||||
m_fetchTimer.cancel ();
|
m_fetchTimer.cancel ();
|
||||||
m_scoreTimer.cancel ();
|
m_scoreTimer.cancel ();
|
||||||
|
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@@ -2084,14 +2084,14 @@ private:
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
UniqueNodeList::UniqueNodeList (Service& parent)
|
UniqueNodeList::UniqueNodeList (Stoppable& parent)
|
||||||
: Service ("UniqueNodeList", parent)
|
: Stoppable ("UniqueNodeList", parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
UniqueNodeList* UniqueNodeList::New (Service& parent)
|
UniqueNodeList* UniqueNodeList::New (Stoppable& parent)
|
||||||
{
|
{
|
||||||
return new UniqueNodeListImp (parent);
|
return new UniqueNodeListImp (parent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
#ifndef RIPPLE_UNIQUENODELIST_H_INCLUDED
|
#ifndef RIPPLE_UNIQUENODELIST_H_INCLUDED
|
||||||
#define RIPPLE_UNIQUENODELIST_H_INCLUDED
|
#define RIPPLE_UNIQUENODELIST_H_INCLUDED
|
||||||
|
|
||||||
class UniqueNodeList : public Service
|
class UniqueNodeList : public Stoppable
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
explicit UniqueNodeList (Service& parent);
|
explicit UniqueNodeList (Stoppable& parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ValidatorSource
|
enum ValidatorSource
|
||||||
@@ -29,7 +29,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// VFALCO TODO make this not use boost::asio...
|
// VFALCO TODO make this not use boost::asio...
|
||||||
static UniqueNodeList* New (Service& parent);
|
static UniqueNodeList* New (Stoppable& parent);
|
||||||
|
|
||||||
virtual ~UniqueNodeList () { }
|
virtual ~UniqueNodeList () { }
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ namespace ripple
|
|||||||
// Application
|
// Application
|
||||||
//
|
//
|
||||||
|
|
||||||
# include "main/NodeStoreSchedulerService.h"
|
# include "main/NodeStoreScheduler.h"
|
||||||
#include "main/NodeStoreSchedulerService.cpp"
|
#include "main/NodeStoreScheduler.cpp"
|
||||||
|
|
||||||
# include "main/IoServicePool.h"
|
# include "main/IoServicePool.h"
|
||||||
#include "main/IoServicePool.cpp"
|
#include "main/IoServicePool.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)
|
Json::Value RPCHandler::doStop (Json::Value, LoadType* loadType, Application::ScopedLockType& masterLockHolder)
|
||||||
{
|
{
|
||||||
getApp().stop ();
|
getApp().signalStop ();
|
||||||
|
|
||||||
return SYSTEM_NAME " server stopping";
|
return SYSTEM_NAME " server stopping";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,10 +95,10 @@ private:
|
|||||||
m_endpoint = nullptr;
|
m_endpoint = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onServiceStop ()
|
void onStop ()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
ScopedLockType lock (m_endpointLock, __FILE__, __LINE__);
|
ScopedLockType lock (m_endpointLock, __FILE__, __LINE__);
|
||||||
@@ -129,8 +129,8 @@ private:
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
WSDoor::WSDoor (Service& parent)
|
WSDoor::WSDoor (Stoppable& parent)
|
||||||
: Service ("WSDoor", parent)
|
: Stoppable ("WSDoor", parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,10 @@
|
|||||||
#define RIPPLE_WSDOOR_RIPPLEHEADER
|
#define RIPPLE_WSDOOR_RIPPLEHEADER
|
||||||
|
|
||||||
/** Handles accepting incoming WebSocket connections. */
|
/** Handles accepting incoming WebSocket connections. */
|
||||||
class WSDoor : public Service
|
class WSDoor : public Stoppable
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
explicit WSDoor (Service& parent);
|
explicit WSDoor (Stoppable& parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~WSDoor () { }
|
virtual ~WSDoor () { }
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
JobQueueImp (Service& parent, Journal journal)
|
JobQueueImp (Stoppable& parent, Journal journal)
|
||||||
: JobQueue ("JobQueue", parent)
|
: JobQueue ("JobQueue", parent)
|
||||||
, m_journal (journal)
|
, m_journal (journal)
|
||||||
, m_lastJob (0)
|
, m_lastJob (0)
|
||||||
, m_processCount (0)
|
, m_processCount (0)
|
||||||
, m_workers (*this, "JobQueue", 0)
|
, m_workers (*this, "JobQueue", 0)
|
||||||
, m_cancelCallback (boost::bind (&Service::isServiceStopping, this))
|
, m_cancelCallback (boost::bind (&Stoppable::isStopping, this))
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
ScopedLock lock (m_mutex);
|
ScopedLock lock (m_mutex);
|
||||||
@@ -107,13 +107,13 @@ public:
|
|||||||
// do not add jobs to a queue with no threads
|
// do not add jobs to a queue with no threads
|
||||||
bassert (type == jtCLIENT || m_workers.getNumberOfThreads () > 0);
|
bassert (type == jtCLIENT || m_workers.getNumberOfThreads () > 0);
|
||||||
|
|
||||||
// If this goes off it means that a child didn't follow the Service API rules.
|
// If this goes off it means that a child didn't follow the Stoppable API rules.
|
||||||
bassert (! isServiceStopped() && ! areServiceChildrenStopped());
|
bassert (! isStopped() && ! areChildrenStopped());
|
||||||
|
|
||||||
// Don't even add it to the queue if we're stopping
|
// Don't even add it to the queue if we're stopping
|
||||||
// and the job type is marked for skipOnStop.
|
// and the job type is marked for skipOnStop.
|
||||||
//
|
//
|
||||||
if (isServiceStopping() && skipOnStop (type))
|
if (isStopping() && skipOnStop (type))
|
||||||
{
|
{
|
||||||
m_journal.debug <<
|
m_journal.debug <<
|
||||||
"Skipping addJob ('" << name << "')";
|
"Skipping addJob ('" << name << "')";
|
||||||
@@ -331,16 +331,16 @@ private:
|
|||||||
// We are stopped when all of the following are true:
|
// We are stopped when all of the following are true:
|
||||||
//
|
//
|
||||||
// 1. A stop notification was received
|
// 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
|
// 3. There are no executing calls to processTask
|
||||||
// 4. There are no remaining Jobs in the job set
|
// 4. There are no remaining Jobs in the job set
|
||||||
//
|
//
|
||||||
if (isServiceStopping() &&
|
if (isStopping() &&
|
||||||
areServiceChildrenStopped() &&
|
areChildrenStopped() &&
|
||||||
(m_processCount == 0) &&
|
(m_processCount == 0) &&
|
||||||
m_jobSet.empty())
|
m_jobSet.empty())
|
||||||
{
|
{
|
||||||
serviceStopped();
|
stopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,7 +500,7 @@ private:
|
|||||||
// Skip the job if we are stopping and the
|
// Skip the job if we are stopping and the
|
||||||
// skipOnStop flag is set for the job type
|
// skipOnStop flag is set for the job type
|
||||||
//
|
//
|
||||||
if (!isServiceStopping() || !skipOnStop (type))
|
if (!isStopping() || !skipOnStop (type))
|
||||||
{
|
{
|
||||||
Thread::setCurrentThreadName (name);
|
Thread::setCurrentThreadName (name);
|
||||||
m_journal.trace << "Doing " << name << " job";
|
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
|
// VFALCO NOTE I wanted to remove all the jobs that are skippable
|
||||||
// but then the Workers count of tasks to process
|
// but then the Workers count of tasks to process
|
||||||
@@ -685,7 +685,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void onServiceChildrenStopped ()
|
void onChildrenStopped ()
|
||||||
{
|
{
|
||||||
ScopedLock lock (m_mutex);
|
ScopedLock lock (m_mutex);
|
||||||
|
|
||||||
@@ -695,14 +695,14 @@ private:
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
JobQueue::JobQueue (char const* name, Service& parent)
|
JobQueue::JobQueue (char const* name, Stoppable& parent)
|
||||||
: Service (name, parent)
|
: Stoppable (name, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
JobQueue* JobQueue::New (Service& parent, Journal journal)
|
JobQueue* JobQueue::New (Stoppable& parent, Journal journal)
|
||||||
{
|
{
|
||||||
return new JobQueueImp (parent, journal);
|
return new JobQueueImp (parent, journal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
#ifndef RIPPLE_CORE_JOBQUEUE_H_INCLUDED
|
#ifndef RIPPLE_CORE_JOBQUEUE_H_INCLUDED
|
||||||
#define RIPPLE_CORE_JOBQUEUE_H_INCLUDED
|
#define RIPPLE_CORE_JOBQUEUE_H_INCLUDED
|
||||||
|
|
||||||
class JobQueue : public Service
|
class JobQueue : public Stoppable
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
JobQueue (char const* name, Service& parent);
|
JobQueue (char const* name, Stoppable& parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static JobQueue* New (Service& parent, Journal journal);
|
static JobQueue* New (Stoppable& parent, Journal journal);
|
||||||
|
|
||||||
virtual ~JobQueue () { }
|
virtual ~JobQueue () { }
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
AsyncService::AsyncService (char const* name, Service& parent)
|
AsyncService::AsyncService (char const* name, Stoppable& parent)
|
||||||
: Service (name, parent)
|
: Stoppable (name, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,5 +37,5 @@ bool AsyncService::serviceCountIoComplete (boost::system::error_code const& ec)
|
|||||||
|
|
||||||
void AsyncService::onServiceIoComplete ()
|
void AsyncService::onServiceIoComplete ()
|
||||||
{
|
{
|
||||||
//serviceStopped();
|
//stopped();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,12 @@
|
|||||||
#ifndef RIPPLE_NET_ASYNCSERVICE_H_INCLUDED
|
#ifndef RIPPLE_NET_ASYNCSERVICE_H_INCLUDED
|
||||||
#define RIPPLE_NET_ASYNCSERVICE_H_INCLUDED
|
#define RIPPLE_NET_ASYNCSERVICE_H_INCLUDED
|
||||||
|
|
||||||
/** Service subclass that helps with managing asynchronous stopping. */
|
/** Stoppable subclass that helps with managing asynchronous stopping. */
|
||||||
class AsyncService : public Service
|
class AsyncService : public Stoppable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** Create the service with the specified name and parent. */
|
/** Create the service with the specified name and parent. */
|
||||||
AsyncService (char const* name, Service& parent);
|
AsyncService (char const* name, Stoppable& parent);
|
||||||
|
|
||||||
~AsyncService ();
|
~AsyncService ();
|
||||||
|
|
||||||
@@ -40,8 +40,8 @@ public:
|
|||||||
bool serviceCountIoComplete (boost::system::error_code const& ec);
|
bool serviceCountIoComplete (boost::system::error_code const& ec);
|
||||||
|
|
||||||
/** Called after a stop notification when all pending I/O is complete.
|
/** Called after a stop notification when all pending I/O is complete.
|
||||||
The default implementation calls serviceStopped.
|
The default implementation calls stopped.
|
||||||
@see serviceStopped
|
@see stopped
|
||||||
*/
|
*/
|
||||||
virtual void onServiceIoComplete ();
|
virtual void onServiceIoComplete ();
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
explicit SNTPClientImp (Service& parent)
|
explicit SNTPClientImp (Stoppable& parent)
|
||||||
: SNTPClient (parent)
|
: SNTPClient (parent)
|
||||||
, Thread ("SNTPClient")
|
, Thread ("SNTPClient")
|
||||||
, mLock (this, "SNTPClient", __FILE__, __LINE__)
|
, mLock (this, "SNTPClient", __FILE__, __LINE__)
|
||||||
@@ -97,10 +97,10 @@ public:
|
|||||||
{
|
{
|
||||||
m_io_service.run ();
|
m_io_service.run ();
|
||||||
|
|
||||||
serviceStopped ();
|
stopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onServiceStop ()
|
void onStop ()
|
||||||
{
|
{
|
||||||
// HACK!
|
// HACK!
|
||||||
m_io_service.stop ();
|
m_io_service.stop ();
|
||||||
@@ -345,14 +345,14 @@ private:
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
SNTPClient::SNTPClient (Service& parent)
|
SNTPClient::SNTPClient (Stoppable& parent)
|
||||||
: AsyncService ("SNTPClient", parent)
|
: AsyncService ("SNTPClient", parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
SNTPClient* SNTPClient::New (Service& parent)
|
SNTPClient* SNTPClient::New (Stoppable& parent)
|
||||||
{
|
{
|
||||||
return new SNTPClientImp (parent);
|
return new SNTPClientImp (parent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
class SNTPClient : public AsyncService
|
class SNTPClient : public AsyncService
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
explicit SNTPClient (Service& parent);
|
explicit SNTPClient (Stoppable& parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static SNTPClient* New (Service& parent);
|
static SNTPClient* New (Stoppable& parent);
|
||||||
virtual ~SNTPClient() { }
|
virtual ~SNTPClient() { }
|
||||||
virtual void init (std::vector <std::string> const& servers) = 0;
|
virtual void init (std::vector <std::string> const& servers) = 0;
|
||||||
virtual void addServer (std::string const& mServer) = 0;
|
virtual void addServer (std::string const& mServer) = 0;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
InfoSub::Source::Source (char const* name, Service& parent)
|
InfoSub::Source::Source (char const* name, Stoppable& parent)
|
||||||
: Service (name, parent)
|
: Stoppable (name, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ public:
|
|||||||
public:
|
public:
|
||||||
/** Abstracts the source of subscription data.
|
/** Abstracts the source of subscription data.
|
||||||
*/
|
*/
|
||||||
class Source : public Service
|
class Source : public Stoppable
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
Source (char const* name, Service& parent);
|
Source (char const* name, Stoppable& parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// VFALCO TODO Rename the 'rt' parameters to something meaningful.
|
// VFALCO TODO Rename the 'rt' parameters to something meaningful.
|
||||||
|
|||||||
Reference in New Issue
Block a user