1

I want someone to tell me where to search for how to make a session between the client(s) and the server in RMI, i.e what is the name of that concept for searching purposes?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165

1 Answers1

2

I named this the Remote Session pattern in my 2001 book.

The idea is to have a singleton RMI object, bound in the Registry, with nothing but a login() method. That method, if successful, returns a new RemoteSession object for every call, that contains the API you need for the session. RemoteSession is another remote interface of course. It also contains a logout() method, which unexports the object, and it also implements Unreferenced, as another way of terminating the session.

Each instance of RemoteSession can maintain client state, so it is a session object, and as the only way to get a RemoteSession object is via login(), it is secure to a first approximation.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • what's the name of this book ? – Eslam Hamdy Jan 11 '13 at 06:22
  • ok, now we have the remote server object that implements referenced, when will this object GC'd ? i want this object to be sent to the GC when this user logout so the session with that user will be terminated, what will be the case if we have more that one user in the same session (two users chatting with each other) how could we track the session ? – Eslam Hamdy Jan 11 '13 at 07:17
  • 1. java.rmi: The Guide to Remote Method Invocation in Java. 2. It is GCd when the client it was allocated to releases the stub, exits the JVM, etc. You can't have more than one user in the same session the way I described it, in response to the way you originally described your problem which you are now changing, but it does generalise to that: the logout() method need to track when its number of clients goes to zero and then unexports itself. The unreferenced() method works the same. – user207421 Jan 11 '13 at 07:46
  • but why the login object that will return a session to the client will be a singleton? – Eslam Hamdy Jan 11 '13 at 12:31
  • @Eslam because it's bound in the Registry. The client has to start somewhere. – user207421 Jan 11 '13 at 22:44
  • ok, but it will also work if it wasn't singleton, if it's a singleton,consider that situation, if client A logs into the system so the login object will be instantiated, now client B wants also to login, now how could the login object be instantiated(as it was instantiated in the past via client A)? – Eslam Hamdy Jan 13 '13 at 15:11
  • @Eslam The login object is a singleton. It is bound in the Registry. That's how both clients can find it. When they login, they each get their own session object. I don't see any point in it not being a singleton. You still have to have a singleton object somewhere, bound into the Registry, for the clients to start with, and it might as well be the login object. I don't understand why you are telling me it can work without it being a singleton and then asking me how it can work without being a singleton. – user207421 Jan 29 '13 at 12:23