|
public class RmiBookModelImpl extends UnicastRemoteObject implements BookModel {
private ArrayList observers = new ArrayList(10);
public void addObserver(BookView bv) throws RemoteException{
synchronized(observers){
observers.add(bv);
}
}
public void update(int recNo, String [] data)
throws RecordNotFoundException, RemoteException{
BookView bv;
Integer recObj = new Integer(recNo);
//db is the Data class.
db.update(recNo,data);
for (int i=0; i<observers.size(); i++) {
try{
bv = (BookView)observers.get(i);
bv.update(recObj);
}catch(Exception e){
//if failed to update.the server will believe the observer is shuted down.so the server delete it.
observers.remove(i);
}
}
}
...
}
Originally posted by song bo:
I define 3 interfaces for model,view ,controller.then I implement these interfaces separately for Local mode and RMI mode.
Originally posted by song bo:
1.Refreshing all the view of the clients is slow.especially some clients is disconnected.
Originally posted by song bo:
2.when the network of one client named "A" is dropped,at this time,another client book a record.the model will delete the client "A" that could not be refreshed.after a while the network of client "A" resume normal,it can be booked but the View can not be refreshed for ever.because the view of "A" has deleted.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Do you mean that you have one view for displaying records when you are in local mode, and one view for displaying records when you are in networked mode?
If so, then I think you will loose points in the OO section of the marking.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I take it that your Model is on the server then. Is your Model the database itself? Or is it a model of the database?
I asked before whether
1.your model was on the server.
This would mean that at a minimum your Controller(s) and possibly your View(s) need to be aware of the communications protocols involved.
Right now you might only have one View. But in the future that might expand to 10 Views, all working off the same Model. And if someone then decided tp change the network protocol, all 10 Views and the 10 Controllers will need to be modified.
2.your model is the database
If this is the case, then ask yourself whether there is any work done on the data at any point before it gets to the View. For example, do you convert any of the Strings into Integers, or do you convert the array of record numbers returned by the call to find() into an array of Records() (or an array of String[])).
If so, then isn't this sort of conversion likely to be common to the entire application? In which case wouldn't this logic be better in the Model rather than in the View? (You don't really want much logic in the View - it is only meant to be displaying the data, not doing large amounts of database specific processing.)
I could not understand still
if you have distributed many client programms and they have all worked fine.But after a time,the boss decide to change the book rule.because the business is wrapped in the client,so you have to modify every client programm and distribute again,if you put the model on the server,you only modify the server code,the clients do not know,because the client only guther the data that user input and pass it to the model,so it need to change.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |