瑞波核心库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

相关文章

Java集合中的List超详细讲解

《Java集合中的List超详细讲解》本文详细介绍了Java集合框架中的List接口,包括其在集合中的位置、继承体系、常用操作和代码示例,以及不同实现类(如ArrayList、LinkedList和V... 目录一,List的继承体系二,List的常用操作及代码示例1,创建List实例2,增加元素3,访问元

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

Python itertools中accumulate函数用法及使用运用详细讲解

《Pythonitertools中accumulate函数用法及使用运用详细讲解》:本文主要介绍Python的itertools库中的accumulate函数,该函数可以计算累积和或通过指定函数... 目录1.1前言:1.2定义:1.3衍生用法:1.3Leetcode的实际运用:总结 1.1前言:本文将详

Redis的Zset类型及相关命令详细讲解

《Redis的Zset类型及相关命令详细讲解》:本文主要介绍Redis的Zset类型及相关命令的相关资料,有序集合Zset是一种Redis数据结构,它类似于集合Set,但每个元素都有一个关联的分数... 目录Zset简介ZADDZCARDZCOUNTZRANGEZREVRANGEZRANGEBYSCOREZ

Go中sync.Once源码的深度讲解

《Go中sync.Once源码的深度讲解》sync.Once是Go语言标准库中的一个同步原语,用于确保某个操作只执行一次,本文将从源码出发为大家详细介绍一下sync.Once的具体使用,x希望对大家有... 目录概念简单示例源码解读总结概念sync.Once是Go语言标准库中的一个同步原语,用于确保某个操

Andrej Karpathy最新采访:认知核心模型10亿参数就够了,AI会打破教育不公的僵局

夕小瑶科技说 原创  作者 | 海野 AI圈子的红人,AI大神Andrej Karpathy,曾是OpenAI联合创始人之一,特斯拉AI总监。上一次的动态是官宣创办一家名为 Eureka Labs 的人工智能+教育公司 ,宣布将长期致力于AI原生教育。 近日,Andrej Karpathy接受了No Priors(投资博客)的采访,与硅谷知名投资人 Sara Guo 和 Elad G

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

PostgreSQL核心功能特性与使用领域及场景分析

PostgreSQL有什么优点? 开源和免费 PostgreSQL是一个开源的数据库管理系统,可以免费使用和修改。这降低了企业的成本,并为开发者提供了一个活跃的社区和丰富的资源。 高度兼容 PostgreSQL支持多种操作系统(如Linux、Windows、macOS等)和编程语言(如C、C++、Java、Python、Ruby等),并提供了多种接口(如JDBC、ODBC、ADO.NET等

深入解析秒杀业务中的核心问题 —— 从并发控制到事务管理

深入解析秒杀业务中的核心问题 —— 从并发控制到事务管理 秒杀系统是应对高并发、高压力下的典型业务场景,涉及到并发控制、库存管理、事务管理等多个关键技术点。本文将深入剖析秒杀商品业务中常见的几个核心问题,包括 AOP 事务管理、同步锁机制、乐观锁、CAS 操作,以及用户限购策略。通过这些技术的结合,确保秒杀系统在高并发场景下的稳定性和一致性。 1. AOP 代理对象与事务管理 在秒杀商品

ispunct函数讲解 <ctype.h>头文件函数

目录 1.头文件函数 2.ispunct函数使用  小心!VS2022不可直接接触,否则..!没有这个必要,方源一把抓住VS2022,顷刻 炼化! 1.头文件函数 以上函数都需要包括头文件<ctype.h> ,其中包括 ispunct 函数 #include<ctype.h> 2.ispunct函数使用 简述: ispunct函数一种判断字符是否为标点符号的函