Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI 001

 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In the recent past for this exam, I did preliminary reading on RMI,
and it's only now that I have begun a very simple implementation
using Core Java 2, Volume II--Advanced Features for J2SE 1.3/1.4
by Horstmann and Cornell, pages 342-347, which sets up a most
rudimentary RMI situation.
The class files for this discussion are downloaded from this link:
http://www.geocities.com/eosrubiginosa
and click on the link called something like "obtain ProjectRmi01.jar"
[note: I did not place the link directly from this message here because then
this free web site blocks the file.]
This example follows the text book quite closely, but I have added
some important lines into the ProductServer class:
LocateRegistry.createRegistry(port); //Read about this at this site.
if failure, then LocateRegistry.getRegistry(port); //Read about this at this site.
if failure, give up.
The port is 1099.
Also, this very simply "toy" RMI server, after it goes through the
following operations:
product1 = new ProductImpl("Blackwell Toaster 001");
product2 = new ProductImpl("ZapXpress Microwave Oven 001");
Naming.rebind("toaster001", product1);
Naming.rebind("microwave001", product2);
it puts up a swing alert box; when the "OK" button
is clicked, this means to turn off the server.
When the "OK" button is clicked, the server unbinds thus:
Naming.unbind("toaster001");
Naming.unbind("microwave001");

and, now I come to my question:
after it unbinds, it then exits thus:
System.exit(0);
My question is: is it appropriate for the server to exit in this manner
by calling System.exit(0)?
For this example above, the local host is used, for example,
within ProductClient, you have:
private static Stringurl = "rmi://localhost/";
private static ProductRemoteInterfacep1;
p1 = (ProductRemoteInterface) Naming.lookup(url + "toaster001");
System.out.println("Product 1 says: " + p1.getDescription());
so, "localhost" is used as the machine. I've found that I had to disconnect
my modem connection for this software to run correctly.
Finally, I created two servers: and they are located, respectively,
in packages rmi1 and rmi2.
This leads to my second question which is a follow-up:
1. I start rmi1.ProductServer,
and rmi1.ProductClient and suncertify.ShowRmiBindings applications work fine.
2. I start rmi2.ProductServer,
and rmi2.ProductClient and suncertify.ShowRmiBindings applications work fine.
But, when I click on the "OK" button for the first server, rmi1.ProductServer,
then the second server rmi2.ProductServer no longer works, and furthermore,
suncertify.ShowRmiBindings fails to work.
In other words, is System.exit(0) a suspect call in this?
I'm on a Mac G4 computer (unix based) running Mac OS X (latest version).
Thanks,
Javini Javono
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Yes that is fine to exit that way.
2. Why do you have 2 servers running on the same machine?
Mark
 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

2. Why do you have 2 servers running on the same machine?
Mark

Because would it not be a normal situation for one computer to have
more than one server running on it, where each server uses the
same port? (also, I did it out of curiousity).
So, if I have two servers running, and they each work fine, and stopping
the first server I started kills everything, either
1. It is a weird way that Mac OS X works, or
2. It is the way all Java systems work on every platform,
and if it is the way that all Java systems work on every platform,
maybe I should not call System.exit(0). Instead, maybe I should
simply unbind what the server bound, and not call System.exit(0).
So, I guess this would fall under "general considerations;" that is,
"did you consider that your server might not be the only one running
on the computer?"
Thanks for your response,
Javini Javono
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!