Skip to content

Commit

Permalink
Dispose activity management during shutdown completely and early ecli…
Browse files Browse the repository at this point in the history
…pse-platform#1084

The WorkbenchActivitySupport is currently disabled quite late during
workbench shutdown. In particular, it is performed after the service
locator disposal, which produces several events for the disablement of
expression-controlled activities that are processed by the activity
management. Since the activity management is shut down afterwards
anyway, the processing of these events is unnecessary.

This change ensures that activities enablement changes are not
unnecessarily processed during workbench shutdown. It consists of two
parts:
1. It performs the disposal of activity management and its persistence
handler early in the workbench shutdown process (in particular before
the service locator disposal).
2. It adds proper dispose functionality for the IActivityManager, such
that disposing the workbench activity support disposes the activity
manager, which then removes all its listeners to not react to further
events.

Contributes to
eclipse-platform#1084.
  • Loading branch information
HeikoKlare committed Sep 19, 2023
1 parent 21eecdc commit a776756
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,13 @@ public interface IActivityManager {
* performed.
*/
void removeActivityManagerListener(IActivityManagerListener activityManagerListener);

/**
* Disposes this activity manager. Removes all listeners. The behavior of all
* other methods after disposing is undefined.
*
* @since 3.131
*/
void dispose();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3019,30 +3019,35 @@ private void shutdown() {
workbenchListeners.clear();

cancelEarlyStartup();
if (workbenchService != null)
if (workbenchService != null) {
workbenchService.unregister();
}
workbenchService = null;

if (e4WorkbenchService != null)
if (e4WorkbenchService != null) {
e4WorkbenchService.unregister();
}
e4WorkbenchService = null;

// for dynamic UI
registry.removeRegistryChangeListener(extensionEventHandler);
registry.removeRegistryChangeListener(startupRegistryListener);

// shut down activity helper before disposing workbench activity support;
// dispose activity support before disposing service locator to avoid
// unnecessary activity disablement processing
activityHelper.shutdown();
workbenchActivitySupport.dispose();
WorkbenchHelpSystem.disposeIfNecessary();

// Bring down all of the services.
serviceLocator.dispose();
application.getCommands().removeAll(commandsToRemove);
application.getCategories().removeAll(categoriesToRemove);
getDisplay().removeFilter(SWT.MouseDown, backForwardListener);
backForwardListener = null;

workbenchActivitySupport.dispose();
WorkbenchHelpSystem.disposeIfNecessary();

// shutdown the rest of the workbench
activityHelper.shutdown();
uninitializeImages();
if (WorkbenchPlugin.getDefault() != null) {
WorkbenchPlugin.getDefault().reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public abstract class AbstractActivityManager implements IActivityManager {
private ListenerList<IActivityManagerListener> activityManagerListeners;

private boolean disposed;

protected AbstractActivityManager() {
}

Expand Down Expand Up @@ -60,4 +62,15 @@ public void removeActivityManagerListener(IActivityManagerListener activityManag
activityManagerListeners.remove(activityManagerListener);
}
}

@Override
public void dispose() {
activityManagerListeners.clear();
disposed = true;
}

protected boolean isDisposed() {
return disposed;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ public MutableActivityManager(ITriggerPointAdvisor triggerPointAdvisor, IActivit
readRegistry(true);
}

@Override
public void dispose() {
super.dispose();
clearExpressions();
activityRegistry.removeActivityRegistryListener(activityRegistryListener);
activitiesById.clear();
activityRequirementBindingsByActivityId.clear();
activityPatternBindingsByActivityId.clear();
categoriesById.clear();
categoryActivityBindingsByCategoryId.clear();
categoryDefinitionsById.clear();
definedActivityIds.clear();
definedCategoryIds.clear();
enabledActivityIds.clear();
identifiersById.clear();
}

@Override
synchronized public IActivity getActivity(String activityId) {
if (activityId == null) {
Expand Down Expand Up @@ -596,7 +613,7 @@ private Map<String, ActivityEvent> updateActivities(Collection<String> activityI
}

private IPropertyChangeListener enabledWhenListener = event -> {
if (addingEvaluationListener) {
if (addingEvaluationListener || isDisposed()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ public Set<String> getEnabledActivityIds() {
public IIdentifier getIdentifier(String identifierId) {
return activityManager.getIdentifier(identifierId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,13 @@ private ImageBindingRegistry getCategoryImageBindingRegistry() {
}

/**
* Dispose of the image registries.
* Dispose of the image registries and activity manager.
*
* @since 3.1
*/
public void dispose() {
this.proxyActivityManager.dispose();
this.mutableActivityManager.dispose();
if (activityImageBindingRegistry != null) {
activityImageBindingRegistry.dispose();
PlatformUI.getWorkbench().getExtensionTracker().unregisterHandler(activityImageBindingRegistry);
Expand Down

0 comments on commit a776756

Please sign in to comment.