Skip to content

Commit

Permalink
Deregister UI remote event push strategy from application context (#1022
Browse files Browse the repository at this point in the history
)

* deregister UI remote event push strategy from application context
* remove application context from holder after detaching the UI

Signed-off-by: Bogdan Bondar <[email protected]>
  • Loading branch information
bogdan-bondar authored Oct 12, 2020
1 parent e6b5f48 commit a092747
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.AbstractApplicationContext;
import org.vaadin.spring.events.EventBus.UIEventBus;

import com.vaadin.annotations.Theme;
Expand Down Expand Up @@ -100,6 +102,21 @@ public void detach(final DetachEvent event) {

if (pushStrategy != null) {
pushStrategy.clean();
clearContextListener();
}

SpringContextHelper.clearContext();
}

private void clearContextListener() {
if (pushStrategy instanceof ApplicationListener && context instanceof AbstractApplicationContext) {
final ApplicationListener<?> listener = (ApplicationListener<?>) pushStrategy;
((AbstractApplicationContext) context).getApplicationListeners().remove(listener);

// we do not need to explicitly remove the listener from
// ApplicationEventMulticaster because it is done by
// UIBeanStore#destroy delegating to
// ApplicationListenerDetector#postProcessBeforeDestruction
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public void clean() {
LOG.debug("Cleanup delayed event push strategy for UI {}", vaadinUI.getUIId());
jobHandle.cancel(true);
queue.clear();

jobHandle = null;
vaadinUI = null;
}

private final class DispatchRunnable implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

/**
* Singleton for the spring application context.
*
*
*
*/
public final class SpringContextHelper {

Expand All @@ -27,6 +24,12 @@ private SpringContextHelper() {
// Utility class
}

/**
* method to set application context.
*
* @param context
* ApplicationContext
*/
public static void setContext(final ApplicationContext context) {
SpringContextHelper.context = context;
}
Expand Down Expand Up @@ -70,4 +73,11 @@ public static <T> T getBean(final String beanName, final Class<T> beanClazz) {
return context.getBean(beanName, beanClazz);
}

/**
* method to clear application context.
*
*/
public static void clearContext() {
context = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vaadin.servlet.productionMode=true
vaadin.servlet.urlMapping=/UI/*
vaadin.servlet.heartbeatInterval=60
vaadin.servlet.closeIdleSessions=false
server.servlet.session.timeout=300

hawkbit.server.ui.links.documentation.root=https://www.eclipse.org/hawkbit/
hawkbit.server.ui.links.documentation.security=https://www.eclipse.org/hawkbit/concepts/authorization/
Expand Down

0 comments on commit a092747

Please sign in to comment.