Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Connection Object

 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ranchers:
My design has a ConnectionFactory and Connection,
I will bind ConnectionFactory to RMI. I believe ConnectionFactory is the only remote object we need to send data to clients. Somebody mentioned
thatConnection also needs to extend UnicastRemoteObject, I am wondering why? Can any one explain it? Since Connection is not bound to RMI, it need not to be a remote object, why does it need to exends UnicastRemoteObject and implement Remote? Thanks.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection object is marshaled by the RMI to the client when you ask for it using the ConnectionFactory. In order for the RMI system to export, marshal the Connection object should extend the UnicastRemoteObject. If you look at the default constructor of the UnicastRemoteObject, it takes care of exporting it.
In order to invoke any methods in the Connection instance, it has to be marked as a Remote object. The other option is implementing the java.io.Serializable interface. In that case, only the copy of the instance is passed to the client. Example: DataInfo.
Since you need to invoke methods in the Connection object, it has to implement the Remote interface and extend UnicastRemoteObject. _Stub instances are created by rmic only if the class implements Remote interface.
 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Sai.
Your explanation is really helpful. Since Connection has all the methods in Data class,
its like a proxy, it will need a Data object to
do the real jobs, why Data object does not have to be a remote object? I am kind of confused here.
I have another question about lock/unlock: since
booking is a client action, does it make better sense to implement locking system on the client-side? And put lock manager in the same pkg (db) as Data class?
Thanks.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data instance is never serialized and transfered to the client when working in remote mode. That's why it doesn't have to implement Serializable or Remote interface. When you invoke a method in the Connection object, the _Stub in turn sends the instruction via RMI to the server Connection object. The server side Connection object already knows about the Data and therefore the Data instance is never transfered to the client.
You need to put the LockManager with the server package and implement the locking in the LockManager. It doesn't make sense to do the locking at the client side since you need to worry about simultaneous access only in the server.
 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Sai:
Is this why dataInfo serialized? Cuz it will be sent to client?
If LockManager sits on server-side, book method will need to sit on server-side too, right? Since local mode will also need a book method, will it be redundant? Or we need to add a middle tier to handle all booking needs and put it in db pkg, so both server and client can share.
Thanks.
 
Robin Underwood
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Book method should be on the client side. It is specific to the Fly By Night application.
 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Robin Underwood:
Book method should be on the client side. It is specific to the Fly By Night application.

Thanks Robin:
I put book method on my clien-side like you said.
I did it becuz its natural to think a client will
lock/unlock the record it wants, that it should not be done by server. I am wondering if this design will do any harm.
 
Robin Underwood
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't finished the assignment yet so I don't know what the graders think. But I think most postings I've read on this board have put the book method on the client side.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keeping book() method at the client side will not harm your score. It is the right place.
Yes. DataInfo is synchoronized because it is transfered to the client and it is enough to deal with a copy of that instance and not the reference.
[ June 16, 2002: Message edited by: Sai Prasad ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic