Hi Kevin,
Sorry it took me so long to get back to you.
Originally posted by Kevin Cao:
Max,
This is a follow up question of this post.
My first question is what is different between Registry.rebind() and Naming.rebind()?
essentially nothing, thought the method I demonstrated has the advantage of not forcing your client to have to start registry manually.
Another question is regarding your example: You bound both FactoryImpl and RemoteDataImpl to rmiregistry using Factory pattern. What if I only bound RemoteDataImpl to the rmiregistry, since we only need one object(RemoteDataImpl) to register. Or this is a scability issue, say in FactoryImpl we can create RemoteData1Impl, RemoteData2Impl... Or unique ID? You register RemoteDataImpl with different name each everytime.
Essentially correct. The factory is remote object, and clients bind to it to get their own instance of a remoteData object.
Also, as Mark posted, we create lockmanager in ConnectionFactory(FactoryImpl)only once, so the WeakHashMap variable will not necessary be "static". But in your example, you have the WeakHashMap in every RemoteDataImpl, so it should be "static". Do I understand this correct?
This example was designed to demonstrate an example of locking by using client refs in a weakHashMap: it's not particularly great code. The way I might do do it, in terms of the
SCJD, is to have the each remoteData object have a (non-static) reference to a data object internally. The lock in remoteData would differ to that data member object. The data object would actually be the owner of the static weakHashMap.
Or you could have a ServiceProvider class, which locks, does stuff, and unlocks. There are a lot of solutions available here. The point I was focusing on was the actual locking.
Thanks for answering my question.
Kevin
Happy to help,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4