I am really confused about the RMI stuff, after reading Roel De Nijs post when he states that he used generated stubs I got confused about this topic. First of all I read Andrew's book and he explains that we should use stubs and mentiones how to create them but I really don't know how to use them.
For instance I used his code to register the database object in RMI not using a factory only registerin the object extending UnicastRemoteObject and that's it. And to give it back to use it as a client I used the Naming.lookup method, but where is the stub getting involved what other steps do I need to do.
Reading a little more I found that you have to use the rmic tool so I went to command line used the rmic tool agains the object that implements the Remote interface and extends UnicastRemoteObject and... that was all, it generated a stub but what do I need to do with it... how do I use it?
I thought that I was near to completion of this assignment and now...
Please take a look at this thread or this thread. I think it might be helpful! I can't really help you more than this because I myself didn't generate these stubs... but maybe my good buddy Roel (or someone else who did generate them) will show up later and give you a good explanation on this
Sorry that my post confused you, that was not my intention
But there is no need to be confused about this one. It is very easy:
- first decide if you want to generate stubs or not. if you decide to generate them, continue the reading (otherwise go have a )
- to generate them you can use the rmic command or you can use the ant task (as shown in this thread.
- after generating them you will see 2 extra class files NameOfYourRemoteClass_Skel.class and NameOfYourRemoteClass_Stub.class (you could also generate sources of these files with an extra option, but that's not needed for the assignment, but if you want to have a look what these classes do, you can do it that way).
- if you see those 2 classes in the runme.jar, your job is finished (and no dynamic code downloading will happen).
You won't see a thing about these stubs, because they are used in the background (just like the program works with jdk 1.5 or higher, even if you didn't generate them). I only generated my stubs when it was time to submit (not during development, just depending on the automagically generating of the stubs, built in jdk 1.5 or higher).
And as a final remark if you want to make sure your stubs are used, have a look at this thread.
if you call your program like this:
you will see when each class is loaded. The output to expect is shown in the last 3 post of that thread.
Hope you now have a clear picture about these stubs.
Ok I got it, it was not that hard after all and no code changes needed to be done.
I did generated them using the command from Andrew book "rmic path.class" and I saw if they were used as the thread you sent me said and it seems they are being loaded so its ok by now. Well its time to wrap-up all and submit the file!
I´m not sure about one thing. I decided to generate stubs but for which classes?
I use a factory, the interface is "DataFactory" and the implementation "DataFactoryImpl". Did I need stubs for both?
Roberto is right about the rmic task, but be aware that rmic ant task does a pretty lame job with processing JUnittest clases, specially inner classes. This will really annoy you if you use TDD (I try to do it most of the time) and want to have complete test cases for the client/server portion... otherwise it will create the stubs and skeletons for help you with no problem.
Ciao for now!
I'm doing laundry! Look how clean this tiny ad is: