refresh grid - broadcaster message

We have a View built with Vaadin Designer, a gird inside and we need to refresh the data provider when a broadcast message is received.
The broadcast is like the one presented here:
https://vaadin.com/docs/-/part/framework/advanced/advanced-push.html

The problem is that in the method where the message is received, the UI is null and the refreshAll method of data provider has no effect.
The refresh works if dataProvider.refreshAll() is called via a button or at any click on grid header.

I tried in several ways without success. Bellow is an example.

@SpringView
@PrototypeScope
public class MyView extends MyViewDesign
        implements View, Broadcaster.BroadcastListener {
...

    @Override
    public void receiveBroadcast(String message) {
           grid.getUI().access(new Runnable() {

                @Override
                public void run() {
                    dataProvider.refreshAll();
                }
           });
    }
}

Thank you!

I managed to find a solution. I saved the UI and VaadinSession and set them in the method where the mesage is received. I tried that before, I didn’t know why it didn’t work at that moment.

public void receiveBroadcast(final String message) {
    UI.setCurrent(ui);
    VaadinSession.setCurrent(vaadinSession);

    UI.getCurrent().access(new Runnable() {
        @Override
        public void run() {
            dataProvider.refreshAll();
        }
    });
}