简体   繁体   English

Akka散点收集器,用于字符串处理

[英]Akka scatter-gather for string processing

I have requirement to split a input string in to output string/s (with some order) by applying a set of regexs on the input string. 我需要通过在输入字符串上应用一组正则表达式将输入字符串拆分为输出字符串(以某种顺序)。 I thinking to implement this functionality with cluster of akka actors in such a way I scatter the regex and input string and gather the string. 我想用akka actor集群实现此功能,使我分散正则表达式和输入字符串并收集字符串。 However I would like to know while collecting back the processed string, how to keep track of the order. 但是,我想知道在回收处理过的字符串时,如何跟踪订单。 Iam not certain if "Scatter-Gather" is the correct approach , if there is any other that can be suited please suggest. 我不确定“ Scatter-Gather”是否是正确的方法,如果还有其他适合的方法,请提出建议。

I guess you will have to provide hints to the gatherer on how to assemble the string in order. 我想您将必须向收集器提供有关如何按顺序组装字符串的提示。 You don't mention how the order is established: whether the initial split can define the order or whether the regex processing will define it. 您没有提到订单的建立方式:初始拆分是否可以定义订单,或者正则表达式处理是否可以定义订单。

In both cases, you need to keep track of 3 things: - the initial source, - the order of each individual piece - the total amount of pieces 在这两种情况下,您都需要跟踪以下三件事:-初始来源-每个零件的顺序-零件总数

You could use a message like: 您可以使用以下消息:

case class StringSegment(id:String, total:Int, seqNr:Int, payload:String)

The scatterer produces StringSegment s based on the input: 分散器根据输入生成StringSegment

def scatter(s:String):List[StringSegment] ...
scatter(input).foreach(msg => processingActor ! msg)

and the gatherer will assemble them together, using the seqNr to know the order and total to know when all the pieces are present. 然后收集器将它们组装在一起,使用seqNr知道顺序和total以了解何时存在所有碎片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM