• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Callback in SCJD Assignment

 
Jose Ortuno
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need you opinion.
I am using RMI as my connection choise, I almost finish my assigment for the SCJD and I have try to keep my desing as simple as possible, so In my MVC I am using a DefaulTableModel in my server wich is able to broadcast the events to all registered client by using callback method.
Client > Register > server
[Listener]--------->[TableModelListener]
[Event Received]
[RemoteMethod]<------[For All Listeners]
It is Ok, to use callback even though some people think are not pure OO approach?.
Thanks.
PD: Any sugestion are wellcome.
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jose,

so In my MVC I am using a DefaulTableModel in my server wich is able to broadcast the events to all registered client by using callback method

What do you mean by "callback"? Why don't you use the events to notify interested objects? The default way of a table model to communicate with a JTable is via TableModelEvents. The table model generates these events, and JTable (which implements TableModelListener) is notified by these events.
When you use a DefaultTableModel, you simply pass the model to the table (e.g. by using the constructor JTable (TableModel tm) . Then you can modify the table model by using the table model methods, and the table (which is the view) is updated automatically.
Hope this helps.
 
Jose Ortuno
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for writing Mag,
What I mean with "callback" is a remote method in my "Client" that can be executed from the "server".
I agree whit you. The esaiest way to handle JTable events is by using DefaultTableModel-TableModelListener because it automatically updtates my view (the JTable).
However
how can I broadcast the event to all clients?In my desing the Client implements TableModelLister. The server have the only instance of the TableModel which is shared among clients. So the server is responsible to notify all clients when the model is updated by calling fireTableChanged().
The main issue is to broadcast the event. how can I notify all clients? My understanding is by calling a method, which could be TableModelListener.tableChanged(TableModelEvent) in all clients. That seems very easy. But I can't because when I register the client in the server by using addtableModelListener RMI creates a copy of the object in the server.
Therefore I consider to use a remote method in the client(call the client back).
I don't know if I should consider review my desing but it seems ok to me .
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose, you do not need to notify all the other clients when one of the clients has booked a flight.
Mark
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My instructions even stated this quite explicitly. That's more than two years ago, mind.
- Peter
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jose,
check your instructions. Mine also explicitely stated that there was no need to notify the client on a change. That is about 6 months ago.
And if you feel the need to have some notification mechanis, I'd suggest to use Event/EventListeners. That is less coupling than callbacks.
Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic