【发布时间】:2019-10-29 13:40:21
【问题描述】:
我正在编写一些连接到控制台但从日志文件中读取的代码。这是独一无二的,因为数据不断被写入日志,而我和我只能在收到它时检查它。数据以数据包的形式接收,这些数据包组装成“行”,然后我在每一行上进行正则表达式,看看它是否是我正在寻找的数据。
例如:
(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 的相对位置如何,它总是会显示为三个相邻的行。
这允许我在块的非常明确的 START 上进行正则表达式以知道何时启用贪婪的正则表达式,然后在我知道的块的显式 END 正则表达式中禁用贪婪的正则表达式。
在块的末尾,我现在有一个完整的数据集。
虽然一旦编写了良好的代码基础就很容易做到这一点,但我遇到的问题是,实际上对某些数据进行非常线性读取的代码本质上是非线性的,因为它出现在由于必须在不同的正则表达式触发器和其他回调之间跳转,源文件。
我想要做的是详细绘制 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”,我想在其中发出命令来请求一些信息。日志文件是系统的“输出”,而“显示”是我从输出接收到的每一行读取的循环。
输出是异步的(在它自己的列中),并且显示是异步的,因为它只显示读取的每一行。并且动作也是异步执行的(可以随时调用)。
我认为这是正确的方法。现在如何将这三者结合在一起来说明它们的关系?
【问题讨论】:
-
设计已经可以使用了。我缺乏的是如何在 UML 中表达这种程序流程的经验。我正在寻找有关如何执行此操作的指导。什么类型的图表,如何以某种方式绘制事物以传达此输出是异步的,等等。我已经以文本形式进行了解释,但我想知道它是否可以更清楚地显示为图表。
-
现在没时间给出正确答案,但我相信活动图可以完全满足您的需求。
-
您建议创建一个包含三列的图表。这三个演员是并行工作的吗?在这种情况下,我将“Action”解释为人类参与者(用户),“Display”解释为从日志文件读取的进程,“Output”解释为外部系统将信息写入日志文件。这是正确的吗?
标签: asynchronous uml visualization diagram sequence-diagram