diff --git a/include/xrpl/core/ServiceRegistry.h b/include/xrpl/core/ServiceRegistry.h new file mode 100644 index 0000000000..bc11a01be8 --- /dev/null +++ b/include/xrpl/core/ServiceRegistry.h @@ -0,0 +1,207 @@ +#ifndef XRPL_CORE_SERVICEREGISTRY_H_INCLUDED +#define XRPL_CORE_SERVICEREGISTRY_H_INCLUDED + +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +// Forward declarations +namespace NodeStore { +class Database; +} +namespace Resource { +class Manager; +} +namespace perf { +class PerfLog; +} + +class AcceptedLedger; +class AmendmentTable; +class Cluster; +class CollectorManager; +class DatabaseCon; +class Family; +class HashRouter; +class InboundLedgers; +class InboundTransactions; +class JobQueue; +class LedgerCleaner; +class LedgerMaster; +class LedgerReplayer; +class LoadFeeTrack; +class LoadManager; +class ManifestCache; +class NetworkOPs; +class OpenLedger; +class OrderBookDB; +class Overlay; +class PathRequests; +class PeerReservationTable; +class PendingSaves; +class RelationalDatabase; +class ServerHandler; +class SHAMapStore; +class TimeKeeper; +class TransactionMaster; +class TxQ; +class ValidatorList; +class ValidatorSite; + +template +class Validations; +class RCLValidationsAdaptor; +using RCLValidations = Validations; + +using NodeCache = TaggedCache; + +/** Service registry for dependency injection. + + This abstract interface provides access to various services and components + used throughout the application. It separates the service locator pattern + from the Application lifecycle management. + + Components that need access to services can hold a reference to + ServiceRegistry rather than Application when they only need service + access and not lifecycle management. + + The implementation (ServiceRegistryImpl) is provided in xrpld. +*/ +class ServiceRegistry +{ +public: + ServiceRegistry() = default; + virtual ~ServiceRegistry() = default; + + // Core infrastructure services + virtual CollectorManager& + getCollectorManager() = 0; + + virtual Family& + getNodeFamily() = 0; + + virtual TimeKeeper& + timeKeeper() = 0; + + virtual JobQueue& + getJobQueue() = 0; + + virtual NodeCache& + getTempNodeCache() = 0; + + virtual CachedSLEs& + cachedSLEs() = 0; + + // Protocol and validation services + virtual AmendmentTable& + getAmendmentTable() = 0; + + virtual HashRouter& + getHashRouter() = 0; + + virtual LoadFeeTrack& + getFeeTrack() = 0; + + virtual LoadManager& + getLoadManager() = 0; + + virtual RCLValidations& + getValidations() = 0; + + virtual ValidatorList& + validators() = 0; + + virtual ValidatorSite& + validatorSites() = 0; + + virtual ManifestCache& + validatorManifests() = 0; + + virtual ManifestCache& + publisherManifests() = 0; + + // Network services + virtual Overlay& + overlay() = 0; + + virtual Cluster& + cluster() = 0; + + virtual PeerReservationTable& + peerReservations() = 0; + + virtual Resource::Manager& + getResourceManager() = 0; + + // Storage services + virtual NodeStore::Database& + getNodeStore() = 0; + + virtual SHAMapStore& + getSHAMapStore() = 0; + + virtual RelationalDatabase& + getRelationalDatabase() = 0; + + // Ledger services + virtual InboundLedgers& + getInboundLedgers() = 0; + + virtual InboundTransactions& + getInboundTransactions() = 0; + + virtual TaggedCache& + getAcceptedLedgerCache() = 0; + + virtual LedgerMaster& + getLedgerMaster() = 0; + + virtual LedgerCleaner& + getLedgerCleaner() = 0; + + virtual LedgerReplayer& + getLedgerReplayer() = 0; + + virtual PendingSaves& + pendingSaves() = 0; + + virtual OpenLedger& + openLedger() = 0; + + virtual OpenLedger const& + openLedger() const = 0; + + // Transaction and operation services + virtual NetworkOPs& + getOPs() = 0; + + virtual OrderBookDB& + getOrderBookDB() = 0; + + virtual TransactionMaster& + getMasterTransaction() = 0; + + virtual TxQ& + getTxQ() = 0; + + virtual PathRequests& + getPathRequests() = 0; + + // Server services + virtual ServerHandler& + getServerHandler() = 0; + + virtual perf::PerfLog& + getPerfLog() = 0; +}; + +} // namespace xrpl + +#endif diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 15abff9b14..2c038455a1 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -217,6 +218,9 @@ public: std::unique_ptr grpcServer_; + // ServiceRegistry implementation that delegates to this Application + std::unique_ptr serviceRegistry_; + //-------------------------------------------------------------------------- static std::size_t @@ -453,6 +457,7 @@ public: std::chrono::milliseconds(100), get_io_context()) , grpcServer_(std::make_unique(*this)) + , serviceRegistry_(std::make_unique(*this)) { initAccountIdCache(config_->getValueFor(SizedItem::accountIdCacheSize)); @@ -808,6 +813,16 @@ public: return *mWalletDB; } + ServiceRegistry& + getServiceRegistry() override + { + XRPL_ASSERT( + serviceRegistry_, + "xrpl::ApplicationImp::getServiceRegistry : non-null service " + "registry"); + return *serviceRegistry_; + } + bool serverOkay(std::string& reason) override; diff --git a/src/xrpld/app/main/Application.h b/src/xrpld/app/main/Application.h index ffb3cd9983..cc0c198acd 100644 --- a/src/xrpld/app/main/Application.h +++ b/src/xrpld/app/main/Application.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -256,6 +257,9 @@ public: virtual std::optional const& trapTxID() const = 0; + + virtual ServiceRegistry& + getServiceRegistry() = 0; }; std::unique_ptr diff --git a/src/xrpld/app/tx/detail/Taker.h b/src/xrpld/app/tx/detail/Taker.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/xrpld/core/ServiceRegistryImpl.h b/src/xrpld/core/ServiceRegistryImpl.h new file mode 100644 index 0000000000..cefca97afd --- /dev/null +++ b/src/xrpld/core/ServiceRegistryImpl.h @@ -0,0 +1,157 @@ +#ifndef XRPLD_CORE_SERVICEREGISTRYIMPL_H_INCLUDED +#define XRPLD_CORE_SERVICEREGISTRYIMPL_H_INCLUDED + +#include + +namespace xrpl { + +// Forward declaration +class Application; + +/** Implementation of ServiceRegistry that delegates to Application. + + This class provides a ServiceRegistry interface that wraps an Application + reference. It allows components to depend on ServiceRegistry instead of + Application, enabling gradual migration and better separation of concerns. + + Usage: + Application& app = ...; + ServiceRegistry& registry = app.getServiceRegistry(); + // or + ServiceRegistryImpl registry(app); +*/ +class ServiceRegistryImpl : public ServiceRegistry +{ +public: + explicit ServiceRegistryImpl(Application& app); + + ~ServiceRegistryImpl() override = default; + + // Core infrastructure services + CollectorManager& + getCollectorManager() override; + + Family& + getNodeFamily() override; + + TimeKeeper& + timeKeeper() override; + + JobQueue& + getJobQueue() override; + + NodeCache& + getTempNodeCache() override; + + CachedSLEs& + cachedSLEs() override; + + // Protocol and validation services + AmendmentTable& + getAmendmentTable() override; + + HashRouter& + getHashRouter() override; + + LoadFeeTrack& + getFeeTrack() override; + + LoadManager& + getLoadManager() override; + + RCLValidations& + getValidations() override; + + ValidatorList& + validators() override; + + ValidatorSite& + validatorSites() override; + + ManifestCache& + validatorManifests() override; + + ManifestCache& + publisherManifests() override; + + // Network services + Overlay& + overlay() override; + + Cluster& + cluster() override; + + PeerReservationTable& + peerReservations() override; + + Resource::Manager& + getResourceManager() override; + + // Storage services + NodeStore::Database& + getNodeStore() override; + + SHAMapStore& + getSHAMapStore() override; + + RelationalDatabase& + getRelationalDatabase() override; + + // Ledger services + InboundLedgers& + getInboundLedgers() override; + + InboundTransactions& + getInboundTransactions() override; + + TaggedCache& + getAcceptedLedgerCache() override; + + LedgerMaster& + getLedgerMaster() override; + + LedgerCleaner& + getLedgerCleaner() override; + + LedgerReplayer& + getLedgerReplayer() override; + + PendingSaves& + pendingSaves() override; + + OpenLedger& + openLedger() override; + + OpenLedger const& + openLedger() const override; + + // Transaction and operation services + NetworkOPs& + getOPs() override; + + OrderBookDB& + getOrderBookDB() override; + + TransactionMaster& + getMasterTransaction() override; + + TxQ& + getTxQ() override; + + PathRequests& + getPathRequests() override; + + // Server services + ServerHandler& + getServerHandler() override; + + perf::PerfLog& + getPerfLog() override; + +private: + Application& app_; +}; + +} // namespace xrpl + +#endif diff --git a/src/xrpld/core/detail/ServiceRegistryImpl.cpp b/src/xrpld/core/detail/ServiceRegistryImpl.cpp new file mode 100644 index 0000000000..4549fa6864 --- /dev/null +++ b/src/xrpld/core/detail/ServiceRegistryImpl.cpp @@ -0,0 +1,245 @@ +#include +#include + +namespace xrpl { + +ServiceRegistryImpl::ServiceRegistryImpl(Application& app) : app_(app) +{ +} + +// Core infrastructure services +CollectorManager& +ServiceRegistryImpl::getCollectorManager() +{ + return app_.getCollectorManager(); +} + +Family& +ServiceRegistryImpl::getNodeFamily() +{ + return app_.getNodeFamily(); +} + +TimeKeeper& +ServiceRegistryImpl::timeKeeper() +{ + return app_.timeKeeper(); +} + +JobQueue& +ServiceRegistryImpl::getJobQueue() +{ + return app_.getJobQueue(); +} + +NodeCache& +ServiceRegistryImpl::getTempNodeCache() +{ + return app_.getTempNodeCache(); +} + +CachedSLEs& +ServiceRegistryImpl::cachedSLEs() +{ + return app_.cachedSLEs(); +} + +// Protocol and validation services +AmendmentTable& +ServiceRegistryImpl::getAmendmentTable() +{ + return app_.getAmendmentTable(); +} + +HashRouter& +ServiceRegistryImpl::getHashRouter() +{ + return app_.getHashRouter(); +} + +LoadFeeTrack& +ServiceRegistryImpl::getFeeTrack() +{ + return app_.getFeeTrack(); +} + +LoadManager& +ServiceRegistryImpl::getLoadManager() +{ + return app_.getLoadManager(); +} + +RCLValidations& +ServiceRegistryImpl::getValidations() +{ + return app_.getValidations(); +} + +ValidatorList& +ServiceRegistryImpl::validators() +{ + return app_.validators(); +} + +ValidatorSite& +ServiceRegistryImpl::validatorSites() +{ + return app_.validatorSites(); +} + +ManifestCache& +ServiceRegistryImpl::validatorManifests() +{ + return app_.validatorManifests(); +} + +ManifestCache& +ServiceRegistryImpl::publisherManifests() +{ + return app_.publisherManifests(); +} + +// Network services +Overlay& +ServiceRegistryImpl::overlay() +{ + return app_.overlay(); +} + +Cluster& +ServiceRegistryImpl::cluster() +{ + return app_.cluster(); +} + +PeerReservationTable& +ServiceRegistryImpl::peerReservations() +{ + return app_.peerReservations(); +} + +Resource::Manager& +ServiceRegistryImpl::getResourceManager() +{ + return app_.getResourceManager(); +} + +// Storage services +NodeStore::Database& +ServiceRegistryImpl::getNodeStore() +{ + return app_.getNodeStore(); +} + +SHAMapStore& +ServiceRegistryImpl::getSHAMapStore() +{ + return app_.getSHAMapStore(); +} + +RelationalDatabase& +ServiceRegistryImpl::getRelationalDatabase() +{ + return app_.getRelationalDatabase(); +} + +// Ledger services +InboundLedgers& +ServiceRegistryImpl::getInboundLedgers() +{ + return app_.getInboundLedgers(); +} + +InboundTransactions& +ServiceRegistryImpl::getInboundTransactions() +{ + return app_.getInboundTransactions(); +} + +TaggedCache& +ServiceRegistryImpl::getAcceptedLedgerCache() +{ + return app_.getAcceptedLedgerCache(); +} + +LedgerMaster& +ServiceRegistryImpl::getLedgerMaster() +{ + return app_.getLedgerMaster(); +} + +LedgerCleaner& +ServiceRegistryImpl::getLedgerCleaner() +{ + return app_.getLedgerCleaner(); +} + +LedgerReplayer& +ServiceRegistryImpl::getLedgerReplayer() +{ + return app_.getLedgerReplayer(); +} + +PendingSaves& +ServiceRegistryImpl::pendingSaves() +{ + return app_.pendingSaves(); +} + +OpenLedger& +ServiceRegistryImpl::openLedger() +{ + return app_.openLedger(); +} + +OpenLedger const& +ServiceRegistryImpl::openLedger() const +{ + return app_.openLedger(); +} + +// Transaction and operation services +NetworkOPs& +ServiceRegistryImpl::getOPs() +{ + return app_.getOPs(); +} + +OrderBookDB& +ServiceRegistryImpl::getOrderBookDB() +{ + return app_.getOrderBookDB(); +} + +TransactionMaster& +ServiceRegistryImpl::getMasterTransaction() +{ + return app_.getMasterTransaction(); +} + +TxQ& +ServiceRegistryImpl::getTxQ() +{ + return app_.getTxQ(); +} + +PathRequests& +ServiceRegistryImpl::getPathRequests() +{ + return app_.getPathRequests(); +} + +// Server services +ServerHandler& +ServiceRegistryImpl::getServerHandler() +{ + return app_.getServerHandler(); +} + +perf::PerfLog& +ServiceRegistryImpl::getPerfLog() +{ + return app_.getPerfLog(); +} + +} // namespace xrpl