我正在编程一些连接到控制台但从日志文件读取的代码。这是独一无二的,因为数据不断地被写入日志,我和我只能在收到数据时检查它。数据是以数据包的形式接收的,这些数据包被组装成“行”,然后我在每一行上进行正则表达式,看看它是否是我要查找的数据。
例如:
(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的相对位置如何。
在块的末尾,我现在有了一个完整的数据集。
虽然一旦编写了一个良好的代码基础,这是很容易做到的,但我所面临的问题是,对于某些数据来说,实际上是一个非常线性的读取的代码本质上是非线性的,因为它出现在源文件中,因为必须在不同的正则表达式触发器和附加回调之间跳转。
我现在写的实际过程比上面的例子要复杂得多。它是相似的,但对于每个条目
B
在里面
我必须发送另一个命令来提取与
. 完整的数据集
在我拥有一切之前是不会完成的。
> 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”,这是我想要发布命令请求一些信息的地方。日志文件是从系统“输出”的,而“显示”是从输出接收到的每一行的循环。
我认为这是正确的方法。现在我如何将这三个结合起来说明他们的关系?