Contact across sessions

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
LVL 1
JNicAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kennethxuCommented:
>> 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.
kennethxuCommented:
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.
JNicAuthor Commented:
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
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

kennethxuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JNicAuthor Commented:
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.)
kennethxuCommented:
As always, my pleasure!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.