I have just started looking at Fantom, the use case I have is to declaratively define a graph of communicating processes (via XML or JSON), to instantiate the graph at runtime and then start the processes executing.
With Fantom I am looking at using actors for the processes and replacing the channels with message passing.
My first approach was to look at object serialization, and while I can serialize an Actor class I can't see how to serialise the Actor context. I need this so that an a deserialized actor can hold references to the other actors in the graph that it must communicate with. I appreciate that the serialised graph is limited to a tree, I can work within these constraints.
The Unsafe wrapper class is not serializable, and I'm not sure how I might go about serialising/deserialising the Actor.locals map.
Is this possible, if not then would a better approach be to use a factory class that reads in the process graph definition and builds the Actor graph incrementally?
TIA
Andy
brianMon 6 Feb 2012
Interesting problem. Assuming you have multiple actors with multiple local states, then serializing them all to one file would be tricky since you'd have to coordinate passing around an OutStream to each one serially. Couple techniques you could use:
have each of your actors respond to a message that writes out their local state to an individual file (so each actor serializes to separate files)
have each actor respond to a message that writes out their state to a StrBuf, and then returns a Str. A coordinator could then merge all the strings together into one big serialization file
Deserializing could then use the reverse of the technique.
march44Mon 6 Feb 2012
brian
Hi, thanks for the reply, I like the idea of an actor saving and loading its own state in response to a message, the co-ordinator sounds very like the factory/builder I was considering.
So maybe the co-ordinator factory class is the right approach from the start, it will also provide greater flexibility when creating and managing the Actor graphs.
march44 Mon 6 Feb 2012
I have just started looking at Fantom, the use case I have is to declaratively define a graph of communicating processes (via XML or JSON), to instantiate the graph at runtime and then start the processes executing.
With Fantom I am looking at using actors for the processes and replacing the channels with message passing.
My first approach was to look at object serialization, and while I can serialize an Actor class I can't see how to serialise the Actor context. I need this so that an a deserialized actor can hold references to the other actors in the graph that it must communicate with. I appreciate that the serialised graph is limited to a tree, I can work within these constraints.
The Unsafe wrapper class is not serializable, and I'm not sure how I might go about serialising/deserialising the Actor.locals map.
Is this possible, if not then would a better approach be to use a factory class that reads in the process graph definition and builds the Actor graph incrementally?
TIA
Andy
brian Mon 6 Feb 2012
Interesting problem. Assuming you have multiple actors with multiple local states, then serializing them all to one file would be tricky since you'd have to coordinate passing around an OutStream to each one serially. Couple techniques you could use:
Deserializing could then use the reverse of the technique.
march44 Mon 6 Feb 2012
brian
Hi, thanks for the reply, I like the idea of an actor saving and loading its own state in response to a message, the co-ordinator sounds very like the factory/builder I was considering.
So maybe the co-ordinator factory class is the right approach from the start, it will also provide greater flexibility when creating and managing the Actor graphs.
Andy