Feature configure delay time out (#391)
* Create a new property (hawkbit.server.ui.event.push.delay),that the event delay forwarding is configurable. Signed-off-by: SirWayne <dennis.melzer@bosch-si.com> * Add javadoc Signed-off-by: SirWayne <dennis.melzer@bosch-si.com> * Change delay to a long Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
committed by
Kai Zimmermann
parent
55a21d2633
commit
e6f702c882
@@ -12,6 +12,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
|
|
||||||
import org.eclipse.hawkbit.DistributedResourceBundleMessageSource;
|
import org.eclipse.hawkbit.DistributedResourceBundleMessageSource;
|
||||||
import org.eclipse.hawkbit.ui.MgmtUiConfiguration;
|
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.DelayedEventBusPushStrategy;
|
||||||
import org.eclipse.hawkbit.ui.push.EventPushStrategy;
|
import org.eclipse.hawkbit.ui.push.EventPushStrategy;
|
||||||
import org.eclipse.hawkbit.ui.push.HawkbitEventProvider;
|
import org.eclipse.hawkbit.ui.push.HawkbitEventProvider;
|
||||||
@@ -67,17 +68,24 @@ public class UIAutoConfiguration {
|
|||||||
*
|
*
|
||||||
* @param applicationContext
|
* @param applicationContext
|
||||||
* the context to add the listener
|
* the context to add the listener
|
||||||
*
|
* @param executorService
|
||||||
* @return the provider bean
|
* 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
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@UIScope
|
@UIScope
|
||||||
public EventPushStrategy eventPushStrategy(final ConfigurableApplicationContext applicationContext,
|
public EventPushStrategy eventPushStrategy(final ConfigurableApplicationContext applicationContext,
|
||||||
final ScheduledExecutorService executorService, final UIEventBus eventBus,
|
final ScheduledExecutorService executorService, final UIEventBus eventBus,
|
||||||
final UIEventProvider eventProvider) {
|
final UIEventProvider eventProvider, final UiProperties uiProperties) {
|
||||||
final DelayedEventBusPushStrategy delayedEventBusPushStrategy = new DelayedEventBusPushStrategy(executorService,
|
final DelayedEventBusPushStrategy delayedEventBusPushStrategy = new DelayedEventBusPushStrategy(executorService,
|
||||||
eventBus, eventProvider);
|
eventBus, eventProvider, uiProperties.getEvent().getPush().getDelay());
|
||||||
applicationContext.addApplicationListener(delayedEventBusPushStrategy);
|
applicationContext.addApplicationListener(delayedEventBusPushStrategy);
|
||||||
return delayedEventBusPushStrategy;
|
return delayedEventBusPushStrategy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.ui;
|
package org.eclipse.hawkbit.ui;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
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 Links links = new Links();
|
||||||
|
|
||||||
private final Login login = new Login();
|
private final Login login = new Login();
|
||||||
|
|
||||||
private final Demo demo = new Demo();
|
private final Demo demo = new Demo();
|
||||||
|
|
||||||
|
private final Event event = new Event();
|
||||||
|
|
||||||
public Demo getDemo() {
|
public Demo getDemo() {
|
||||||
return demo;
|
return demo;
|
||||||
}
|
}
|
||||||
@@ -288,4 +326,8 @@ public class UiProperties implements Serializable {
|
|||||||
return login;
|
return login;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Event getEvent() {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,9 @@ import com.vaadin.ui.UI;
|
|||||||
/**
|
/**
|
||||||
* An {@link EventPushStrategy} implementation which retrieves events from
|
* An {@link EventPushStrategy} implementation which retrieves events from
|
||||||
* {@link com.google.common.eventbus.EventBus} and store them first in a queue
|
* {@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
|
* where they will dispatched every x (default is 2 and can be configured with
|
||||||
* Vaadin access thread {@link UI#access(Runnable)}.
|
* 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
|
* 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
|
* 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);
|
BLOCK_SIZE);
|
||||||
|
|
||||||
private final ScheduledExecutorService executorService;
|
private final ScheduledExecutorService executorService;
|
||||||
|
private final EventBus.UIEventBus eventBus;
|
||||||
private final transient EventBus.UIEventBus eventBus;
|
|
||||||
|
|
||||||
private final UIEventProvider eventProvider;
|
private final UIEventProvider eventProvider;
|
||||||
private ScheduledFuture<?> jobHandle;
|
private ScheduledFuture<?> jobHandle;
|
||||||
|
private final long delay;
|
||||||
private UI vaadinUI;
|
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,
|
public DelayedEventBusPushStrategy(final ScheduledExecutorService executorService, final UIEventBus eventBus,
|
||||||
final UIEventProvider eventProvider) {
|
final UIEventProvider eventProvider, final long delay) {
|
||||||
this.executorService = executorService;
|
this.executorService = executorService;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.eventProvider = eventProvider;
|
this.eventProvider = eventProvider;
|
||||||
|
this.delay = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEventProvided(final org.eclipse.hawkbit.repository.event.TenantAwareEvent event) {
|
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()),
|
jobHandle = executorService.scheduleWithFixedDelay(new DispatchRunnable(vaadinUI, vaadinUI.getSession()),
|
||||||
10_000, 2_000, TimeUnit.MILLISECONDS);
|
10_000, delay, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user