我正在编写一些代码,这些代码连接到一个控制台,但从日志文件中读取。这是独一无二的,因为数据不断地写入日志,而我和我只能在收到数据时检查它。数据是以数据包的形式接收的,这些数据包被组装成“行”,然后我在每行上执行正则表达式,以查看它是否是我正在寻找的数据。
例如:
(output) -- ignore
(output) -- ignore
(output) -- ignore
(input ) -- > ask for A - enable regex for A
(output) -- ignore
(output) -- ignore
(output) -- regex match - A_START - enable regex for B and C
(output) -- regex match - B
(output) -- regex match - B
(output) -- regex match - B
(output) -- regex match - C
(output) -- regex match - A_END - process completed data set输出是从我的应用程序异步写入日志的,所以我不能发送命令,然后期望下一个输出就是结果;它将在将来的某个时候输出。因此,我的读缓冲区通常只有一行。
请注意,A的匹配行可能随时出现,这就是为什么我在需要时按顺序显式启用和禁用这些正则表达式模式的原因。
这可能看起来不可能解析,但这种疯狂是有顺序的。虽然接收的数据是异步的,但它是以“块”的形式发送的,其中每个块都是一个完整的数据集。例如,如果数据集X、Y、Z都是一行,那么它可以以任何顺序出现在日志中。但是如果X是三条线,那么它将始终显示为三条相邻的线,而不管它与Y和Z的相对位置。
这允许我在一个非常显式的块开始时使用正则表达式,以知道何时启用贪婪正则表达式,然后在我所知道的块显式结束时禁用贪婪正则表达式。
在块的末尾,我现在有了一个完整的数据集。
虽然一旦编写了良好的代码基础,就很容易做到这一点,但我遇到的问题是,由于必须在不同的正则表达式触发器和额外的回调之间跳转,对某些数据的实际线性读取的代码本质上是非线性的,因为它出现在源文件中。
我想要做的是将它详细地表示为UML,这样我以后就可以再次引用它,因为我知道从现在开始三个月后我将经历一段地狱般的时间来理解它。
我现在正在写的实际过程比上面的简短示例要复杂得多。这是类似的,但是对于A中的每个条目B,我必须发送另一个命令来拉取一个与A相关的额外数据集。直到我有了所有的东西,A的完整数据集才算完成。
以下是序列的简要摘要:
> invoke catalog show
(output) -- Catalog Begin
(output) Collection 1
(output) Collection 2
(output) Collection 3
(output) -- Catalog End
// foreach next entry in Catalog...
> invoke Collection 1 show
(output) -- Collection Begin
(output) ...
(output) ...
(output) ...
(output) -- Collection End
// Perform action on Collection 1
// foreach next entry in Catalog...下面是对同样的事情的更详细的总结:
-- enable 'catalog begin' regex pattern
> invoke catalog show
(output) -- Catalog Begin
-- REGEX MATCH
-- disable 'catalog begin' regex pattern
-- enable 'catalog entry' regex pattern
(output) Collection 1
-- REGEX MATCH
-- add to catalog list
(output) Collection 2
-- REGEX MATCH
-- add to catalog list
(output) Collection 3
-- REGEX MATCH
-- add to catalog list
(output) -- Catalog End
-- REGEX MATCH
-- disable 'catalog end' regex pattern
-- enable 'collection begin' regex pattern
-- collections max = 3
-- next collection = 1
-- send command: invoke Collection 1 (next collection) show
> invoke Collection 1 show
(output) -- Collection Begin
-- REGEX MATCH
-- disable 'collection begin' regex pattern
-- enable 'collection entry' regex pattern
(output) ...
-- REGEX MATCH
-- add to collection entry list
(output) ...
-- REGEX MATCH
-- add to collection entry list
(output) ...
-- REGEX MATCH
-- add to collection entry list
(output) -- Collection End
-- REGEX MATCH
-- disable 'collection begin' regex pattern
-- enable 'collection entry' regex pattern
-- next collection + 1 (2)
-- send command: invoke Collection 2 (next collection) show
-- if next collection > 3 (collections max)... (false)
-- repeats for all 3 entries
> invoke Collection 2 show
...
-- collections invoked + 1 (3)
-- if next collection > 3 (collections max)... (false)
> invoke Collection 3 show
...
-- collections invoked + 1 (3)
-- if next collection > 3 (collections max)... (true)
-- perform processing on data (catalog list and collection lists)请帮助我理解我如何才能清楚地说明这一点,这样我才能理解如何组装组成一个非常线性的操作的所有不同的部分。
更新:
我认为这是正确的方法吗?
我有"Action“,它是我想要发出命令来请求一些信息的地方。有一个日志文件,它是系统的“输出”,还有一个“显示”,它是我从输出中读取每一行的循环。
输出是异步的(在它自己的列中),显示也是异步的,因为它只在读取时显示每一行。并且操作也是异步执行的(它可以在任何时候被调用)。
我认为这是正确的方法。现在,我如何将这三者结合在一起来说明它们之间的关系?

发布于 2019-06-16 04:14:09
您可以使用活动图、序列图或状态机图。所有这三种图表类型都具有对异步流程建模的广泛可能性。对于您的目的,我认为活动图是首选。使用"fork“符号,您可以创建两个并行线程,每个线程监听不同的事件。要侦听事件,请使用下图中所示的相应多边形。线程可以使用对象流(橙色箭头)进行通信,也可以通过数据存储进行通信。我试着创建一个活动图来反映你算法的一部分。这些颜色不是由UML规定的。我使用颜色来突出显示不同类型的模型元素。

我希望这能帮到你。请注意,该图没有结束节点。如果活动在特定条件下停止,那么您必须添加该条件。此外,它在每次regexp匹配后等待另一个块。您必须扩展该图,以显示它将多个正则表达式应用于单个块。
https://stackoverflow.com/questions/56606277
复制相似问题