xdoo / vaadin-demo

demo using vaadin with spring boot.
4 stars 2 forks source link

Singletons für Navigator und EventBus #180

Closed peter-mueller closed 8 years ago

peter-mueller commented 9 years ago

Testen ob das von überall aus geht:

UI.getCurrent().getNavigator()

Und dann eine ähnliche Lösung für den EventBus bauen.

@xdoo Bitte bestätigen dass es pro GUI nur einen Navigator und einen EventBus gibt.

darenegade commented 9 years ago

In der MainUI wird der Navigator erstellt und gesetzt. Dieser sollte dann fix bleiben, da die UI für jede Vaadin Instanz auch fix bleibt. MainUI.class:

        this.navigator = new Navigator(this, componentContainer);
        this.navigator.addProvider(viewProvider);
        setNavigator(this.navigator);

https://vaadin.com/book/-/page/application.lifecycle.html

darenegade commented 9 years ago

Beim Eventbus schaut das etwas schlechter aus, da man diesen in die UI und die damit verbundene VaadinSession packen müsste. Und zwar so, dass man es auch à la Navigator von überall bekommt. Ich sehe da derzeit keine Möglichkeit, dies auf eine schöne/praktikable Weise umzusetzen.

Dies wäre z.B. eine sehr hässliche Möglichkeit, die aus den Libs nicht möglich ist:

EventBus bus = ( (MainUI) UI.getCurrent() ).getEventBus();
peter-mueller commented 9 years ago

So OK? Mit Navigation das funktioniert so.

/**
 * Provides a simple EventBus.
 *
 * @author rene.zarwel
 */
public class EventBus extends reactor.bus.EventBus implements Serializable {

    private static EventBus eventBus = null;

    public static EventBus make() {
        if (eventBus == null)
            return eventBus = new EventBus();
        return eventBus;
    }

    private EventBus() {
        super(SynchronousDispatcher.INSTANCE);
    }
}
darenegade commented 9 years ago

Dann haben wir einen eventbus für alle Sessions aller User und das wäre vielleicht keine gute Idee.

Von meinem iPhone gesendet

Am 16.10.2015 um 07:46 schrieb Peter Müller notifications@github.com:

So OK? Mit Navigation das funktioniert so.

/**

  • Provides a simple EventBus. *
  • @author rene.zarwel */ public class EventBus extends reactor.bus.EventBus implements Serializable {

    private static EventBus eventBus = null;

    public static EventBus make() { if (eventBus == null) return eventBus = new EventBus(); return eventBus; }

    private EventBus() { super(SynchronousDispatcher.INSTANCE); } } — Reply to this email directly or view it on GitHub.

peter-mueller commented 9 years ago

Nein, ist getestet und funktioniert scheinbar. Geht so nicht

peter-mueller commented 9 years ago

So ?:

If you also want to access the variables of your own subclass of UI in a static way you can use the following pattern to create a getCurrent() method that is narrowed to your UI class:

public class MyApplicationUI extends UI {

   // ...

    public static MyApplicationUI getCurrent() {
        return (MyApplicationUI) UI.getCurrent();
    }
}

You can then statically access your own UI subclass as follows:

MyApplicationUI.getCurrent().getMyUIScopedVariable();

By that, managing ThreadLocal variables isn’t necessary any longer. Statically accessing session-scoped variables through the VaadinSession can be achieved in a similar way.

darenegade commented 9 years ago

Das ist besser :smile:

Von meinem iPhone gesendet

Am 16.10.2015 um 08:15 schrieb Peter Müller notifications@github.com:

So ?:

If you also want to access the variables of your own subclass of UI in a static way you can use the following pattern to create a getCurrent() method that is narrowed to your UI class:

public class MyApplicationUI extends UI {

// ...

public static MyApplicationUI getCurrent() {
    return (MyApplicationUI) UI.getCurrent();
}

} You can then statically access your own UI subclass as follows:

MyApplicationUI.getCurrent().getMyUIScopedVariable(); By that, managing ThreadLocal variables isn’t necessary any longer. Statically accessing session-scoped variables through the VaadinSession can be achieved in a similar way.

— Reply to this email directly or view it on GitHub.

darenegade commented 9 years ago

Ist übrigens meine Lösung von oben

Von meinem iPhone gesendet

Am 16.10.2015 um 08:15 schrieb Peter Müller notifications@github.com:

So ?:

If you also want to access the variables of your own subclass of UI in a static way you can use the following pattern to create a getCurrent() method that is narrowed to your UI class:

public class MyApplicationUI extends UI {

// ...

public static MyApplicationUI getCurrent() {
    return (MyApplicationUI) UI.getCurrent();
}

} You can then statically access your own UI subclass as follows:

MyApplicationUI.getCurrent().getMyUIScopedVariable(); By that, managing ThreadLocal variables isn’t necessary any longer. Statically accessing session-scoped variables through the VaadinSession can be achieved in a similar way.

— Reply to this email directly or view it on GitHub.