Hi,
I Have a directory with XML Files.
Each file needs to be parsed into an object that is then turned into an Actor with the state of the content from the file.
The Actor can then receive update change messages and when sent a “Save” command will write the XML file back to the disk.
One of the main reasons for using Actors, is that there is a requirement that only one person at a time make changes to the file. An Actor will track who is making the changes and in the case that there are no changes, in like half an hour, can mark the document as open for edit again.
I am saving the commands and the final file.
I will have a FilesSupervisor Actor that will have a command for loading the content of a file and turning it into an Actor for that specific file.
Obviously, working with files is blocking! Where do I do the file handling and parsing?
Option One:
Have a worker Actor whose job it is to read the file and parse the object. This object is then sent as a message to the XMLFile Actor.
Same for a worker actor that writes the final object to the disk.
I can create a special dispatcher for these actors (since they do blocking things) and can put them behind a router to have more of them if needed
Option Two:
In the XMLFileActor, it is created with a name and id. It finds the file on the disk, then reads and parses into an object that is then the state of the actor.
This can be done with the Alpakka library (I think) and is non blocking, since Alpakka manages the blocking operations - is this correct?
Is option two a good idea and if so, is there an example of using Alpakka in this scenario in Java?
Please advise. What is the recommended way to handle Actors that need to have their initial state loaded from a file containing an XML that needs to be parsed, then changed, and then saved.
Thanks,
Tamara.
1 post - 1 participant