Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sending notification/events to client of RMI  RSS feed

 
Ariffin Ahmad
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm just trying the functionality of RMI.
i tried to created a java beans, which will fire an events in some conditions. the problem is, the events is catch by the RMI server, not at the client as it suppose. is the any way, i can notify clients for any changes in the server, beside using fireChanges()?....
thanks......
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Event messaging between remote systems is a bit tricky. Here's what has to happen:
- The client must register interest in the events fired on the server side. To register, the client must be remotely available to the event source object.
- In order to be able the register, the client must find the server to begin with, so the server object must be remotely available to the client.
Ick, right? And that's the simple pattern for implementing remote event handling.
A few weeks ago I started a tutorial that was heade down this path -- it's right here, and I'm hoping to add something to it before the end of the week. Alas, the need to make the rent has interfered and I'm not able to add to it as quickly as I'd like.
If you can't wait, however, that's the key: both sides have to be remotely available for the messaging system to work.
 
Ariffin Ahmad
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...
not really clear, actually, but still can help... )
but, where can i reach your tutorial?...
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ariffin Ahmad:
thanks...
not really clear, actually, but still can help... )
but, where can i reach your tutorial?...

Michael meant that server as well as the client must be remote objects.
Michael correct me if i'm wrong!
Let all clients implement a Remote interface.
RemoteClientIfc extends Remote {
void inform();
}
have a remote method register() on the *Server* object which accepts RemoteClientIfc.
c'd be something like this...
register(RemoteClientIfc client){
arrayListofClients.add(client);
}
So client will do a look up on the remote server object and register itself.
remoteObj.register(clientInstance);
In the remote server you
can probably have another method to send notifications to the client.
Run through the ArrayList and call
inform() on each of them.
Thus the client will receive notification.
tellClients(){
Iterator i = ....
while(i.hasNext()){
((RemoteClientIfc).i.next()).inform();
}
}
Can change the method signature if you want to pass some object to the client.
Looks very similar to the awt event notification mechanism does'nt it?
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ariffin -
The tutorial in this forum is here. We haven't gotten to messaging just yet; as I mentioned it's non-trivial, so it takes a while to get there from square one.
 
Ariffin Ahmad
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried that, and it's work....
thank a lot!....
but i notice something....
i have to run rmiregistry and webserver(for downloading stub purpose)on both machine, so that both client and and server visible to each other....
what i really need is, the client don't need to run that rmiregistry and webserver. all it has to do is just to find the remote server and then, run the remote method. and, when necessary, the server will update the client.
is this possible to do?...
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure! If the client knows the hostname and port number the server is running on (and vice versa), there's no need for a lookup service at all. rmiregistry is intended as a convenience and a de-coupling agent; it's not required.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!