SCJP (1.4), SCWCD, SCJD
on the RMI side
RemoteConnectionInterface.java (extends ConnectionInterface and Remote)
RemoteConnectionInterfaceImpl.java (is the implementation of the above interface), and i am registering this Impl class with the registry.
This implementation class holds a private instance of the DataAdaptor, which inturn holds a private instance of Data.java.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
I don't think it would be a good idea for you to distinguish your clients on the Data class itself. There should only be one Data class per database file for all clients. Meaning all your clients should share one Data class. What you want is a wrapper around the Data class that is unique for each clients.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Qusay
SCJP (1.4), SCWCD, SCJD
Do i make any sense atall
That said, if i dont choose individual Data instance, i wont know which client locked which record, and when i want to call the updateRecord() method i wont know which lockCookie i need to pass. If i use individual Data instance, i can use Data.this as the lockCookie, and i can store the recNo this instance has locked in a WeakHashMap.
Originally posted by Philippe Maquet:
Hi Arun,
Lock cookies are returned by lockRecord(), probably generated as random long values. Data.this is not a long cookie ! Unfortunately, I think that mapping Data instances to recNos in a static WeakHashMap is a solution which does not apply to assignments where cookies are used in lock() (as mine BTW). Now, I am just thinking to another possible solution : if you map cookies to recNos is a static WeakHashMap (where keys are cookies as Longs and values are recNos as Longs) , and if your Data instance (one per client) keeps the cookies it received in some HashMap as Longs, you should get the same protection against deadlocks caused by crashed clients. BTW, don't forget the notification issue of the WeakHashMap solution. I discussed it here recently.
Best,
Phil.
SCJP (1.4), SCWCD, SCJD
Am i on track?
SCJP (1.4), SCWCD, SCJD
SCJP (1.4), SCWCD, SCJD
Originally posted by Andrew Monkhouse:
Hi Amish,
I think it depends on the assignment. There are some assignments where having a unique Data class for each connected client makes perfect sense.
Regards, Andrew
Lock cookies are returned by lockRecord(), probably generated as random long values. Data.this is not a long cookie ! Unfortunately, I think that mapping Data instances to recNos in a static WeakHashMap is a solution which does not apply to assignments where cookies are used in lock() (as mine BTW). Now, I am just thinking to another possible solution : if you map cookies to recNos is a static WeakHashMap (where keys are cookies as Longs and values are recNos as Longs) , and if your Data instance (one per client) keeps the cookies it received in some HashMap as Longs, you should get the same protection against deadlocks caused by crashed clients. BTW, don't forget the notification issue of the WeakHashMap solution. I discussed it here recently.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
you are saying that in the DataAdapter class which keeps an instance of the Data class to do all the work, you should keep an instance variable declared as Long.
How will the WeakHashMap know that the reference that it has stored as a Long (not long) has disappeared in the case when the client crashes?
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
SCJP (1.4), SCWCD, SCJD
The HashMap is needed since you are allowing the guiclient to choose multiple records from the JTable. So when calling unlock from DataAdaptor, i will know which lockCookie to send back to unlock. After a successful unlock i have to remove the corresponding entry from this HashMap.
In my case i dont allow multiple selections from JTable, so i will always allow only one lock per guiclient. So in the DataAdaptor class i can have two instance variables which will store the recNo and the returned lockCookie.
SCJP (1.4), SCWCD, SCJD
Originally posted by Philippe Maquet:
Hi Arun,
You have three levels : DataAdapter --> Data --> lockedRecords (static in Data).
The cookies/recNos key/value pairs are already stored in lockedRecords. Data only needs to store cookies as Longs, for the only purpose of helping WeakHashMap lockedRecords to track crashed clients. DataAdapter methods which call lock() need to keep the cookies/recNos pairs in order to be able to unlock the records they locked. Now, in DataAdapter, if you never lock more than one record at a time, of course just save the recNo and cookie in two simple long variables. Else, a HashMap could be OK or even two long arrays (if locks are handled locally as a whole within single methods).
Best,
Phil.
SCJP (1.4), SCWCD, SCJD
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|