?
Solved

Contact across sessions

Posted on 2003-10-31
6
Medium Priority
?
201 Views
Last Modified: 2010-04-01
Hi!

I am designing (and soon implementing) a web-application (mysql-tomcat-jsp-struts).

The application deals with shift-planning, and there is two kinds of users: "regular" and "boss". The users are working in teams, and a typical team counts approx. 10 regular users and one boss.

The boss-users can alter some settings (restrictions and other rules) that apply for all the regular users on his team.

The way the application is designed right now, an object "SystemVariables" is loaded from MySQL with the relevant settings for the team (as mentioned, these settings are made by boss-users), and is stored in Session when the user logs in. This way it is not neccesary to consult the DB each time you need a setting in fx an ActionClass.

My problem is, that I am not sure if this is good approach! If a boss-user changes some settings, all the users that are logged in at that time will NOT be affected before they log in next time.

1) Is there a way that one session (the boss-session) can "contact" the other active sessions, and tell them to reload their settings?

2) Alternatively I COULD of course reload system-settings in the beginning of each Action-class, but this seems a bit clumsy. What do you think about that?

Kind regards,

Nic
0
Comment
Question by:JNic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 9660442
>> My problem is, that I am not sure if this is good approach!
NO, and your question followed right after this actually tells youself it is not.

The right approach depends on your other requirements.

1. as you already know, read database in every request. and you know pros and cons.

2. if you know that your application will never be clustered. use context bag instead of session bag. You only store group name in session, which will never change, and store a map in servlet context (or in another word, application scope). the map will be indexed by group name and value your SystemVariables object.

3. if you need cluster, you'll have to implement your SystemVariables as EJB, it should be an Entity Bean and the primary key will be group name. In every action class, you consult EJB instead of database.

there are other possible approaches like use JMS and session, that will be over complicated and error prone.

Let us know.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9660506
OK, I take 50% of my "NO" answer.
if you don't use cluster, option 2 is always the best approach. but if you do use cluster, there is another option besides 1 and 3 if your user can accept that the boss change will be delayed to take effect on currently logged in users. the idea is:

Store a long var 'updatetime' in session with SystemVariables. when you load SystemVariables from database, you set updatetime=System.currentTimeMillis();
in every action, you compare the updatetime with currentTimeMillis(), if it is more then, say 60 seconds, you'll read the SystemVariables from database again. this can greatly limit database access and also gets setting updated for logged in users.
0
 
LVL 1

Author Comment

by:JNic
ID: 9660780
Kenneth, it is SO nice to have you back! (You have been away a bit, havent you?)

Your answer is really helping a LOT, and it seems to me, that solution 2 is right for me. I dont know why I forgot everything about application scope... (blush)

But could you elaborate a little bit on the subject of "clustered applications"? Are you talking about applications that are running on multiple servers? Or/and  multiple DB's?

Kindest regards,

Nic
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
kennethxu earned 500 total points
ID: 9664782
Thanks for your greeting! Yeah, a lot of things happened, change job, move house, get kid into school. You know that's a lot and sorry for being away for such a long while :-)

I meant "clustered applications" as j2ee web application deployed to a clustered j2ee application server. by specification, application scope objects are not replicated to clustered servers so it is only available to local server. For example,

J2ee Server A and B are clustered. webapp deployed to the cluster, so there will be 2 copies of you webapp running.
copyA in serverA and copyB in serverB
a user login and is routed to serverA
a boss login and is routed to serverB
boess change setting in serverB
user in serverA don't see the changes

let me know if you have futher enquires,
Ken
0
 
LVL 1

Author Comment

by:JNic
ID: 9665546
OK, - thas was what I thought it meant. :-)

For me, I am very sure that this scenario will never happen. The teams will always be stored on the same server.

Anyway- if this scenario would actually happen, I will be a millionaire and able to solve it! :) :) :)

Thanks a lot for your help!

Kindest regards,

Nicolai Krog (had to change username because I have a new e-mail.)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9665868
As always, my pleasure!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question