Search code examples
javasessiondesign-patternscallbackrmi

How to do a session pattern with callbacks?


I know how to do a session pattern without callbacks like here How to organize RMI Client-Server architecture. But i don't know how to do one with callbacks. Do I need another session object for the client to pass to the server when logging in? If yes where do i keep it in the server side: hold a reference of the client session in the server session, or a collection of all client sessions somewhere else like the login server? If no what is the object that implements the client callback methods?

Maybe someone can give a code example like in the question i linked, because that one was clear and I didn't find one for the callbacks.

The answer doesn't have to be strictly RMI but I saw a lot of questions on this with no answers so i added the tag.


Solution

  • You need a remote object for the client to pass to the server, on which the callbacks are called. It's rather likely to be a session object given that you're supplying it on login, but there isn't really enough information here to be sure. It depends on what you want it to be.

    If you want it to be a session object, i.e. one that is unique to the session and does not survive it, you should ensure:

    1. That the client unexports it when logging out, and
    2. That the server loses its reference to this object when logout occurs, which is easily done by storing it in the server-allocated session object.