File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Mobile code" Watch "Mobile code" New topic
Author

Mobile code

Sandeep Advani
Ranch Hand

Joined: Mar 11, 2004
Posts: 78
Hello

I have the following files

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

2. ServerImpl.java: 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. Server.java: Updates RMI registry using rebind method of Naming class.

4. Client.java: Does a lookup for server URL and gets a reference to the object for ServerImpl.java. Packs TestClient.class into a buffer and invokes serviceMethod() passing this buffer as its first argument and TestClient being the second argument/id. TestClient.java 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 ServerImpl.java which accepts 2 numbers and returns the summation of the two. Then I have the same client Client.java load this bytecodes called TestClient.class except that this class file is now different. The method inside TestClient.java say method test1() now calls add() passing 2 numbers.

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

What I am trying to do at an abstract level is that TestClient.java is a mobile code which Client.java sends to ServerImpl.java. Eventually, ServerImpl.java will be a WebService with serviceMethod() and add() as exposed methods. Client.java 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.

Thanks.
Kedar Bhawarthi
Greenhorn

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mobile code
 
Similar Threads
Sending bytecodes
sending array of bytes through webservice
Advise needed !
Loading Class
Not able to load Class