• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

my lock mecanism NEED GREEN LIGHT

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All

preparing the following
///////////////////
i am using rmi
1.class data,lock manager singelton.
2.local and remote acess can happen at the same time;we need to implement lock in local too.
3.client id in cass of remote access is a unique remote object ,in case of local ,clientid is the current data object.
4.only one user can go local on the same jvm
5.all lock mechanism happen in server side
//////////////////
now the mechanism itself......
a-in case of remote acess , the clients will acess the lock method in class rmidataserver which can easily define the clientid as the unique remote object,and then will invoke the lockmanager class which has a hashmap with clientid and record.
b.in case of local acess, the local client will acess the lock method in class data directly and this lock method will direct him to the same lockmanager and add in the same hashmap.
///////////////////////////
I NEED SOME ONE TO GIVE ME THE GREEN LIGHT
any commenets are appreciated!
Walid
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds to me like you are using the server in local mode. This is incorrect. there is NO SERVER in local mode. It is a stand-alone mode. So your comment where Remote and Local mode can occur simultaneous is also wrong.
No Singleton is needed in Data or your LockManger. Your code should just create one instance and that is all.
Also I am of the advocate that since local mode is stand-alone, there is absolutely no need for any locking since the records would be locked by the same client anyway. There is no contention or concurrency here for the records.
Mark
 
walid aly
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for ur reply
i had to think that both local and remote are working in same time to write some code in the lock method in class data...
so the question now is
///////////
class data
.
.
public void lock(int rec)
{}
///////////
i.for remote access i am doing all the lock in class rmidataserver which extends unicast, shall i leave the lock method in class data BLANK , or should i change its signature to be lock(int rec, obj clientid ) and do the lock mechnism in it .
ii.since there is no lock in local mode(which now seems reasonable) y should i write anything in data class lock method...

thanks alot
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well there is a few solutions to locking.
If you have a LockManager you can get away with not implementing lock or unluck directly in the Data class and leave it blank.
You can have the Connection object store all the locks for that client, and also have Data class have a collection of locks, so that if the client calls unlock, it checks its Connection object, and if it is in there then it can be passed to the Data classes unlock.
Hope that helps
Mark
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have
public class RemoteDataImplementationextends UnicastRemoteObject implements DataInterface
that holds Data and LockManager. They are as you said only created once in server mode. But how will the lock and unlock of RemoteDataImplementationlook? Must it be sync. and first check look in LockManager and then preform add... on Data?
I am no quite clear on what the RemoteDataImplementatio lock methos should do....
Thanks for a great site...just found it.
Raffe
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"I am no quite clear on what the RemoteDataImplementatio lock methos should do...."
I think call lock() on the LockManager?
Mark
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,

You can have the Connection object store all the locks for that client, and also have Data class have a collection of locks, so that if the client calls unlock, it checks its Connection object, and if it is in there then it can be passed to the Data classes unlock.


Can you explain this more? It seems you implement the locking schema in Data.
And one more question? What is the difference between a singleton and static LockManager in this assignment(one table database)?
Thanks,
Kevin
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a singleton object. the way to create an instance of the object is through a method of the class, rather than through the constuctor. This way the class cna make sure that it is instantiated only once. It has a reference to the only instance that exists, so that this method can check to see if there is an instance to the reference, and if there is return that object, or if there isn't create a first new one.
In a Static Object, The JVM handles the "One class".

As far as the locking goes, it is simple. Using a HashSet in the Connection object, I call lock(), it puts the recordnumber into the HashSet, it then calls lock() on the data class. The Data class has it's own HashSet of locked records. So the Connection object calls lock() on the Data class, it checks its HashSet, if the record number is there, it waits, if not it adds it.
Now when the client calls unlock in the Connection Object, it first checks to see if that record number is in its own HashSet, if it is it allows the call to Data.unlock to go through(), otherwise it fires and Exception which is chained to the client, which says "Hey can't do that, you don't have the lock" or something nicer than that.
So Data never has to check which client has what, that is the responsibility of the Connection Object.
Now after having explained how I did it. I Like the LockManager solution much much better. I only lost 4 points in the entire submission and it was in the server part, and I'd say 2 of them was because I didn't use the LockManager, the other 2 points I missed was not splitting the db and server into two seperate packages.
Mark
 
Kevin Cao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
Thanks a lot. Everything is well explained. The only deduction you had is probably because the relationship between Connection and Data is not guaranteed by RMI, do I understand it correctly?
Mark, do you mind answer this question for me? I always have a confussion about using LockManager. I think somehow, somewhere there should be a static Hashmap or static LockManager that keep track of all the locks, otherwise every remote object will have its own locking system. I know it may not be correct for multiple table database. But for this particular assignment, is this the case?
Need help
-Kevin
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But if the LockManager instance is created in the ConnectionFactory, just like the Data instance, then there will be only one instance ever made, you just pass the reference to it to the Connection Object, and you don't have to worry about multiple contents.

The only deduction you had is probably because the relationship between Connection and Data is not guaranteed by RMI, do I understand it correctly?


Actually no, the Connection is one per client, and the Data class is only one instance in the ConnectionFactory, so the relationship is sound for my lock and unlocking scheme.
The part not guaranteed by RMI is that calls from a client will always go through the same thread everytime. hence why threadID is not guaranteed for each client.
Mark
 
Kevin Cao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Mark. You are always so helpful.
Kevin
 
Raffe Paffe
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark!
 
Raffe Paffe
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"I am no quite clear on what the RemoteDataImplementatio lock methos should do...."
I think call lock() on the LockManager?
Mark


Yes, i understand. But should it handle the databaseexception thrown by lockmanager.lock or throw it?
 
This one time, at bandcamp, I had relations with a tiny ad.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic