aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes connection factory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "connection factory" Watch "connection factory" New topic
Author

connection factory

walid aly
Ranch Hand

Joined: Nov 06, 2002
Posts: 38
can u plz help me how to make a connection factory class that return a unique rmi object for each rmi connection.
although of course i am having only one instance of the data class
thanks
walid
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194

Hope this helps.


Mag
Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
Hello again Mag!
Is the code snippet you provided how we track which client has locked which record? If so, since this is done on the client, we need to pass this object as a parameter into the lock and unlock methods, right? That way, our lock code can persist who locked what, and our unlock code can ensure the person attempting to unlock the record is the current owner.
Do I have this right? Or is the client ID generated differently.
Thank you kindly,
Dave.
walid aly
Ranch Hand

Joined: Nov 06, 2002
Posts: 38
i am sorry but can u plz clarify more
i have in my design one class that extend unicast and implement the data interface that inturn extend remote interface.
i juyst run this class and bind it , and to this instance the clients connect
where should i add the factort with the factory method
and when will it be invoked
i really need ur help
thanks
Daniel Chen
Greenhorn

Joined: Oct 07, 2002
Posts: 24
Hi Dave,
When and why can a client unlock a record that doesn't lock by itself?
Jacob George
Ranch Hand

Joined: Jun 26, 2001
Posts: 46
Originally posted by walid aly:
i am sorry but can u plz clarify more
i have in my design one class that extend unicast and implement the data interface that inturn extend remote interface.
i juyst run this class and bind it , and to this instance the clients connect
where should i add the factort with the factory method
and when will it be invoked
i really need ur help
thanks

Hi,
If you want to implement a factory,the data server class which extends UnicastRemoteObject needn't be bound to the registry. Instead, create one more class named ConnectionManager or so which extends UnicastRemoteObject and should also have a Remote interface of its own. Bind this ConnectionManager to the registry. This instance will be looked up by clients. A call like getInstance() on the ConnectionManager returns data server class which u have already created. In this case each call to the ConnectionManager's getInstance() returns a new remote data instance to the client.
But as you have already noticed, we should have only one local data object. So classes should be designed in such a way that all the remote instances refer to the same local data object. So the method body of ConnectionManager's getInstance() should be somewhat like,
public RemoteDataInterface getInstance(){
return new RemoteDataObject(localObject);
}
So, for each invocation, a new Remote object will be created, but all of them refer to the same local data object. Hope you understood the idea.

regards Jacob
walid aly
Ranch Hand

Joined: Nov 06, 2002
Posts: 38
thanks alot for clarifing this to me
i have one more question

I have implemented already the ConnectionManager and created a unique RemoteDataObject for each connection ,but how can i get a refrence of this unique RemoteDataObject ,
in the lock method of class Data , i tried "this" but it returned a refrence to the same Data object. plz advice.
also did u change the signature of the lock method??, am i right in having the key value pair in hash table as recordnum,a unique RemoteDataObject ...
thanks alot for everything
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by walid aly:
I have implemented already the ConnectionManager and created a unique RemoteDataObject for each connection ,but how can i get a refrence of this unique RemoteDataObject ,
in the lock method of class Data , i tried "this" but it returned a refrence to the same Data object. plz advice.
You cannot get a reference to RemoteDataObject without passing it in, which would require you to change the signature. But this modified signature goes against requirements and would cause trouble in local mode. You could also overload the lock() method. However I would suggest you do neither. I would contend that the Data class is the wrong place to implement locking.
Think in terms of responsibilities -- in a good OO design, every class has a single, well-defined responsibility. In my design, the responsibility of the Data class is to provide a local database implementation. Arguably, a local database is necessarily single-user and does not need locking. The lock() and unlock() methods can be simple placeholders.
- Peter
[ November 09, 2002: Message edited by: Peter den Haan ]
Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
Daniel,
The reason we want to know the client ID in the unlock method is to enforce that only clients that obtained the lock on a record can free the lock. This may seem strange that a client would try to unlock a record they do not own, but it could happen if a client was behaving badly.
--Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connection factory