Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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
0
JNic
Asked:
JNic
  • 4
  • 2
1 Solution
 
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.
0
 
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.
0
 
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
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!

 
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
0
 
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.)
0
 
kennethxuCommented:
As always, my pleasure!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now