• Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI Question  RSS feed

 
Joel Ricker
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've gotten started with RMI using the tutorial that Sun provides. One thing I'm a little unsure of is when we inherit from different classes. Do all classes I want to use remotely inherit from UnicastRemoteObject or just the object I register with my object server with rmiregistry?

Joel
[ July 06, 2005: Message edited by: Joel Ricker ]
 
Joel Ricker
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I understand now about UnicastRemoteObjects but I've run into some other trouble. What I am trying to do is request objects from my Server but decide on the types of objects at runtime. I've created my Server with a method that my client will call asking for a particular type of object. I want to request instances of that type of object but not have to code in a seperate method for each individual class.

For example, here is my interface for my server object:


My implementation looks something like this:




The ??? stands for the return type I'm trying to figure out. So far I have only created one controller class but want to figure this out so I can make this more dyanamic. Since I can't use the specific interface (MyControllerInterface) I've tried things that the interface inherits from such as UnicastRemoteObject, Remote, or also an interface that I created for my controllers to inherit from.

However, when I try to do a cast on the client side like this:

MyControllerInterface controller = (MyControllerInterface) myServer.createControllerInstance("MyController");

I get some sort of failure -- usually CastExceptions. Is there a way around this?

Thanks
Joel
[ July 06, 2005: Message edited by: Joel Ricker ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should definitely be able to do this - it's the RMI Factory Pattern.

Something is going wrong somewhere though - how are you setting your codebase? Perhaps the client cannot get the actual class of the new implementation that it needs? Are you remembering to export your Remote implementation before sending the reference back to the client? That can cause problems, too...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!