• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ignorant RMI question??? Design choice

 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To all-
I have been struggling with an RMi issue on a sample program where I am receiving a ClassCastException if the client and server are in different packages such as :
suncertify.client
suncertify.server
If I put everything in one package, it works great. I've scoured JavaRanch and was wondering what I'm missing here, or if its acceptable to have a 'comm' package and have both the client and server sit in there. Then once I jar this up for submission, I can make a client and server jar for the grader to execute, but there will be a duplication of classes.
Is this acceptable, or conversely, can anyone recommend a tutorial or something that will help me get past my package and RMI issue?
Thank you for your feedback,
Eric McEntee
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to include the stub classes in the client. Unless you have a web server and use dynamic downloading, which isn't necessary.
Mark
 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark-
Thanks for your quick reply, but I'm not sure I understand. I've attempted the following:
1) run rmic on the server package
2) start the rmiregistry on peort 1099
3) start my server with a custom policy file and codebase parameter to the directory where the server classes are.
4) copy the stub and skeleton to the client directory
5) Start the client with a copy of the same policy file.
I have tried copying just the stub, but I'm not sure thats the right thing either.
Am I supposed to be adding a -D parameter to rmic? Right now, I just do this:
rmic suncertify.server.textBasedServer
so I guess, maybe I should be doing something more like :
rmic suncertify.server.textBasedServer
-Djava.rmi.codebase=file:/c:/suncertify/server
-Dsuncertify.server -Dsuncertify.client
I appreciate your patience and assitance.
Thanks,
Eric McEntee
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rmic suncertify.db.ConnectionFactoryEngine
That's all I used to create the stubs etc.
Did you include an import statement for the class in the client package class.
Well, you must of otherwise you would have gotten a compile error instead of a class cast exception.
Can you post the stack trace?
Thanks
Mark
 
Reshma Das
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did u followed the same directory structure for stub class in client.jar ?
If u r using win98 pls be careful the rmic places the stub/skel in a different location. i used to copy the files explicity in to the server dir.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey dude, did you get this one yet?
Paul
 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark-
Sorry for the delay, things get a bit busy. Anyway, I haven't jar'ed everything up yet, but I seem to have gotten a bit further. If I copy the code from my laptop to my desktop, linked through a hub, the machines can ping each other with IP addresses or computer name. Now when I start the server and client with the following, it just hangs until the client returns a "Name not bound" exception.

Server :

Client :

My policy file (I'm sure that this overkill, but it works on the localhost, so I haven't messed with it):


So I guess, what I am going to try tonight is to locate a registry in the server setup, if its not there I am going to create it, and then I'll list all of the objects that are bound to see if I have some sort of network issue.
In the server code, I bind like this:

and in the client, I look it up like this:

Just to refresh, the textBasedServer implements an interface called RemoteTextServer. When I run rmic, I do the following:

and then I copy that entire suncertify directory to the other machine, so this isn't an issue of the code not being accessible.
So after I mess around with it tonight, I'll either post another question, or I will post my solution and maybe this weekend I'll write notes on my experience and post those somewhere for other folks that might have the same problems.
I do appreciate everyone's feedback.
- Eric
 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops, I posted the wrong version of the client lookup, the url has the machine name or IP address instead of 'localhost'. I had reverted back to testing on a single machine, and actually was accepting command line arguments, but must have copied the wrong file to floppy when I brought it to work.
So the lookup actually looked liked:
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you do not need an RMISecurityManager in the server.
So I guess, what I am going to try tonight is to locate a registry in the server setup, if its not there I am going to create it, and then I'll list all of the objects that are bound to see if I have some sort of network issue.

weird question, but how do you start up the Registry? I would just start it in code, it's easier that way.

here, it looks like you might be confused about local and remote versions. The local version does not need a server, nor should it. Local is like MS word, all the data is on your local machine and you don't need a server to get them.
Or you are just doing a simple test and checking to see whether it wants to connect to the server that is on localhost, hence no args, or on another machine which needs the arg to define the location. If it is this later case, just ignore me

and finally. Is this line printing out? If it is then we should know that the object got bound, and the difficulty must be in the client side. At least that would be my guest.
 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Mark.
I'll try removing the SecurityManager from the server.
I was starting the rmiresgistry with a separate DOS on the defauly port after I run rmic. I just read in O'Reilly's Java Network Programming book about how to Locate and start a registry from within the program, so I'll switch to that tonight. It will be a lot nicer to have just a client and server command, rather than all 3.
As far as the localhost stuff, the intent there was if the client is started without arguments, it would use the url "rmi:/localhost/textBasedServer", otherwise it was going to paste in the argument which will be the machine name or IP address. I guess I'm not sure what you meant about the Client not needing a server. I wanted to use RMI either way, and just make that the switch, but maybe it makes more sense to avoid it if its all on the localhost. I really haven't done much to start the project, this is an experiment to see if I can RMI working, or if I should switch to object serialization.
And as far as your last question, I do see "textBasedServer is now bound to the RMI registry". So that would lead me to believe that its the client.
I'm really not convinced its not just a network problem. I'll post my results tonight.

Thanks again for your help.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. Sounds good.
As far a local mode in the requirements, there is to be No server whatsoever in that mode. So there is no RMI there.
Mark
 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark-
Well, I got it to work across the network so I was pretty happy. I have one last question. In the following code, I get the following exception at the line with the bind command.


I guess I thought all I had to do to create a registry was :

have you seen this before? I'm wondering if its not picking up the policy file or something.
Thanks for you advice about the no-RMI in a local implementation. This was really just a program to see if I could get RMI working before I really started, but I appreciate all the feedback.
Thanks,
Eric
P.S. my policy file reads:
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try running it without the policy file and see what happens. ALso use the rebind method instead of bind. Even though you start up the RMIRegistry just before the bind method, and therefore no other object had been bound, rebind is better because, say if there was a n object already bound, then rebind will replace it with the new one.
Also It says it was trying to connect to 192.168.0.3, that is your IP adress for the machine with the server correct?
Hope that works
Mark
 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark-
I can get it to work with the following code snippet, but I get weird results when I try other url combinations like: "rmi://localhost/textbasedServer" or "//textBasedServer" even if I look it up that way on the client.
Can you give me an idea of what format the url should be in? I have seen different versions from the RHE book, an O'Reilly book, and "The Java Tutorial Continued"
When I run it, the output is as follows, the name that is spit out is kind of curious:

Here is the code:

I think aside from the url convention everything seems to be OK.

In addition, how would create the client and server jar? I guess that if you do rmic -v1.2 you just need to copy the stub into both jars as long as the server directory structure is in both. Also, can you have your codebase be out on a network ( like my own website ), or should I have it as a file?
Thanks again for the time,
Eric
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
 
eric mcentee
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark-
I justed wanted to take a moment and really thank you for all of your replies and advice. My experiment is working, and I have a great feel for how I want to implment my RMI solution, how to package it, and more importantly how to make it work for the grader.
My distributed computing background is based on CORBA, object serialization, COM, and J2EE, so my code samples that you've helped me work through were more a proof of concept for me to make sure that I understood the issues with RMI, policy, codebase, and executing the jar. Now that I have made this work, I feel like I can make great progress on the exam and hope to be a regular contributor to the board.
Thanks again for your help.
- Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic