diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java index 4ff89d2c6..21bfd6b13 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java @@ -12,6 +12,7 @@ import java.util.concurrent.ScheduledExecutorService; import org.eclipse.hawkbit.DistributedResourceBundleMessageSource; import org.eclipse.hawkbit.ui.MgmtUiConfiguration; +import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy; import org.eclipse.hawkbit.ui.push.EventPushStrategy; import org.eclipse.hawkbit.ui.push.HawkbitEventProvider; @@ -67,17 +68,24 @@ public class UIAutoConfiguration { * * @param applicationContext * the context to add the listener - * - * @return the provider bean + * @param executorService + * the general scheduler service + * @param eventBus + * the ui event bus + * @param eventProvider + * the event provider + * @param uiProperties + * the ui properties + * @return the push strategy bean */ @Bean @ConditionalOnMissingBean @UIScope public EventPushStrategy eventPushStrategy(final ConfigurableApplicationContext applicationContext, final ScheduledExecutorService executorService, final UIEventBus eventBus, - final UIEventProvider eventProvider) { + final UIEventProvider eventProvider, final UiProperties uiProperties) { final DelayedEventBusPushStrategy delayedEventBusPushStrategy = new DelayedEventBusPushStrategy(executorService, - eventBus, eventProvider); + eventBus, eventProvider, uiProperties.getEvent().getPush().getDelay()); applicationContext.addApplicationListener(delayedEventBusPushStrategy); return delayedEventBusPushStrategy; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/UiProperties.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/UiProperties.java index 0e0bdac8a..29f57aa46 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/UiProperties.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/UiProperties.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui; import java.io.Serializable; +import java.util.concurrent.TimeUnit; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -270,12 +271,49 @@ public class UiProperties implements Serializable { } } + /** + * Configuration of the UI event bus. + */ + public static class Event implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * + * Configuration of the UI push. + * + */ + public static class Push implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * The delay for the ui event forwarding. + */ + private long delay = TimeUnit.SECONDS.toMillis(2); + + public long getDelay() { + return delay; + } + + public void setDelay(final long delay) { + this.delay = delay; + } + } + + private final Push push = new Push(); + + public Push getPush() { + return push; + } + } + private final Links links = new Links(); private final Login login = new Login(); private final Demo demo = new Demo(); + private final Event event = new Event(); + public Demo getDemo() { return demo; } @@ -288,4 +326,8 @@ public class UiProperties implements Serializable { return login; } + public Event getEvent() { + return event; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java index 2e06a0367..7c998d5f4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java @@ -50,8 +50,9 @@ import com.vaadin.ui.UI; /** * An {@link EventPushStrategy} implementation which retrieves events from * {@link com.google.common.eventbus.EventBus} and store them first in a queue - * where they will dispatched every 2 seconds to the {@link EventBus} in a - * Vaadin access thread {@link UI#access(Runnable)}. + * where they will dispatched every x (default is 2 and can be configured with + * the property) seconds to the {@link EventBus} in a Vaadin access thread + * {@link UI#access(Runnable)}. * * This strategy avoids blocking UIs when too many events are fired and * dispatched to the UI thread. The UI will freeze in the time. To avoid that @@ -71,19 +72,31 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy, Applicati BLOCK_SIZE); private final ScheduledExecutorService executorService; - - private final transient EventBus.UIEventBus eventBus; - + private final EventBus.UIEventBus eventBus; private final UIEventProvider eventProvider; private ScheduledFuture jobHandle; - + private final long delay; private UI vaadinUI; + /** + * Constructor. + * + * @param executorService + * the general scheduler service + * @param eventBus + * the ui event bus + * @param eventProvider + * the event provider + * @param delay + * the delay for the event forwarding. Every delay millisecond + * the events are forwarded by this strategy + */ public DelayedEventBusPushStrategy(final ScheduledExecutorService executorService, final UIEventBus eventBus, - final UIEventProvider eventProvider) { + final UIEventProvider eventProvider, final long delay) { this.executorService = executorService; this.eventBus = eventBus; this.eventProvider = eventProvider; + this.delay = delay; } private boolean isEventProvided(final org.eclipse.hawkbit.repository.event.TenantAwareEvent event) { @@ -99,7 +112,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy, Applicati } jobHandle = executorService.scheduleWithFixedDelay(new DispatchRunnable(vaadinUI, vaadinUI.getSession()), - 10_000, 2_000, TimeUnit.MILLISECONDS); + 10_000, delay, TimeUnit.MILLISECONDS); } @Override