Disable to set the current page first item id
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.app;
|
package org.eclipse.hawkbit.app;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.ui.HawkbitEventProvider;
|
||||||
import org.eclipse.hawkbit.ui.HawkbitUI;
|
import org.eclipse.hawkbit.ui.HawkbitUI;
|
||||||
import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy;
|
import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -34,6 +35,6 @@ public class MyUI extends HawkbitUI {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public MyUI(final EventBus systemEventBus, final org.vaadin.spring.events.EventBus.SessionEventBus eventBus) {
|
public MyUI(final EventBus systemEventBus, final org.vaadin.spring.events.EventBus.SessionEventBus eventBus) {
|
||||||
super(new DelayedEventBusPushStrategy(eventBus, systemEventBus));
|
super(new DelayedEventBusPushStrategy(eventBus, systemEventBus, new HawkbitEventProvider()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.ui;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface EventProvider {
|
||||||
|
|
||||||
|
Set<Class<?>> getSingleEvents();
|
||||||
|
|
||||||
|
Set<Class<?>> getBulkEvents();
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.ui;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dennis Melzer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class HawkbitEventProvider implements EventProvider {
|
||||||
|
|
||||||
|
private static final Set<Class<?>> SINGLE_EVENTS = Sets.newHashSet(TargetTagCreatedBulkEvent.class,
|
||||||
|
DistributionSetTagCreatedBulkEvent.class, DistributionSetTagDeletedEvent.class,
|
||||||
|
DistributionSetTagUpdateEvent.class, RolloutGroupChangeEvent.class, RolloutChangeEvent.class);
|
||||||
|
|
||||||
|
private static final Set<Class<?>> BULD_EVENTS = Sets.newHashSet(TargetCreatedEvent.class,
|
||||||
|
TargetInfoUpdateEvent.class, TargetDeletedEvent.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Class<?>> getSingleEvents() {
|
||||||
|
return SINGLE_EVENTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Class<?>> getBulkEvents() {
|
||||||
|
return BULD_EVENTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,7 +15,6 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -141,8 +140,6 @@ public class TargetTable extends AbstractTable implements Handler {
|
|||||||
private Boolean isTargetPinned = Boolean.FALSE;
|
private Boolean isTargetPinned = Boolean.FALSE;
|
||||||
private ShortcutAction actionSelectAll;
|
private ShortcutAction actionSelectAll;
|
||||||
private ShortcutAction actionUnSelectAll;
|
private ShortcutAction actionUnSelectAll;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@@ -349,7 +346,8 @@ public class TargetTable extends AbstractTable implements Handler {
|
|||||||
@Override
|
@Override
|
||||||
protected Object getItemIdToSelect() {
|
protected Object getItemIdToSelect() {
|
||||||
if (managementUIState.getSelectedTargetIdName().isPresent()) {
|
if (managementUIState.getSelectedTargetIdName().isPresent()) {
|
||||||
setCurrentPageFirstItemId(managementUIState.getLastSelectedTargetIdName());
|
LOG.info("****** getItemIdToSelect *********");
|
||||||
|
// setCurrentPageFirstItemId(managementUIState.getLastSelectedTargetIdName());
|
||||||
return managementUIState.getSelectedTargetIdName().get();
|
return managementUIState.getSelectedTargetIdName().get();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.ui.push;
|
package org.eclipse.hawkbit.ui.push;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -19,15 +20,10 @@ import java.util.concurrent.ScheduledFuture;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent;
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.EntityEvent;
|
import org.eclipse.hawkbit.eventbus.event.EntityEvent;
|
||||||
import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent;
|
import org.eclipse.hawkbit.eventbus.event.Event;
|
||||||
import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent;
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent;
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent;
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent;
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent;
|
|
||||||
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
||||||
|
import org.eclipse.hawkbit.ui.EventProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.core.context.SecurityContext;
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
@@ -36,7 +32,6 @@ import org.springframework.security.web.context.HttpSessionSecurityContextReposi
|
|||||||
import org.vaadin.spring.events.EventBus;
|
import org.vaadin.spring.events.EventBus;
|
||||||
import org.vaadin.spring.events.EventBus.SessionEventBus;
|
import org.vaadin.spring.events.EventBus.SessionEventBus;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.common.eventbus.AllowConcurrentEvents;
|
import com.google.common.eventbus.AllowConcurrentEvents;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.vaadin.server.VaadinSession;
|
import com.vaadin.server.VaadinSession;
|
||||||
@@ -71,12 +66,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
|
|
||||||
private ScheduledFuture<?> jobHandle;
|
private ScheduledFuture<?> jobHandle;
|
||||||
|
|
||||||
/**
|
private final EventProvider eventProvider;
|
||||||
* only events defined in the set are dispatched to the session event bus.
|
|
||||||
*/
|
|
||||||
private static final Set<Class<?>> UI_EVENTS = Sets.newHashSet(TargetInfoUpdateEvent.class,
|
|
||||||
TargetCreatedEvent.class, TargetDeletedEvent.class, RolloutChangeEvent.class, RolloutGroupChangeEvent.class,
|
|
||||||
TargetTagCreatedBulkEvent.class, DistributionSetTagCreatedBulkEvent.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -88,9 +78,10 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
* back-end
|
* back-end
|
||||||
*/
|
*/
|
||||||
public DelayedEventBusPushStrategy(final SessionEventBus eventBus,
|
public DelayedEventBusPushStrategy(final SessionEventBus eventBus,
|
||||||
final com.google.common.eventbus.EventBus systemEventBus) {
|
final com.google.common.eventbus.EventBus systemEventBus, final EventProvider eventProvider) {
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.systemEventBus = systemEventBus;
|
this.systemEventBus = systemEventBus;
|
||||||
|
this.eventProvider = eventProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,12 +96,22 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
@AllowConcurrentEvents
|
@AllowConcurrentEvents
|
||||||
public void dispatch(final org.eclipse.hawkbit.eventbus.event.Event event) {
|
public void dispatch(final org.eclipse.hawkbit.eventbus.event.Event event) {
|
||||||
// to dispatch too many events which are not interested on the UI
|
// to dispatch too many events which are not interested on the UI
|
||||||
if (UI_EVENTS.contains(event.getClass()) && !queue.offer(event)) {
|
if (!isEventProvided(event)) {
|
||||||
|
LOG.trace("Event is not supported in the UI!!! Dropped event is {}", event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!queue.offer(event)) {
|
||||||
LOG.warn("Deque limit is reached, cannot add more events!!! Dropped event is {}", event);
|
LOG.warn("Deque limit is reached, cannot add more events!!! Dropped event is {}", event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isEventProvided(final org.eclipse.hawkbit.eventbus.event.Event event) {
|
||||||
|
return eventProvider.getSingleEvents().contains(event.getClass())
|
||||||
|
|| eventProvider.getBulkEvents().contains(event.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(final UI vaadinUI) {
|
public void init(final UI vaadinUI) {
|
||||||
LOG.debug("Initialize delayed event push strategy");
|
LOG.debug("Initialize delayed event push strategy");
|
||||||
@@ -152,6 +153,9 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int addAccess = 0;
|
||||||
|
private static int startAccess = 0;
|
||||||
|
|
||||||
private final class DispatchRunnable implements Runnable {
|
private final class DispatchRunnable implements Runnable {
|
||||||
|
|
||||||
private final UI vaadinUI;
|
private final UI vaadinUI;
|
||||||
@@ -206,38 +210,66 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||||
try {
|
try {
|
||||||
SecurityContextHolder.setContext(userContext);
|
SecurityContextHolder.setContext(userContext);
|
||||||
|
|
||||||
|
// TODO viele kleine access?
|
||||||
|
addAccess++;
|
||||||
|
final int endAddAccess = addAccess;
|
||||||
|
LOG.info("Add Access to runnable{}", addAccess);
|
||||||
vaadinUI.access(() -> {
|
vaadinUI.access(() -> {
|
||||||
|
startAccess++;
|
||||||
|
final int currentAccess = startAccess;
|
||||||
|
LOG.info("Started Access {}", currentAccess);
|
||||||
|
final Instant startAcess = Instant.now();
|
||||||
|
|
||||||
if (vaadinSession.getState() != State.OPEN) {
|
if (vaadinSession.getState() != State.OPEN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fowardEvents(events, userContext);
|
fowardSingleEvents(events, userContext);
|
||||||
|
fowardBulkEvents(events, userContext);
|
||||||
// send a list of events, because ui performance issues
|
berechneDauer(startAcess, "End Access " + currentAccess);
|
||||||
publishEventAsList(events, userContext, TargetInfoUpdateEvent.class);
|
|
||||||
publishEventAsList(events, userContext, TargetCreatedEvent.class);
|
|
||||||
publishEventAsList(events, userContext, TargetDeletedEvent.class);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
LOG.info("End add Access to runnable{}", endAddAccess);
|
||||||
} finally {
|
} finally {
|
||||||
SecurityContextHolder.setContext(oldContext);
|
SecurityContextHolder.setContext(oldContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void publishEventAsList(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
private void berechneDauer(final Instant start, final String methode) {
|
||||||
final SecurityContext userContext, final Class<?> eventType) {
|
final Instant end = Instant.now();
|
||||||
final List<org.eclipse.hawkbit.eventbus.event.Event> bulkEvents = events.stream()
|
final long second = end.getEpochSecond() - start.getEpochSecond();
|
||||||
.filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event)
|
LOG.info("Dauer {} {} sekunden.", methode, second);
|
||||||
&& eventType.isInstance(event))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (bulkEvents.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
eventBus.publish(vaadinUI, bulkEvents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fowardEvents(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
private void fowardBulkEvents(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
||||||
final SecurityContext userContext) {
|
final SecurityContext userContext) {
|
||||||
events.stream().filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event))
|
final Set<Class<?>> filterBulkEvenTypes = events.stream().map(Event::getClass)
|
||||||
.forEach(event -> eventBus.publish(vaadinUI, event));
|
.filter(eventClass -> eventProvider.getBulkEvents().contains(eventClass))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
publishBulkEvent(events, userContext, filterBulkEvenTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void publishBulkEvent(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
||||||
|
final SecurityContext userContext, final Set<Class<?>> filterBulkEvenTypes) {
|
||||||
|
for (final Class<?> bulkType : filterBulkEvenTypes) {
|
||||||
|
final List<org.eclipse.hawkbit.eventbus.event.Event> listBulkEvents = events.stream()
|
||||||
|
.filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event)
|
||||||
|
&& bulkType.isInstance(event))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!listBulkEvents.isEmpty()) {
|
||||||
|
LOG.info("Publish bulk event");
|
||||||
|
eventBus.publish(vaadinUI, listBulkEvents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fowardSingleEvents(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
||||||
|
final SecurityContext userContext) {
|
||||||
|
events.stream().filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event)
|
||||||
|
&& eventProvider.getSingleEvents().contains(event.getClass())).forEach(event -> {
|
||||||
|
LOG.info("Publish single event");
|
||||||
|
eventBus.publish(vaadinUI, event);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user