This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes Mobile code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Mobile code" Watch "Mobile code" New topic

Mobile code

Sandeep Advani
Ranch Hand

Joined: Mar 11, 2004
Posts: 78

I have the following files

1. An interface with a method serviceMethod() that accepts 2 arguments. First is a byte-array and second is an id.

2. Implements this interface. serviceMethod() accepts byte-array from a client. This byte-array are actually compiled bytecodes that the client sends. Second argument determines the name of the bytecodes/class file. The method serviceMethod() stores the bytecodes in a local file system with a file name determined using the second parameter. Then, using dynamic class loaders, it loads this class file and executes it. With the help of Java reflection, it finds out the name of the method to call in this bytecode/class file. Lets say the bytecode is stored as TestClient.class and the method is test1() inside this class file. FileName TestClient will be the second argument and test1 is calculated thru reflection.

3. Updates RMI registry using rebind method of Naming class.

4. Does a lookup for server URL and gets a reference to the object for Packs TestClient.class into a buffer and invokes serviceMethod() passing this buffer as its first argument and TestClient being the second argument/id. is a simple file which displays some text inside a method test1(). Name of the method is determined on the fly thru' reflection.

Everything works fine smoothly as per RMI tutorial till this point.

Now I add another method add() in which accepts 2 numbers and returns the summation of the two. Then I have the same client load this bytecodes called TestClient.class except that this class file is now different. The method inside say method test1() now calls add() passing 2 numbers.

My question is how can I compile this since method add() is on the server side?

What I am trying to do at an abstract level is that is a mobile code which sends to Eventually, will be a WebService with serviceMethod() and add() as exposed methods. will be a traditional client sending bytecodes through serviceMethod(). WebService loads that bytecode and executes it. Bytecodes which is loaded on the fly will finally call this second add() method on the webservice. Question remains same....compiling this bytecode which makes a call to add()???

Any suggestions or leads to further reading will be appreciated. If you think, I should use some different concept to achieve the same goal, I will be more than glad to hear that as well.

Kedar Bhawarthi

Joined: Jun 21, 2004
Posts: 10
talking perticularly about rmi problem
as your serverinterface is having two methods serviceMethod() and add()
you can write your TestClient's test1() method something like...

now when you are invoking this method on server using Method.invoke() add this as member of arg array in place of iServer.
... this will help to compile your TestClient on client side and while executing server's add method will be used
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Mobile code
It's not a secret anymore!