vaadin 7 - transaction listener

Hi,

i am looking for a way to track the begin and end of a transaction to set a reference to a ThreadLocal variable.
Vaadin 6 offered the transaction listener. It allowed me to do initialization when a transaction was started and clean up if it was ended.

ThreadLocalHelper:
trxStarts(){
MyService.setCurrent(instance)
}

txnEnds() {
MyService.setCurrent(null)
}

But i can not find a way to do so in vaadin 7? Is there a replacement for it?

Thanks Florian

@vaadin-core-team: Any ideas?

Thanks Florian

What exactly do you want to do with it? The normal use case was that you wanted to store the application reference into a place that you can access it statically, like MyApplication.get();. If this is what you are looking for, there is now UI.getCurrent(); built in into Vaadin without the need of transaction listeners.

I would like to store one of my own objects to a ThreadLocal variable.
Then i can access it everywhere from the code as long as i am in an active request.

With vaadin 6 that was simple.


TransactionListener {
   trancationStart() {
       Context.foo = someValue
   }  

   transactionEnd() {
      Context.foo = null
   }

A downcast of UI is not an option in my case.

Thanks, Florian

Hi Florian,

Take a look at VaadinSession.getCurrent().set/getAttribute(). That is one way you can store it.

How about if we want to set logging MDC values unique to each request thread? Certainly we can’t use the session object in that case: Log4J’s MDC knows nothing about Vaadin.

In general, there may be thread locals that are not under our control, so we can’t resort to a Session. I suppose we could hijack Vaadin’s servlet, but then this feels more and more like a regression.

Another use case is one in which we enable maintenance mode in an application and we want our users to immediately get a different screen. We used to decide this on transactionStart. How can we decide it in Vaadin 7?

Has this been awnsered? Im having the exact same issue (MDC logging) and cant figure out the proper place to implemt it.

Also - Ive tried

VaadinSession.getCurrent().addRequestHandler(...)

But the request handler is only called for non UI requests, which isnt enough to correctly setup the logging MDC for all threads.