• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What to do if client closed?

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use rmi in my assignment,and I get a data connection from DBFactory. when client done all his work, he will close the client appliation. at this moment, what should be done? inform the server to close the connection? or rmi will deal with it automaticly?
I've thought about to make a connection pool, but if that too complicated?
Is there any better solution to this problem?
Waittinf for experts' reply, really thanks!
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sean Lee:
I use rmi in my assignment,and I get a data connection from DBFactory. when client done all his work, he will close the client appliation. at this moment, what should be done?

Why, the client application should ensure that it calls close(), of course -- regardless of whether the database is local or remote.

I've thought about to make a connection pool, but if that too complicated?

It would complicate the design for performance reasons, which the instructions ask you not to do.
- Peter
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply, but i'm still not very clear about closing.
surpose DBFactory create 3 Connections for 3 clients, if client a closed, what DBFactory should do? close that connection? or rmi will do that for me?
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter,
When you say close(), do you mean System.exit(0)? im confused where close() comes from.
Thanks,
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As in DataInterface.close() -- clean up nicely when the client application exits.
I'm a bit confused now whether we are talking about the client or the server, by the way. The client would presumably have an "Exit" menu option and you can ensure that close() is called before you System.exit(0). You could add a shutdown hook for the server, but arguably cleanup is less important there. You certainly won't have to notify the clients; they'll get a nice exception next time they want to invoke the database.
- Peter
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter, I'm talking about the moment when client closing itself, what server should do.
Maybe it's because i'm not very familier with rmi. I think when DBFactory create a Connection for a client, there's a object created and run in the server. when client closing itself, I should inform the server to close the Connection object. am i right? yes, I know i should call a Connection's close method to do that. but how?
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sean Lee:
I think when DBFactory create a Connection for a client, there's a object created and run in the server. when client closing itself, I should inform the server to close the Connection object. am i right? yes, I know i should call a Connection's close method to do that. but how?

Calling close() is not the problem. It's just a Java method call and isn't obviously different from any ordinary method call (well, it may throw RemoteException, but that's it).
The only sensible thing the server-side implementation of close() might do is clean up any remaining locks held by the client.
I may understand your problem though: what happens to the Connection object itself? Like the method call, that isn't much different from what happens normally. RMI features a distributed garbage collector (DGC) which finds out that the client has released all references to your Connection, or exited altogether which boils down to the same thing. If the Connection implements Unreferenced, the unreferenced method is called. In any case, if you don't keep any further server-side references to the Connection, it will become eligible for garbage collection and ultimately be cleaned up.
In other words, beyond implementing a sensible close() method you don't have to anything.
Does that clarify things?
- Peter
[ January 04, 2003: Message edited by: Peter den Haan ]
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter, thanks.
now, i know rmi will do garbage collection for me to destory those unused Connection objects. rmi is really fantastic.
the last problem is still the close() method in Connection object.
as u know, all Connection objects are generated from DBFactory, and every one has a reference to a unique local Data object. when closing, we cannot close the Data object, but only close the Connection object itself. and as u said, GC will do that for me. so the only work i have to do is release all locks of this Connection.
but unlock method of LockManager doesn't have the function of unlocking by owner. we must give both record id and owner to run this method.
so I have to change the unlock method, am i right?
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sean Lee:
but unlock method of LockManager doesn't have the function of unlocking by owner. we must give both record id and owner to run this method.

Your call. You can either assume that clients will have cleaned up their locks before closing, and never crash, in which case you don't do anything --- or you assume that they may be buggy or crash, in which case your lock manager will have to have some kind of unlock by owner method.
Yet another design decision to make. It's almost real life
- Peter
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic