prassee
prassee

Reputation: 3629

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. 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.

Upvotes: 1

Views: 735

Answers (1)

maasg
maasg

Reputation: 37435

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 StringSegments based on the input:

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.

Upvotes: 2

Related Questions