Since my previous attemp of getting logging in users through a SessionListener failed, this week i started back with two alternatives.
1. As suggested by my mentor Pascal, i tried to use a scheduler task for this. But since the task also doesn't have HTTPSession infomation this was not successful.
2. Created a new UI button to enable user login data tracking. When it is tirggerred the HTTPSession of the servlet request is passed to the Collector thread and logged in user count is retirved and stored into the databse from here onwards.
Below is how it is done.
I added a button to UI to click to enable login indicator. When user clicks this button it starts the LoggedInUsersCountCollectorThread with the session as below.
@RequestMapping(value = "/module/systemmetrics/track", method = RequestMethod.GET)
public void track(HttpServletRequest request)
{
loggedInUsersCountCollectorThread = new LoggedInUsersCountCollectorThread(request.getSession());
Thread loginThread = new Thread(loggedInUsersCountCollectorThread);
loginThread.start();
}
After that i can use the current session and get logged in users from time to time. This is similar to how the OpenMRS Core --> Administration --> Maintenance --> View logged in users section is also getting the users list.
public void track(HttpServletRequest request)
{
loggedInUsersCountCollectorThread = new LoggedInUsersCountCollectorThread(request.getSession());
Thread loginThread = new Thread(loggedInUsersCountCollectorThread);
loginThread.start();
}
After that i can use the current session and get logged in users from time to time. This is similar to how the OpenMRS Core --> Administration --> Maintenance --> View logged in users section is also getting the users list.
Below is the chart view of the stored data which is calculated every 30 seconds.
Here are the commits i made for the feature within this week.
- https://github.com/openmrs/openmrs-module-systemmetrics/commit/e9a36740f2eddf35e6d5e435c13286735aecf0be
Since there is a new JIRA project is created for our project now i created the first feature entry there.
- https://issues.openmrs.org/browse/SPU-1