Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Lock/Unlock on Client side or Server Side Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Lock/Unlock on Client side or Server Side" Watch "Lock/Unlock on Client side or Server Side" New topic
Author

Lock/Unlock on Client side or Server Side

Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
I have two questions.
1) I get the unique remotedata object for each client from the server and on the client side, i use a factory that will wrap the RemoteData in to RemoteData Wrapper and Data into localdata wrapper. Is this okay to do it on the client side.
2) I have a method BookFlight in the wrapper on client side that inturn will call remotedata.lock,remotedata.read,remotedata.modify and remotedata.unlock.
or
should I have a method bookflight in remotedata and
from client side simply call remotedata.bookflight and the method bookflight in remote data will inturn call lock,read,modify and unlock.
Please let me know the advantages of both these approches. Are these approaches correct.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Yes.
Actually the bookflight is on the "client side" and it calls the lock and unlock on the "remote side" you would want the client to do locking, since also in local mode there is no locking done. So it is the server side that you want to lock.
Did that make sense? I just finished writing it and got a confused look on my face.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
So I should have bookFlight on ClientrSide and call bookFlight on RemoteData that will handle lock-read-modify-unlock. I need not make the client call lock and unlock. Is my understanding correct.
Please clarify.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

No, not quite.
What you will have is you have the Data class and you have an interface that has all the public methods of the Data Class, so you have a Remtoe implementation of this interface. You then wrap the interface into a Facade class. The Facade class has the bookFlight method. It is the only class that has the bookFlight method.
So the client calls bookFlight on the Facade class, that class calls the lock, unlock, etc methods on the implementation of the data interface.
Mark
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
Mark, is this correct.
DataInterface(All public methods of Data) implements Remote.
Data implemens this DataInterface.
RemoteData(remoteImplementation) implements DataInterface. This RemoteData has Data and LockManager as instance variables.
On client side I have a DataAdapter interface which has Bookflight,search etc. methods.
LocalDataAdapter implements DataAdapter and it has Data as Member variable. So LocalDataAdapter's bookFlight method will call Data.read,data.modify.
RemoteDataAdapter implements DataAdapter and it has RemoteData as Member Variable. So RemoteDataAdapter's bookFlight method will call RemoteData.lock,read,modify,unlock.
DataAdapter acts as a Facade. Is this what u meant.
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
Mark. can u please tell me whether my understanding is correct.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Very close. I have the Data interface being implemented by RemoteDataAccess and Local DataAccess. My interface name is DataAccess, so the client gets a DataAccess class, creates the Facade passing this class, and away it goes.
I just have one less interface than what you wrote. But that doesn't mean that you are completely off base either. I have seen others with two interfaces.
The Facade is still in the db package. But it will be created and object is on the client, meaning it is not residing on the server.
Mark
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
Thanks a lot Mark.
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
Mark, I have one more question. DataFacade has a DataInterface object and it has a bookFlight method. Then irrespective of whether it is Local or Network mode, bookFlight method will call lock and unlock. In case of Local Mode we need not call lock and unlock as there will be only one client. (Though Lock and Unlock will be empty in Data). Is it okay to call the empty Lock and unlock implementations in Data (but it is not necessary in Local Mode). That is the reason I had a LocalDataAdapter and RemoteDataAdapter. So in LocalDataAdapter's bookflight method, I just read and modify the record. In RemoteDataAdapter's bookFight method I lock,read,modify and unlock. What is your opinion about this.
[ April 02, 2003: Message edited by: Saraswathy Krishnamoorth ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Exactly. In local mode it calls an unimplemented lock and unlock methods.
So if you have the DataAccessInterface, it has the lock and unlock methods, then in your two implementing classes. The one implementing class for DataAccessRemote will have code in the lock and unlock methods. But in the one implementing class for DataAccessLocal, the implementation will be blank. Basically it would look like this

Good Luck
Mark
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
Thank you very much Mark.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lock/Unlock on Client side or Server Side
 
Similar Threads
Implementing Lock/Unlock using Event delegator
question about assignment
To Terry McKee, Rasika Chitnis and others
where to put bookflight() question
Lock and Unlock methods