• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how clients may notify the server about disconnecting?

 
Roman Rytov
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connecting to the server is easy: lookup/casting.
But how to disconnect from the server? Undoubtedly when a client goes down DGC will detec it in a while (usually 10 min). but is there any way to explicitly disconnect and to let the server be notified about it immediately?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you can set the reference to the remote object to null. But if the client goes down without the code getting a chance to call that line, then you just rely on the Unreferenced interface.
Mark
 
Roman Rytov
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it doesn't help. All you get by setting RemoteObject to null is your GC becomes eligible to clean up RemoteObject's memory. But what's the connection to the RemoteServer? I don't see. THe server will clean your object's memory since lease checking notifies it that the object is dead. So we get back merely to rmi.server.dgc.leaseValue:-)
 
Gennady Shapiro
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to define what you are trying to achieve to "disconnecting". When you set your remote reference to null you effectively lose connection to the server object, this is "disconnect" in a broader sense -- who cares if the server takes a little longer to gc some objects. All Web/App servers have object time-to-live values for remote objects, and this is the standard way of handling these situations.
If you want to be really diligent (and this is beyond the scope of this project) you may create someting like an invalidate() method on your server object (similar to HTTPSession.invalidate()) to dispose of resources and nullify itself ... but why bother , thats what DGC is there for.
[ January 16, 2002: Message edited by: Gennady Shapiro ]
 
Roman Rytov
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Genady, you're 100% right. My question was not a practical but rather theoretical one. If you want to notify the server that you're disconnecting you have to call a specific method. I agree.
 
Gennady Shapiro
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roman, theoretically speaking, RMI does not provide facilities for immediate GC-eligibility. there is no invalidate() method , not even something like 'Invalidatable' interface ... which would make sense unless RMI designers thought to safeguard the server against potentially dangerous memory manipulations. The thing is that immediate nullification of your objects leads to memory fragmentaion and that forces more frequent execution of the GC. The problem with this is that all modern JVMs use "adaptive generational stop-and-copy mark-and-sweep" (cool , huh?) method of garbage collection. This means your entire server will stop and wait until memory analysis and GC are completed.
So the RMI designers probably figured not to give you any bright ideas and didnt give you easy ways to nullifying your server objects...although nothing stops you from having a method that would do this kinda thing.
[ January 18, 2002: Message edited by: Gennady Shapiro ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic