Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI Project Questions  RSS feed

 
Roger Shields
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to RMI and am doing a project in school using RMI.
I need to write a client server type application utilizing RMI instead of standard object serialization over sockets.
Now my question is how to lay out my classes and how the objects will interact with each other.

In a previous assignment, we wrote a database "engine" that reads from a file.
The server is to be an intermediary to the database.
The client will call methods to the server to get values back, or modify values in the database.

What are some recomendations on how to implement this with Java RMI? Thanks.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make an interface for your server, put all the methods that you want the client to be able to call in this interface. Make the interface extend "Remote", and make all the methods throw RemoteException. Implement this interface in a class that extends "UnicastRemoteObject" - this will be your server class. Wrap an instance of your existing database class in this new class and delegate all remote method calls to the wrapped database instance. If the objects you're returning from your database aren't serializeable, you'll need to make them so. Add a main() method to this class (or make another class with main() ) and make a call to Naming.rebind("somename", instance of your new class); Run rmic on your new server class to produce stubs (unless you're running JDK 5+, then this is done automatically). Now, start rmiregistry in one command prompt window, start your server class in another, and start your client in another - you may run into other issues - problems with serialization, security settings, etc. Refer to this page for an easy HelloWorld example.
 
Roger Shields
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathan, that helped a lot, but I have one problem that I can't seem to find an answer to. In the link you gave me, the author uses
but when I use that I get a java.util.MissingResourceException:
Is this a custom ResourceBundle that he made himself or just spelled incorrectly in his examples? What would be another way to get around getting the port number from the resourceBundle?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a custom bundle he made himself - it's the RMI.properties file mentioned in the page.

If you don't want to go with using a property for the port, you can completely leave the ResourceBundle stuff out and just specify the port directly in the code. Or you can just leave it out altogether and the RMI Naming server will default to port 1099.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!