aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI newby question - B&S Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI newby question - B&S" Watch "RMI newby question - B&S" New topic
Author

RMI newby question - B&S

Christiaan Thamm
Greenhorn

Joined: May 29, 2012
Posts: 21

Hi guys

I have B&S as my assignment.

Okay so heres what ive been working on: I implemented a MVC pattern where I have my model interface extend Remote and my model implementation extends UnicastRemoteObject. In my model implementation i have a book method where i implement the lock, update, unlock methods and after this i fire a modelChangeEvent to my view and view implementation to let my GUI class know that the table has changed. This then makes my gui class set a new Tablemodel so that the updated table display gets shown. This model book method gets called from the controller, which gets called from my gui object

This works if im not using RMI. As soon as i use RMI the table doesnt get updated. Well it does backend, the view of it doesnt though. I can only see the customer that booked out the contractor if i refresh my view. Ive tried debugging this. It seems like at the point of calling the book method on the model (the model is the remote object) i cant enter this method for a debug. so i cant see why my modelChangEevent isnt firing.

So the controller gets called to do this:

Contractor contractor = model.readContractor(recordNumber); //this gets my contractor
contractor.setRecordHolder(customer); //changes the contractors record holder (the customer that booked the record)
model.bookContractor(contractor); //the calls the book method below and fires the modelChangeEvent

in the model implemenation:

public void bookContractor(Contractor contractor) throws ContractorException {

try {
int recordNumber = contractor.getRecordNumber();

long cookie = dataAccess.lock(recordNumber);
dataAccess.update(recordNumber,Contractor.toStringArray(contractor),
cookie);
dataAccess.unlock(recordNumber,cookie);
fireModelChangeEvent(contractor);

} catch (RecordNotFoundException e) {
e.toString();
throw new ContractorException("ContractorModelImpl.bookContractor\n" + e);
}
}


The fire change event doesnt happen so it doesnt refresh my table in the gui. I also put a printscreen in this method to see if it gets fired, it doesnt. Im pretty sure im missing some RMI functionality here, im just not sure what is it?

Thanks guys

OCJA, OCJP, OCMJD, OCEJWCD, OCEJBCD, OCEJWSD
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 801
    
    1
So, your question is that when there is an update in the db , the GUI does not update. It is because the update in the db on the server side is not passed back to the client side.
The exam does not require that the server must notify all clients about any changes in the db.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

If I understand correctly: when a contractor is booked, all methods (lock/update/unlock) are executed correctly (so the record is booked correctly server-side), but your client isn't updated.

Your model implementation is exposed through the RMI repository (based on "my model implementation extends UnicastRemoteObject"). Your client talks with this model implementation (using a stub), but it's just an invocation of a method. Nothing more, nothing less. Your model implementation resides at the server and thus you invoke the fireModelChangeEvent method on the server, but the thing that should be updated (your table) is at the client side. I think that's your main problem.

Hope it helps!


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Christiaan Thamm
Greenhorn

Joined: May 29, 2012
Posts: 21

Roel De Nijs wrote:If I understand correctly: when a contractor is booked, all methods (lock/update/unlock) are executed correctly (so the record is booked correctly server-side), but your client isn't updated.

Your model implementation is exposed through the RMI repository (based on "my model implementation extends UnicastRemoteObject"). Your client talks with this model implementation (using a stub), but it's just an invocation of a method. Nothing more, nothing less. Your model implementation resides at the server and thus you invoke the fireModelChangeEvent method on the server, but the thing that should be updated (your table) is at the client side. I think that's your main problem.

Hope it helps!


Hi Roel

You are exactly right thats what happened. Not sure how I missed this, too much coffee and late nights! I changed things around a bit, so that my events fire on my client side instead of my server side, seems to work now

Thanks!
 
 
subject: RMI newby question - B&S