Split LoadEvent to a new file

This commit is contained in:
Vinnie Falco
2013-06-03 07:39:49 -07:00
parent 32a3024ce4
commit 3f3c76ab7e
7 changed files with 93 additions and 51 deletions

View File

@@ -74,6 +74,8 @@
#include "src/cpp/database/SqliteDatabase.h"
#include "src/cpp/ripple/ripple_LoadEvent.h"
#include "src/cpp/ripple/AcceptedLedger.h"
#include "src/cpp/ripple/AccountItems.h"
#include "src/cpp/ripple/AccountSetTransactor.h"
@@ -266,6 +268,10 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
//------------------------------------------------------------------------------
// Refactored sources
#include "src/cpp/ripple/ripple_LoadEvent.cpp"
// Implementation of interfaces
#include "src/cpp/ripple/ripple_Features.cpp"

View File

@@ -980,6 +980,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_LoadEvent.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>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_LoadFeeTrack.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -1632,7 +1638,6 @@
<ClInclude Include="src\cpp\ripple\LoadManager.h" />
<ClInclude Include="src\cpp\ripple\LoadMonitor.h" />
<ClInclude Include="src\cpp\ripple\NetworkOPs.h" />
<ClInclude Include="src\cpp\ripple\NetworkStatus.h" />
<ClInclude Include="src\cpp\ripple\NicknameState.h" />
<ClInclude Include="src\cpp\ripple\Offer.h" />
<ClInclude Include="src\cpp\ripple\OfferCancelTransactor.h" />
@@ -1658,6 +1663,7 @@
<ClInclude Include="src\cpp\ripple\ripple_ILoadFeeTrack.h" />
<ClInclude Include="src\cpp\ripple\ripple_IUniqueNodeList.h" />
<ClInclude Include="src\cpp\ripple\ripple_IValidations.h" />
<ClInclude Include="src\cpp\ripple\ripple_LoadEvent.h" />
<ClInclude Include="src\cpp\ripple\RPC.h" />
<ClInclude Include="src\cpp\ripple\RPCDoor.h" />
<ClInclude Include="src\cpp\ripple\RPCErr.h" />

View File

@@ -801,6 +801,9 @@
<ClCompile Include="src\cpp\ripple\ripple_Features.cpp">
<Filter>1. Modules\ripple_main\processing</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_LoadEvent.cpp">
<Filter>1. Modules\ripple_main\main</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="database\sqlite3ext.h">
@@ -1448,9 +1451,6 @@
<ClInclude Include="src\cpp\ripple\LoadMonitor.h">
<Filter>1. Modules\ripple_main\main</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\NetworkStatus.h">
<Filter>1. Modules\ripple_main\main</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\Version.h">
<Filter>1. Modules\ripple_main\main</Filter>
</ClInclude>
@@ -1484,6 +1484,9 @@
<ClInclude Include="src\cpp\ripple\ripple_IHashRouter.h">
<Filter>1. Modules\ripple_main\sockets</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_LoadEvent.h">
<Filter>1. Modules\ripple_main\main</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="SConstruct" />

View File

@@ -1022,6 +1022,7 @@ void LedgerConsensus::playbackProposals()
}
}
// VFALCO: TODO, clean these macros up and put them somewhere. Try to eliminate them if possible.
#define LCAT_SUCCESS 0
#define LCAT_FAIL 1
#define LCAT_RETRY 2
@@ -1040,6 +1041,7 @@ int LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTrans
<< (retryAssured ? "/retry" : "/final");
WriteLog (lsTRACE, LedgerConsensus) << txn->getJson(0);
// VFALCO: TODO, figure out what this "trust network" is all about and why it needs exceptions.
#ifndef TRUST_NETWORK
try
{

View File

@@ -55,51 +55,4 @@ private:
boost::mutex mLock;
};
class LoadEvent
{
public:
typedef boost::shared_ptr<LoadEvent> pointer;
typedef UPTR_T<LoadEvent> autoptr;
public:
LoadEvent(LoadMonitor& monitor, const std::string& name, bool shouldStart) :
mMonitor(monitor), mRunning(false), mName(name)
{
mStartTime = boost::posix_time::microsec_clock::universal_time();
if (shouldStart)
start();
}
~LoadEvent()
{
if (mRunning)
stop();
}
void reName(const std::string& name)
{
mName = name;
}
void start()
{ // okay to call if already started
mRunning = true;
mStartTime = boost::posix_time::microsec_clock::universal_time();
}
void stop()
{
assert(mRunning);
mRunning = false;
mMonitor.addCountAndLatency(mName,
static_cast<int>((boost::posix_time::microsec_clock::universal_time() - mStartTime).total_milliseconds()));
}
private:
LoadMonitor& mMonitor;
bool mRunning;
std::string mName;
boost::posix_time::ptime mStartTime;
};
#endif

View File

@@ -0,0 +1,37 @@
LoadEvent::LoadEvent (LoadMonitor& monitor, const std::string& name, bool shouldStart)
: mMonitor (monitor)
, mRunning (false)
, mName (name)
{
mStartTime = boost::posix_time::microsec_clock::universal_time();
if (shouldStart)
start();
}
LoadEvent::~LoadEvent()
{
if (mRunning)
stop();
}
void LoadEvent::reName(const std::string& name)
{
mName = name;
}
void LoadEvent::start()
{
mRunning = true;
mStartTime = boost::posix_time::microsec_clock::universal_time();
}
void LoadEvent::stop()
{
assert(mRunning);
mRunning = false;
mMonitor.addCountAndLatency (mName,
static_cast<int>((boost::posix_time::microsec_clock::universal_time() - mStartTime).total_milliseconds()));
}

View File

@@ -0,0 +1,35 @@
#ifndef RIPPLE_LOADEVENT_H
#define RIPPLE_LOADEVENT_H
class LoadMonitor;
class LoadEvent
{
public:
typedef boost::shared_ptr<LoadEvent> pointer;
typedef UPTR_T<LoadEvent> autoptr;
public:
// VFALCO: TODO, remove the dependency on LoadMonitor.
LoadEvent (LoadMonitor& monitor,
const std::string& name,
bool shouldStart);
~LoadEvent();
// VFALCO: TODO, rename this to setName () or setLabel ()
void reName (const std::string& name);
// okay to call if already started
void start();
void stop();
private:
LoadMonitor& mMonitor;
bool mRunning;
std::string mName;
boost::posix_time::ptime mStartTime;
};
#endif