Posted: June 08, 2011 18:24 by LizardSF
Greetings! Trying to use cajo to handle some fairly basic multi-VM communication tasks, ideally with minimal changes to the existing code. The basic setup is, or should be, fairly simple: I've got a main app with a front end, that spawns a certain number of threads which contain objects that do the actual work. I've got a different application, with no front end, that just spawns a worker-type object and sits around waiting for the main app to need it. There's minimal state being shared; the main app needs to know "How many records has each worker processed" and "is the worker done with its asigned tasks". The workers need a mountain of static data for settings, rules, etc. There's two objects that really matter: One which keeps track of which tasks have been assigned and which remain, and another which just tracks active workers.
Here's the problem. When I run the "Create Worker" app, it is fine, and as soon as the main/engine app starts working, the worker in the other VM, thanks to cajo, notices this and does its thing. However, when it tries to add the object it creates to the list of workers maintained by the main app, I get "java.io.NotSerializableException: gnu.cajo.Cajo" and the usual stack trace.
Here's the list to be maintained by the engine:
pendingWork = new HashSet<SplitBasedLoanProcessingTaskCajo>();
Here's how the engine exposes itself:
cajo = new Cajo();
System.out.println("Server running in split-based engine.");
Here's the function that adds the new worker to the list:
public void addWorkerToQueue(SplitBasedLoanProcessingTaskCajo work)
(I've done some other experiments with the code, but then I end up with an unserializable object exception on BufferedWriter, which leads me to believe I have a fundamental misunderstanding of what I need to do in order to share objects between VMs.)
For my purposes, I need to:
a)Have a worker start at any time during the process, and be fed the set of startup information that the engine has.
b)Let that worker access the list of unassigned tasks to be processed. This is the most important "state" to be shared among VMs. This list is the only non-static object a worker needs access to, so I have other solutions for getting it the other values, if need be.
c)Let the main engine know there's another worker, and when it's done.
d)Retrieve from the worker a set of results.