question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider adding interfaces to listen to session and UI initializations, and to session destructions

See original GitHub issue

Describe your motivation

Many use cases require applying some logic to all sessions or to all UIs. For example, to implement a custom error handler, one needs to listen to session initialization events and add the custom handler to each session. Similarly, certain use cases require listening to all UI initializations (for example, to check user’s credentials) and all session destructions (for example, to free up some resources).

Currently, one can listen to those three events via VaadinService’s addUIInitListener, addSessionInitListener, and addSessionDestroyListener methods. However, it might not be obvious to developers that VaadinService is the way to access these three events. Moreover, listening to these three events currently requires some boilerplate to listen to init events of the VaadinService itself.

Describe the solution you’d like

Consider providing convenient interfaces to enable listening to UI initializations and session initializations and destructions. Such interfaes would enable one to do something like the following:

public class MySessionListener implements VaadinSessionInitListener {
    
    @Override
    public void sessionInit(SessionInitEvent event) {
        event.getSession().setErrorHandler(new MyErrorHandler());
    }
}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Legiothcommented, Jun 29, 2022

We are optimizing our designs for the Spring case, where adding @Component is already simple enough and the least surprising (and most versatile) way for seasoned Spring users.

For CDI users, there’s (iirc) already the option of using @Observes to get those events, so they also wouldn’t need anything simpler.

That mostly leaves the fully manual crowd that doesn’t use any DI framework, which is probably because they prefer to do things manually even if that requires slightly more explicit code. Also for them, a fully automatic approach would probably not be appreciated.

1reaction
knoobiecommented, Jun 29, 2022

Doing something automatically is, to my mind, simpler than manually doing so.

From the end-user perspective totally valid! I was more worried about the flow team 😉 Because I think this could break “easily” with different servlet container, OSGI, Portlets and all the other crazy implementation details the guys have to manage. So using either @Component support for spring or the standard way of Java to hook things up (META-INF) sounds better to maintain in the long run.

I would call this a breaking change, not a regression.

You got me with that, fair point!

But how about if we provide people with the option to disable auto-registering if they need to?

Possible, but probably not something I can answer rightfully 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Online Subsystem Session Interface in Unreal Engine
One of the main duties of the session interface is session management, including session setup, updating, and destruction.
Read more >
Spring Framework For Beginners — Part 2 - Medium
We know that spring is instantiating them,configuring them depending on what values we are providing, but when and how this is happening?
Read more >
Chapter 2. Servlet event propagation
ServletContextListener interface. The event object fired is a javax.servlet.ServletContext (since that's the only relevant information in the javax.servlet.
Read more >
AWS IAM Identity Center now supports session management ...
AWS IAM Identity Center now supports session management capabilities for AWS Command Line Interface (AWS CLI) and SDKs.
Read more >
Hooking Into the Spring Bean Lifecycle - Reflectoring
Spring provides different callbacks and interfaces to hook into the lifecycle of Spring-managed beans. This article describes the lifecycle ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found