Solved

Contact across sessions

Posted on 2003-10-31
6
194 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Accepted Solution

by:
kennethxu earned 125 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now