Does anyone know how to use Java for Strong code mobility? Have you ever done it before?
Here's what I try to achieve.
Suppose we have 2 separate Java applications that communicate over network. App A and App B.
App A has a class x instantiated as an object, and has been using it. App B has no prior knowledge of this class x.
App A needs to migrate the instance of class x over to App B. App B should be able to dynamically load class x, and retains the state of class x.
I have Googled around and found a bunch of resources on how to dynamically load class at run-time. However, I'm not sure if the mechanism of transferring an object instance over network along with its state, and to invoke it dynamically is covered.
Any pointers would be very helpful, and thank you in advance!
NOTE: I'm mostly interested in how (i.e. the approach, way to think) this problem is solved, not what is used to solve this; this is because I'm tasked to come up with my own solution to solve this problem. Though pointing out libraries/framework is great, it would be ideal if answers are posted from people who have done something like this before (however rare).
You ask about strong mobility, but your requirements are fulfilled with weak mobility, which with some limitations is provided by the RMI protocol. RMI does not only support RPC, object serialization and distributed object graphs, but also code sharing usually used so that the client can load the bytecode of classes only known to the server and execute that bytecode locally.
Strong mobility is not supported by Java and I can't think of a way to implement it without making proprietary extensions to the VM. Essentially, strong mobility in a Java context would mean that you suspend or pause a thread in one VM, transfer all object instances reachable from that thread, potentially bytecode required for the execution and the internal thread st (call stack, etc.) to a different VM and make it recreate the thread state and continue execution at the point where the thread was paused in the original VM.
I have written an open source library which supports Code Mobility exactly as asked above. Actually it supports RPC-type usage as well.
See: Mobility-RPC - Seamless Code Mobility and RPC for the Java platform
In terms of where this stands on weak mobility versus strong mobility: in the middle.
When you transfer an object to a remote machine, you can control which method on the object gets invoked, and with which arguments, when it arrives on the remote machine. So if you're writing a mobile agent, then it can decide itself how it wants to resume execution on the next machine before it transfers itself, it doesn't have to resume from the same place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With