I have stored all the active sessions in a database by sessionid and the unique username within the organization.
When I want to do an update or a shutdown of the webapp. I want to inform my users of that so that they can save their work.
So from the sessionid which is stored in the database I want to send a message to the user.
An another way of thinking is that I could send a general message to all users in the form of an variable on application scope, but I'm still curious how to connect directly to a user session if needed.
If you bind a map to application scope, and then, as sesssions are created, using a session listener, bind the session to that map, using the session id as the key, you can, at any time iterate over the map and get a handle to each session.
Make sure you remove the sessions from the map when they are invalidated.
session listner is a good option. i have a question here out of curiosity, how are you planning to push data to the users? do you use some applet in client side?
SCJP 1.5, SCWCD 1.4, SCBCD 5
Joined: Dec 28, 2006
I understand that you're suggesting to keep a map of active sessions which I could use for getting the desired session. This might work. I've already code for updating the database. I could change this code.
I'm not removing the id's. I update the database table where activeInd is set to 0. Records older then a month are removed automatically.
When I have a logged error and a certain time I'm able to see what kind of users where logged into the system. Al those errors and special events are also logged into the system. I use this data of customers for finding problems which could be solved. Mostly in this way I'm able to solve a problem before my customer discovers the problem which is always better. You probably already know a lot of problems could arise with multi threading.
Now I want to implement a nice updating system in which the users will get a warning. when a update will take place and I want to close all the sessions gracefully, because I had a few incidents where there was a corruption in the business logic because a session was shutdown.
I know I have to make my application better for circumventing this kind of issues, but you can always try not to have them. I now the server could shutdown, network failure, database closure, etc.
Since HTTP is stateless, you can't really push a message to a user but, since you've got a reference to their session, you could bind a message to it. Then, the next time the user makes a request you could either show them the message on the current page or redirect them to a page with the message on it.
Joined: Dec 28, 2006
I've bookmarked your site.
subject: Getting active session from the session id