• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Client runs even when server stopped

 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I just want to know how do you all handle this situaltion.
1. RMIServer started , client connects gets a stub reference of RemoteConnectionFactory, then he invokes a getConnection which returns a stub reference of RemoteData.
2. RMIServer stopped, so RemoteConnectionFactory remote object is unbinded but the remote reference to RemoteData is still exist so the client works happily in the remote mode even when the server is stopped , what to do worried please help
How do you handle this situation
Please anyone
Farouk
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest I haven't tested it, but I would expect any attempt to call the remote object would throw a RemoteException. Which you should already be handling in your code.
- Peter
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter
In my design the RemoteCOnnectionfactory on getConnections returns a instance of RemoteData object.
The requests will not throw a remote exception cause here the request go to the RemoteData instance which has nothing to do with the RemoteConnectionFactory rmi registry remote object.
The RemoteConnectionFactory object gets unbinded when you stop the server but the RemoteData object given to the client is not
binded to the registry so the instance is live and running even if the server stops. Can you tell me what to do now and wht did you do on this occassion
Pleaseeeeeeeeeeeeeeee
Farouk
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. So what happens when you call a method on the RemoteData class. Do you get any exceptions? If you do handle them by showing a nice JOptionPane with a message stating what happened.
I would think that you might not get an exception in that there is no reference to the RemoteConnectionFactory class in the RemoteData class, unless all this RMI does not work unless the Registry is running? I mean isn't the registry just a holding tank for bound objects, and not the "Server"?
I also would suspect that the RemoteData class has the instance of the Data class, and works it's magic on it's own.
So in that case then new clients would not be able to run remotely, but your already connected clients will, until they exit.
I don't think there is too much to worry about. Try testing it, and see what happens to the program, where does it blowup, what does it do to the db.db file. I think you will be fine
Mark
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mark
I think u got i am saying ,
As long the client is connected to the remoteData object everything will run fine even if the server is shut down.
So what i plan to do is
1. Have a HashMap of all clients in the RemoteConnectionFactory
and when the server is stopped i explicity make the RemoteData invalid by adding a boolean attribute to RemoteData called "valid" and settin it to false.
2. So now when server is closed all the clients connected to the server will have a attribute of "valid" set to false.
3. Now change the RemoteConnection(Wrapper for data ) object to check for validity before doing any processing or throw a exception when the connection is invalid
Please your comments
Farouk
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure. Hmm, sounds like it would work. I didn't do anything that elaborate, or really anything at all in that situation. I hope they don't mark me down for it. I submitted my assignment yesterday, and doing the essay exam on Sunday.
Try it out, if it doesn't work then remove it.
Mark
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Farouk Mohamed1:
The RemoteConnectionFactory object gets unbinded when you stop the server but the RemoteData object given to the client is not binded to the registry so the instance is live and running even if the server stops.
How so? Surely the RemoteData object lives on the server and dies with it. Sure, the client-side stub is still alive, but any attempt to call its methods will result in a RemoteException.
It should be easy to verify this - try!
Your proposed solution appears to add lots of unnecessary complexity you might be penalised for. I still don't understand why you need it. Okay, maybe you would need something of the kind if you wanted to actively notify the clients that the server goes down. But Sun's instructions appear to steer you away from active communication from server to client, for instance by indicating that the clients do not need to update their display when a seat is booked by another client.
- Peter
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter again
The RemoteData will not die even when the server is shut because it is nothing to do with the server . It is a remote object and is created by the remoteConnectionFactory which is registerd in the RMIRegistry.
So when server dies only the RemoteConnectionFactory object will die as i do a unbind but it has nothing to do with the RemoteData reference in the exising connection.
Only when new clients connect there will be aa exception thrown
but what about existing clients
So there is no way existing RemtoeData will die when the server stops
Farouk
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I'm misunderstanding you. Where does RemoteData live, if not on the server? If the answer is "the client", then what is Remote about RemoteData?
- Peter
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter
RemoteData lives on the server and it is a Remote Object and implemts DataInterface and not a registry object.
RemoteConnectionFactory lives on the server and it is a Remote Object and implemts ConnectionInterface and a registry bound object.
Please reply
Farouk
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure your client is running by looking up the connectionFactory, and using that connection to the data, rather than it possibly is using the local mode.
Because I get an exception when the Registry is stopped, even though the object that the client is using, is not in the registry but just a remote object, just like yours.
However, when the "Server is stopped, and my client tries to do anything, it gets an exception.
Mark
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Farouk Mohamed1:
RemoteData lives on the server and it is a Remote Object and implemts DataInterface and not a registry object.
Exactly. And after you brought down the server, any attempt to invoke a method on your local RemoteData stub will throw a RemoteException. No need to implement any wizardry on your part.
Whether or not it's registered with the RMI registry is immaterial.
- Peter
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys
I dint know how you made that magic happen bcos in my case the RemoteData and RemoteConnectionFactory dint have any relationship at all and when stopping the server i unbinded RemoteConnectionFactory thats all.
So i dont know how this affects RemoteData as there is nothing i do to remove it from the server.
But what i did now is used a sunchronized arraylist and add every clients who does a Naming.Lookup and when i do the unbind of RemoteConnectionFactory i go and unset the attribute "valid" in RemoteData to false. There by now the association is created and now when client tries to do something in the server(remoteData) object every method does a variant check (precondition check) in the remoteData methods to see if the connection is a vaid one. Otherswise it refuses the request and says the server is not running
What do you think now
Farouk
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is a lot of work that is uneccessary.
I think the reason why it might still run is that you say the Factory is unbound, but the RMI Registry is still running.
When you shut down the server, have the Registry close too, this way you will get the RemoteException thrown, and you can pass it to your GUI, which will display your beautiful message.
Hope that helps
Mark
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark
You are right,
I start the regisrtry using code i dont know how to stop it with code that is my problem get it?
Do you know how to stop it with code then what i am doing is unnessary?
Please reply
I think we are in line now..
Farouk
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>I start the regisrtry using code i dont know how to stop it >>with code that is my problem get it?
he he. OK, where do you have the code to start the registry?
Mine is in the actual Factory Object that gets bound into the registry. So when that class ends, becomes null, I guess it automatically closes the Registry at the same time.
There was no extra code that I added to directly close the registry.
I do have a System.exit(0), when the "Factory" gets shutdown.
I hope that helps
Mark
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark
i do the same thing before i bind the factory with the registry i start the registry usign the code
LocateRegistry.createRegistry(Integer.parseInt(portNo));
and when i close server i unbind and set the fatory to null.
I dont have syste.exit(0);
probably thats what is making the difference?
Farouk
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>I dont have syste.exit(0);
>>probably thats what is making the difference?
That could be.
>>fatory
>>syste.
Plus it looks like your missing your constanants.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic