I want to know How many users are connected to my application in real time. I got the idea to loop on number of session that are open but I can't find how to do that. If you have another way to do it your suggestions are welcome.
Vaadin Fusion: StatelessBy default, Fusion will not create server sessions and will use the token-based authentication mechanism, keeping the server stateless. Since server endpoints don't use a session, a server can handle more concurrent users, enabling easier horizontal scaling and high availability of services.
Vaadin Flow is a framework for building web apps 100% in Java. Flow automates everything on the frontend. The strong abstraction layer and server-driven architecture provide security and stability, allowing you to focus on creating user value.
Best solution i found so far is to count the sessions when they are created and destroyed.
public class VaadinSessionListener{
private static volatile int activeSessions = 0;
public static class VaadinSessionInitListener implements SessionInitListener{
@Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
incSessionCounter();
}
}
public static class VaadinSessionDestroyListener implements SessionDestroyListener{
@Override
public void sessionDestroy(SessionDestroyEvent event) {
/*
* check if HTTP Session is closing
*/
if(event.getSession() != null && event.getSession().getSession() != null){
decSessionCounter();
}
}
}
public static Integer getActiveSessions() {
return activeSessions;
}
private synchronized static void decSessionCounter(){
if(activeSessions > 0){
activeSessions--;
}
}
private synchronized static void incSessionCounter(){
activeSessions++;
}
}
then add the SessionListeners in the VaadinServlet init() method
@WebServlet(urlPatterns = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = true, ui = MyUI.class)
public static class Servlet extends VaadinServlet {
@Override
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
/*
* Vaadin SessionListener
*/
getService().addSessionInitListener(new VaadinSessionListener.VaadinSessionInitListener());
getService().addSessionDestroyListener(new VaadinSessionListener.VaadinSessionDestroyListener());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With