jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Running a RMI Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Running a RMI Application" Watch "Running a RMI Application" New topic
Author

Running a RMI Application

Elinor Chang
Ranch Hand

Joined: Jul 30, 2003
Posts: 58
I am teaching myself RMI now, after knowing it is a required by SCJD. I was following the tutorial http://java.sun.com/docs/books/tutorial/rmi/TOC.html. After I finished up reading, I was trying to setup the example application but I got confused. Do I need a web server? I have the following setup in my unix box
1. A compiled example RMI application
2. A apache web server
3. Of course JDK. I am using 1.3.0 now.
Can someone show a step-by-step instruction of how to set the Compute engine up?
Appreciated
Elinor


The more I learn, the less I know....<br /> <br />SCJP2 <br />SCWCD
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

No you do not need a web server. you would only need a web server if you are dynamically downloading the stubs. In this case you are not using Dynamic downloading. The stubs will be with your client.
Here's a way to test. Create your object that you will bind into the registry. Run RMIC on this class to produce the stubs, etc. Then run the registry, run the class that will bind the object into the registry.
Create a client class that will lookup the class in the registry and call a method on the remote object.
That is a simple way to explain it. You might want to make sure you classes are all in your classpath.
Of course JDK. I am using 1.3.0 now.

Um unfortunately you might need to upgrade to a newer production version. 1.3.0 is past the eighteen months of a newer version and by the instructions isn't a valid version to use.
Good Luck
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Elinor Chang
Ranch Hand

Joined: Jul 30, 2003
Posts: 58
Thanks Mark. Now I got another one. I was trying to build the server stub and got the following error. Does that mean my rmic is not up to date?
rmic -d . engine.ComputeEngine
ComputeEngine_Stub.java:40: expecting an identifier, found '{'
java.lang.Exception: exited with errorcode 1
at java.lang.Throwable.<init>(Throwable.java:38)
at java.lang.Exception.<init>(Exception.java:24)
at kaffe.tools.compiler.Compiler_kjc.compile(Compiler_kjc.java:44)
at kaffe.rmi.rmic.RMIC.compile(RMIC.java:826)
at kaffe.rmi.rmic.RMIC.processClass(RMIC.java:90)
at kaffe.rmi.rmic.RMIC.run(RMIC.java:73)
at kaffe.rmi.rmic.RMIC.main(RMIC.java:52)
Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

kaffe

It looks like you might have an older version.
I highly suggest you download SDK 1.4 for the SCJD assignment, especially the newer assignments.
Mark
Elinor Chang
Ranch Hand

Joined: Jul 30, 2003
Posts: 58
Ya, I think so too! Thanks for your timely response...
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11432
    
  85

Hi Elinor
Normally I only see kaffe installed on Linux systems. Is that the case?
The instructions do require you to use a Sun SDK. You should not use Kaffe, (or Blackdown, or IBM's JDK or GCJ). If you can, I would recommend you remove kaffe from your system so that you can ensure that there are no conflicts. (speaking from experience, compiling with Sun's compiler then accidently running under gcj causes some real interesting problems
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Elinor Chang
Ranch Hand

Joined: Jul 30, 2003
Posts: 58
Andrew, I was not aware of THAT requirement of the SCJD. I am indeed using LINUX system and using IBM's JDK 1.3.0. I am actually planning on using this configuration to take the SCJD exam! Are you saying it will be a problem? Um... That does not sound good, I guess, I will have to reconfig my box to take the SUN's JDK instead.
By the way, my little example program does work now.
Thanks!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11432
    
  85

Hi Elinor
You might want to check your instructions.
In Fly By Night Services (airline) it states that "the submission that you return must have been tested and shown to work under a production (not development) version of the Sun Microsystems' Java 2 platform."
In UrlyBird (hotel) it states that "the submission that you return must have been tested and shown to work under a production (not development) version of the Sun Microsystems' Java 2 platform and that platform must not have been superseded by a new production version for more than 18 months by the time you make your submission."
Bodgitt & Scarper (contractors) has the same statement as UrlyBird.
Regards, Andrew
Eugene Sun
Greenhorn

Joined: Aug 09, 2003
Posts: 17
Originally posted by Mark Spritzler:
No you do not need a web server. you would only need a web server if you are dynamically downloading the stubs. In this case you are not using Dynamic downloading. The stubs will be with your client.
Here's a way to test. Create your object that you will bind into the registry. Run RMIC on this class to produce the stubs, etc. Then run the registry, run the class that will bind the object into the registry.
Create a client class that will lookup the class in the registry and call a method on the remote object.
That is a simple way to explain it. You might want to make sure you classes are all in your classpath.

Um unfortunately you might need to upgrade to a newer production version. 1.3.0 is past the eighteen months of a newer version and by the instructions isn't a valid version to use.
Good Luck
Mark

Mark,
This is Eugene. I was research an answer to my question and saw your answer mention "dynamically loading server classes", and thought you might be able to shed some light here for me also.
I am working on the Flight by Night service project. My hurdle right now it to get codebase to work the way I want.
You mentioned that you have to have a web server to have "dynamically loading server classes" to work. I have not tried web server approach for my java.rmi.server.codebase URL, I am testing file:/// approach, the below is my command line
java -Djava.security.policy=server.policy -Djava.rmi.server.codebase=file:///c:/scjd/deploy/server.jar -jar server.jar localhost 6000
server.jar contains the server classes (stub, remote interface, remote interface implementation classes), and I put server.jar in the classpath of the server's JVM.
on the client side, I have
java -Djava.security.policy=client.policy -jar client.jar localhost 6000
client.jar only contains the GUI, Data Client class that calls the server.
And I then put client.jar in the classpath of the client's JVM.
I expect the clent would find server classes from the server's codebase at runtime, but when the client's calling
Naming.lookup to find the remote object and then cast the result to my remote interface type, the JVM could not find the remote interface class.
Is it because the file:/// approach doesn't know how to dynamically load server classes to client JVM ?
I did successfully download the stub class from the client, if I had my remote interface class (just one class) to the classpath of the client's JVM.
Will the web server approach be able to load server classes other than the stub class even if I don't put those classes in the classpath of the client's JVM ?
Thanks,
Eugene
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11432
    
  85

Hi Eugene
Welcome to JavaRanch.
I'll start with some suggestions of how to avoid your issues altogether, before actually answering your questions.
If you start the RMI Registry from within your application, you do not need to set the codebase.
If you copy the stub files into the client jar file, you will not need to dynamically download them.
Now to your issues...
...you have to have a web server to have "dynamically loading server classes" to work...
Is it because the file:/// approach doesn't know how to dynamically load server classes to client JVM ?

This is not strictly true. Dynamic loading using file:/// URIs can occur if the client and server are both on the same computer. This is obviously a big limitation - most people want to have the client and server on different computers, and to do that you would need an HTTP server or an FTP server to dynamically download the stubs.
Sun describe dynamic downloading on this page: http://java.sun.com/j2se/1.4.2/docs/guide/rmi/codebase.html This also gives useful troubleshooting tips.
Here is some code you could try to see if you can get it working.
First the interface (which should be in both the client and server directories):

Now the server code:
Finally the client class:
You also need a policy file for the client:

Compile them all, and run rmic against the server.
Make sure you start the registry in a totally different directory to the server code. The command lines I used are listed below. Hopefully you will note that the directories are different for all three command lines:

Regards, Andrew
[ August 09, 2003: Message edited by: Andrew Monkhouse ]
Eugene Sun
Greenhorn

Joined: Aug 09, 2003
Posts: 17
Welcome to JavaRanch.

Thanks Andrew, I am glad to be on board, this site seems to be melting pot for java techies...
regarding your comment,
If you start the RMI Registry from within your application, you do not need to set the codebase.
If you copy the stub files into the client jar file, you will not need to dynamically download them.

How do you start the RMI registry from my appliation ? I haven't seen any documentation at java.sun.com so far yet..
I understand that copying stub files to my client jar will save the effort for the client JVM to try to load server classes dynamically, but that's not the issue I am having. I am able to load the stub classes dynamically if I package JUST my remote interface class into client jar, not remote interface implementation class or remote interface implementation stub class (both the implementation and the stub packaged in the server jar).
I think it was not being clear enough about my issues.
on my server side, I have remote server interface, remote server interface implementation and remote server interface implementation stub classes packaged in a server jar and this jar is the referenced in the java.rmi.server.codebase when the server is started, and of course the jar is stored in the runtime classpath of the server's JVM. ( and I have my database classes in another jar and added to the runtime classpath of the server's JVM)
on my client side, I have this client jar that only contains GUI classes and database classes no server side classes at all.
That got me in the position of not able to find remote server interface class at runtime, when the client JVM is executing the code like yours

the DBRmote class

First the interface (which should be in both the client and server directories):

What you suggested essentially is the same as my approach of packaging my remote interface class into my client jar which I have tested working succesfully before I posted my question yesterday.
I thought I could get it to work even when the client JVM doesn't have any of the server classes in it's classpath, all the code including remote interface, remote interface implementation and remote interface implementation stub will be just loaded from server's codebase at runtime.

I hope I am being clear enough now, so what do you think now ? Is what I am trying to accomplish technically doable ?
Again I am testing the file:/// approach with my server and client running on a same physical box, I am planning to test out the web server shortly
Thanks,
Eugene
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11432
    
  85

Hi Eugene
How do you start the RMI registry from my appliation ? I haven't seen any documentation at java.sun.com so far yet..

The java.rmi.registry.LocateRegistry class will allow you to start the registry programatically.
I hope I am being clear enough now, so what do you think now ? Is what I am trying to accomplish technically doable ?

I think it should be doable. Perhaps you could post the exact exception you are getting, and we can try and work out what is going wrong.
Again I am testing the file:/// approach with my server and client running on a same physical box, I am planning to test out the web server shortly

The file:/// approach should work as long as client and server are on the same computer. If they are on the same computer then the web server approach should not make any difference.
As an aside, the new assignments (Contractors and Hotel) have the following requirements:

To avoid unnecessary complexity in the marking environment certain restrictions are placed on solutions that use RMI. Specifically:
  • [list]You must not require the use of an HTTP server.
  • You must not require the installation of a security manager.
  • You must provide all classes pre-installed so that no dynamic class downloading occurs.
  • You must use RMI over JRMP (do not use IIOP)


  • So although you can get away with dynamically downloading your code (and even using a web server) because it is not specifically disallowed, you might want to think about whether you really want to do something that Sun are explicitly stopping people from doing in later assignments.
    Regards, Andrew
    Eugene Sun
    Greenhorn

    Joined: Aug 09, 2003
    Posts: 17
    Here is the error I am getting while trying to start my GUI client

    Line 69 is the Naming.lookup line in the source code below

    My server starts succesfully, again, I have the database and server classes in the classpath of the server JVM, but just the GUI client classes in the classpath of the client's JVM.

    So although you can get away with dynamically downloading your code (and even using a web server) because it is not specifically disallowed, you might want to think about whether you really want to do something that Sun are explicitly stopping people from doing in later assignments.

    thanks for your input, I will think about this...
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11432
        
      85

    Hi Eugene
    Sorry, just reread your earlier post, and in conjunction with the error you posted, I now understand what you are trying to do. Now I am changing to say it cannot be done.
    The exception you are getting is not an RMI issue - rather it is the JVM complaining that it doesnt know what a DataServer is so that it can typecast the returned remote class.
    The interface does need to be on the client side. You cannot dynamically download it. You need to have the interface available to the client when you compile so that you can use the methods of the interface, and when you deploy so that the JVM can cast the class correctly.
    The only things that can get dynamically downloaded are the stubs and any serialized classes.
    Regards, Andrew
    Eugene Sun
    Greenhorn

    Joined: Aug 09, 2003
    Posts: 17
    Thanks Andrew, feels like I've got a closure to it. Now I am moving on to test the web server approach.
    I am really eager to wrap up this SCJD so I can start studying for the architect exam, that's the one I am dying to start on....
    Eugene
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Running a RMI Application