瑞波核心库Stoppable类讲解

2023-12-25 04:58
文章标签 讲解 核心 瑞波 stoppable

本文主要是介绍瑞波核心库Stoppable类讲解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

瑞波核心库Stoppable类主要提供启动和停止接口。


构建服务器或P2P代码的常见方法是将概念上的功能独立到单独的类来实现,进而聚合成更大的“应用程序”或“核心”对象,这些组件通常使用不可避免地相互依赖复杂的方式。他们还经常使用线程并执行异步I / O和 涉及套接字或其他操作系统对象的操作。这个过程开始和停止这样的系统可能是复杂的。这个接口确保了它们启动和停止。

下面是瑞波中使用Stoppable类做为基类的应用类:


                                                     Application
                                                            |
                   +--------------------+--------------------+
                   |                                         |                    |
              LoadManager          SHAMapStore       NodeStoreScheduler
                                                                                 |
                                                                           JobQueue
                                                                                 |
        +-----------+-----------+-----------+-----------+----+--------+
        |           |                    |                      |                        |             |
        |       NetworkOPs      |                  InboundLedgers    |        OrderbookDB
        |                                |                                               |
     Overlay                  InboundTransactions             LedgerMaster
        |                                                                                |

    PeerFinder                                                            LedgerCleaner

在这些类初始化过程中,Stoppable将会执行如下步奏:

    1.  Construct sub-components.
        These are all typically derived from Stoppable. There can be a deep
        hierarchy: Stoppable objects may themselves have Stoppable child

        objects. This captures the relationship of dependencies.

    2.  prepare()

        Because some components may depend on others, preparatory steps require
        that all objects be first constructed. The prepare step calls all
        Stoppable objects in the tree starting from the leaves and working up
        to the root. In this stage we are guaranteed that all objects have been
        constructed and are in a well-defined state.
    3.  onPrepare()
        This override is called for all Stoppable objects in the hierarchy
        during the prepare stage. It is guaranteed that all child Stoppable
        objects have already been prepared when this is called.
        Objects are called children first.
    4.  start()
        At this point all sub-components have been constructed and prepared,
        so it should be safe for them to be started. While some Stoppable
        objects may do nothing in their start function, others will start
        threads or call asynchronous i/o initiating functions like timers or
        sockets.
    5.  onStart()
        This override is called for all Stoppable objects in the hierarchy
        during the start stage. It is guaranteed that no child Stoppable
        objects have been started when this is called.

        Objects are called parent first.

在停止过程中将会顺序触发如下事件:

   6.  stopAsync() [optional]
        This notifies the root Stoppable and all its children that a stop is
        requested.
    7.  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.
    8.  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.
        Objects are called parent first.
    9.  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.
        Objects are called children first.
    10. 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.

如上图可知道,Application为所有继承于Stoppable起源类,在Stoppable.h 和Stoppable.cpp中专门构建了

class RootStoppable : public Stoppable 用于管理所有其他Stoppable的 prepare,start,stop,以及isStopping,started查询。


博主QQ: 122209017

这篇关于瑞波核心库Stoppable类讲解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/534321

相关文章

深度解析Spring Security 中的 SecurityFilterChain核心功能

《深度解析SpringSecurity中的SecurityFilterChain核心功能》SecurityFilterChain通过组件化配置、类型安全路径匹配、多链协同三大特性,重构了Spri... 目录Spring Security 中的SecurityFilterChain深度解析一、Security

RabbitMQ消费端单线程与多线程案例讲解

《RabbitMQ消费端单线程与多线程案例讲解》文章解析RabbitMQ消费端单线程与多线程处理机制,说明concurrency控制消费者数量,max-concurrency控制最大线程数,prefe... 目录 一、基础概念详细解释:举个例子:✅ 单消费者 + 单线程消费❌ 单消费者 + 多线程消费❌ 多

Olingo分析和实践之OData框架核心组件初始化(关键步骤)

《Olingo分析和实践之OData框架核心组件初始化(关键步骤)》ODataSpringBootService通过初始化OData实例和服务元数据,构建框架核心能力与数据模型结构,实现序列化、URI... 目录概述第一步:OData实例创建1.1 OData.newInstance() 详细分析1.1.1

Spring Boot Maven 插件如何构建可执行 JAR 的核心配置

《SpringBootMaven插件如何构建可执行JAR的核心配置》SpringBoot核心Maven插件,用于生成可执行JAR/WAR,内置服务器简化部署,支持热部署、多环境配置及依赖管理... 目录前言一、插件的核心功能与目标1.1 插件的定位1.2 插件的 Goals(目标)1.3 插件定位1.4 核

从入门到进阶讲解Python自动化Playwright实战指南

《从入门到进阶讲解Python自动化Playwright实战指南》Playwright是针对Python语言的纯自动化工具,它可以通过单个API自动执行Chromium,Firefox和WebKit... 目录Playwright 简介核心优势安装步骤观点与案例结合Playwright 核心功能从零开始学习

嵌入式数据库SQLite 3配置使用讲解

《嵌入式数据库SQLite3配置使用讲解》本文强调嵌入式项目中SQLite3数据库的重要性,因其零配置、轻量级、跨平台及事务处理特性,可保障数据溯源与责任明确,详细讲解安装配置、基础语法及SQLit... 目录0、惨痛教训1、SQLite3环境配置(1)、下载安装SQLite库(2)、解压下载的文件(3)、

详解MySQL中DISTINCT去重的核心注意事项

《详解MySQL中DISTINCT去重的核心注意事项》为了实现查询不重复的数据,MySQL提供了DISTINCT关键字,它的主要作用就是对数据表中一个或多个字段重复的数据进行过滤,只返回其中的一条数据... 目录DISTINCT 六大注意事项1. 作用范围:所有 SELECT 字段2. NULL 值的特殊处

Python包管理工具核心指令uvx举例详细解析

《Python包管理工具核心指令uvx举例详细解析》:本文主要介绍Python包管理工具核心指令uvx的相关资料,uvx是uv工具链中用于临时运行Python命令行工具的高效执行器,依托Rust实... 目录一、uvx 的定位与核心功能二、uvx 的典型应用场景三、uvx 与传统工具对比四、uvx 的技术实

java中Optional的核心用法和最佳实践

《java中Optional的核心用法和最佳实践》Java8中Optional用于处理可能为null的值,减少空指针异常,:本文主要介绍java中Optional核心用法和最佳实践的相关资料,文中... 目录前言1. 创建 Optional 对象1.1 常规创建方式2. 访问 Optional 中的值2.1

Java进程CPU使用率过高排查步骤详细讲解

《Java进程CPU使用率过高排查步骤详细讲解》:本文主要介绍Java进程CPU使用率过高排查的相关资料,针对Java进程CPU使用率高的问题,我们可以遵循以下步骤进行排查和优化,文中通过代码介绍... 目录前言一、初步定位问题1.1 确认进程状态1.2 确定Java进程ID1.3 快速生成线程堆栈二、分析