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 need TWO things transferred from A to B in order to move an instance I of the class C.
First the class definition of C (usually in form of a list of byte codes) and then the serialized form of I. Please note that you should use XML serialization instad of the old binary serialization.
The really tricky part is getting the dependencies of C transferred as you need to essentially transfer all the superclasses of C too, plus all the return types and field types, and THEIR superclasses and return/field types etc. etc. etc.
If you really need to do this for all possible values of C your best bet is using a framework designed to do this like a grid one or Terracotta. If you can restrain yourself to e.g. a given and narrow interface, you will probably be much better of. Also consider just using properties for this, as they are very simple and can get you far.