• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling CallBack or Broadcast in RMI

 
Swapnil Sapar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm just jumping around RMI classes till I get my programming assignment.

I've a doubt regarding the handling of CallBack or Broadcast mechanisms in RMI client server environment. I can always inform (pass a message) to server from client but when it comes to the server to inform something to client, my thread slows down
e.g. If I want to broadcast a message "server going down" to all the clients connected to it. Basically I'm looking for a mechanism of calling a client's method from server by passing some message object.

I couldn't find a definitive, commonly used approach for this. I finally implemented a thread mechanism in which a client thread is constantly locked into the Server till some message appears in the server Q for broadcasting. And then the method returns to client with the message and then again gets locked with server. But then it was getting complex and risky with all the use-cases coming together.

Instead I'm more interested in knowing if there is any traditional, more sophisticated mechanism already available in Java RMI world?

I browsed though the SCJD topics but couldn't find anything which is classical.

Thanks in advance,
Swapnil
 
Swapnil Sapar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found an approach here which achieves this...
Using RMI with Client-Side Callbacks

and

An in-depth look at RMI callbacks

In this they suggest to expose client side object on an anonymous port.
Secret lies in
http://java.sun.com/j2se/1.4.2/docs/api/java/rmi/server/UnicastRemoteObject.html#exportObject

Its really easy.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swapnil,

Another useful article, which includes information on client-side callbacks, is Sun's jGuru: Remote Method Invocation (RMI) article.

Regards, Andrew

P.S. Yes, this is easy to do. However when you get your assignment you will find that you will not get any extra marks for going beyond the specifications (and there is no need for you to update all the clients when shutting down the server or when a different client makes a booking).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic