• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

? Client ID ?

 
amit ahuja
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm sure we have discussed this b4 but never came up with any concrete answer to my knowledge.
We know how RMI works with possibility of differnet thread for consecutive requests from same client. And also most of us are against changing signature of lock() and unlock().
So when booking has to be done. Client calls
lock(x) -> read(x) -> modify(x) -> unlock(x)
Now how to make sure that lock(x) and unlock(x) is called by same client (one of our requirements..)
If lock, modify and unlock is called form server itself , threadID works. But our lock unlock shud be implemented independently and take care of clients calling it.
I'm sure we have better alternative, please help.
amit
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Amit:
Let me try to help you out. I will explain how did I do it.
I did not give any chance to the clients, so that they can call lock and unlock methods directly. If everythings goes all right (I mean, no input error in number of desired seats to be booked), then clients can only call confirmBooking methods of my RemoteData class. So far so good. My confirmBooking method is commited book a flight, right. First it locks the record. I mean calls the lock method. Then reads the record, modifies it, and at the end unlocks it. Let me show you sample code.

I'm sure we have better alternative, please help.
I do not know it is a better alternative or not but it worked for me. If you call confirmBooking methods you follow the process of lock, read, modify, and unlock. Even I did not bother to keep track of client Id. Does it make sense to you? If it does, I would be glad being some help.
-Bal
[ February 20, 2002: Message edited by: Bal Sharma ]
 
amit ahuja
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definitly it makes very sense to do so.
But at same time i was wondering what will happen if in next version somebody wants to add new features and want to use lock(), unlock() from client itself ?
In your implimentation we force the use of lock() and unlock() to the server. And if that is the case, why we are asked to have "a class that implements the same public methods as the suncertify.db.Data class" at client side? I mean why are we trying to expose lock() and unlock() to client?
amit
* ur comments are very valuable *
 
Rajesh Matti
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amith -
1. You can make dataclass extend unicastRemoteObject and use getClientHost() to recognize the current client (I prefer it better than the thread ID).
2. Need to store the client id + record number somewhere in your locking mechanism.
3. You can also achieve #1, simply by wrapping dataclass (only one instance) inside a remote data class (one per client) and do some locking tricks before forwarding client call to lock and unlock of the data class.

I am not sure if I addressed your question. Please let me know.
-Rajesh
 
amit ahuja
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh,
You r right on the mark in answering my query.
Now IP address from getClientHost() is good but we are limiting one client from a machine and what if a group of users are working from a n/w behind a proxy (I'm not very good at n/w fundas).
Storing of clientID and record no. is being done good enough in my LockManager which i tested with 100000 threads..(second thot, that was a crazy no.)
The big brother is this clint ID.
I liked ur idea of "do some locking tricks before forwarding client call to lock and unlock of the data class" and 'm gonna brain-strom on that.
Still long way to go...
amit
 
Rajesh Matti
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, have a seperate remote data class (which wrapps a sigle data class) for every client request,You are fine !!!
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your implimentation we force the use of lock() and unlock() to the server...
Yes sir! I do. I am not trying to expose lock() and unlock() to client. It is not a client business. I do not know how strong and healthy is my decision. We got to see it when result comes out.
Let me describe my decison choice here, it might pop up some new ideas for you. Below is the comment for my Data class.
The Data class provides services for the local database. This program is designed so that there will not be a situation where two clients can concurrently access the local database while the program is running in the local mode. Therefore the sequence methods of lock, read, modify, and
unlock are not necessary in the Data class. The methods lock and unlock have been excluded from the Data class.
And I deleted lock and unlock methods form SUN supplied code. I designed RemoteDAta class, it has following comment.
REMOTEDATA CLASS INSTANTIATES REMOTE OBJECT TO RUN PROGRAM ON REMOTE MODE. THIS IS MAJOR DIFFERENCE BETWEEN REMOTEDATA AND DATA CLASS.
REMOTEDATA CLASS IMPLEMENTS lock,unlock, AND lockRecordOrDataBase METHOD BESIDE WHATEVER IT IS IN DATA CLASS.
So, if you create Data object, there is nothing to do with lock and unlock process. It is open for single user. If you are in remote mode, you create RemoteData class object. When you call booking method automatically you got to follow lock, read, modify, and unlock procedures. If you have lock, unlock it, it you don't, you don't. If you do, and it is not unlocked yet. You wait. I do not know how good and robust it is. I will know when I get result.
Keep it up and good luck. -Bal
 
amit ahuja
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bal,
I'm sure ur implementation is robust and good. And will be adored by examiner when combined with the justification u have given.
I'm using ClientID and no deletion of lock unlock methods. Let's see if i can convince the examiner with my justification.
I have useded some delegation and "played tricks" (in Rajesh's words) and same time tried to stick to requirements as i understand them.
Will keep posted, as my present code matures...
All the best
amit
[ February 22, 2002: Message edited by: amit ahuja ]
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no need for any client ID. Each connection object identifies itself. Please look at some of the threads where Peter Den haan, Mark and others have discussed the solution.
Good luck.
 
Vivek Rana
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kalichar,
What u mean by Connection Object ???
are u using yr lock and unlock in side the modify method ? then u are right u don't need it.
Couldn't find the thread.. where the solution is disscussed .. please help

Rana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic