Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deregister UI remote event push strategy from application context #1022

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear context from SpringContextHelper

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