Skip to content

Commit

Permalink
Bug 560084: Improve startup up time of Marketplace client
Browse files Browse the repository at this point in the history
Refactored UI initialization. Everything is lazy
and service-based now.

Change-Id: I43bebf133f9d764ce336895e8cd6bbff13c166b4
Signed-off-by: Carsten Reckord <reckord@yatta.de>
  • Loading branch information
creckord committed Sep 2, 2020
1 parent 89f7cc9 commit f99217c
Show file tree
Hide file tree
Showing 32 changed files with 695 additions and 195 deletions.
Expand Up @@ -47,7 +47,7 @@ public class HttpClientService {

private HttpServiceContext context;

private IProxyService proxyService;
private volatile IProxyService proxyService;

@Reference(policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, updated = "bindClientFactory", unbind = "unbindClientFactory")
void bindClientFactory(HttpClientFactory factory) {
Expand Down
@@ -0,0 +1,8 @@
classpath=true
dsVersion=V1_3
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
path=OSGI-INF/services
validationErrorLevel=error
validationErrorLevel.missingImplicitUnbindMethod=error
406 changes: 404 additions & 2 deletions org.eclipse.epp.mpc.ui/MPC Runtime.launch

Large diffs are not rendered by default.

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.epp.mpc.ui.debug.options">
<property name="listener.symbolic.name" value="org.eclipse.epp.mpc.ui"/>
<service>
<provide interface="org.eclipse.osgi.service.debug.DebugOptionsListener"/>
</service>
<implementation class="org.eclipse.epp.internal.mpc.ui.MarketplaceClientUiPlugin$DebugOptionsInitializer"/>
</scr:component>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.epp.mpc.ui.marketplace-client">
<implementation class="org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceClientService"/>
<service>
<provide interface="org.eclipse.epp.mpc.ui.IMarketplaceClientService"/>
</service>
</scr:component>
</service>
<implementation class="org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceClientService"/>
</scr:component>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="org.eclipse.epp.mpc.ui.resources">
<service>
<provide interface="org.eclipse.epp.internal.mpc.ui.MarketplaceClientUiResources"/>
</service>
<implementation class="org.eclipse.epp.internal.mpc.ui.MarketplaceClientUiResources"/>
</scr:component>
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.statushandlers.StatusManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;

/**
Expand Down Expand Up @@ -135,7 +136,7 @@ public static IStatus computeWellknownProblemStatus(Throwable exception) {
}

public static BundleContext getBundleContext() {
return MarketplaceClientUiPlugin.getInstance().getBundle().getBundleContext();
return FrameworkUtil.getBundle(MarketplaceClientUiPlugin.class).getBundleContext();
}

public static Map<String, IInstallableUnit> computeInstalledIUsById(IProgressMonitor monitor) {
Expand Down
Expand Up @@ -13,33 +13,21 @@
*******************************************************************************/
package org.eclipse.epp.internal.mpc.ui;

import static org.eclipse.jface.resource.ResourceLocator.imageDescriptorFromBundle;

import java.util.Hashtable;

import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.epp.internal.mpc.core.util.DebugTraceUtil;
import org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider;
import org.eclipse.epp.mpc.ui.IMarketplaceClientService;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.DecorationOverlayIcon;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.debug.DebugOptionsListener;
import org.eclipse.osgi.service.debug.DebugTrace;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.service.component.annotations.Component;

/**
* bundle activator. Prefer {@link MarketplaceClientUi} where possible.
*
* @author David Green
*/
public class MarketplaceClientUiPlugin extends AbstractUIPlugin {
public class MarketplaceClientUiPlugin implements BundleActivator {

/**
* image registry key
Expand Down Expand Up @@ -105,126 +93,21 @@ public class MarketplaceClientUiPlugin extends AbstractUIPlugin {

public static final String DROP_ADAPTER_DEBUG_OPTION = DEBUG_OPTION + "/dnd"; //$NON-NLS-1$

private static MarketplaceClientUiPlugin instance;

private static BundleContext bundleContext;

public static boolean DEBUG = false;

private static DebugTrace debugTrace;

private ServiceTracker<IMarketplaceClientService, IMarketplaceClientService> clientServiceTracker;

private ResourceProvider resourceProvider;

public MarketplaceClientUiPlugin() {
}

@Override
public void start(BundleContext context) throws Exception {
instance = this;
super.start(context);
MarketplaceClientUiPlugin.bundleContext = context;
clientServiceTracker = new ServiceTracker<>(context, IMarketplaceClientService.class, null);
clientServiceTracker.open();
resourceProvider = new ResourceProvider();

Hashtable<String, String> props = new Hashtable<>(2);
props.put(org.eclipse.osgi.service.debug.DebugOptions.LISTENER_SYMBOLICNAME, MarketplaceClientUi.BUNDLE_ID);
context.registerService(DebugOptionsListener.class.getName(), (DebugOptionsListener) options -> {
DebugTrace debugTrace = null;
boolean debug = options.getBooleanOption(MarketplaceClientUi.BUNDLE_ID + DEBUG_OPTION, false);
if (debug) {
debugTrace = options.newDebugTrace(MarketplaceClientUi.BUNDLE_ID);
}
DEBUG = debug;
MarketplaceClientUiPlugin.debugTrace = debugTrace;
}, props);
}

@Override
public void stop(BundleContext context) throws Exception {
Job.getJobManager().cancel(context.getBundle());
clientServiceTracker.close();
clientServiceTracker = null;

if (resourceProvider != null) {
resourceProvider.dispose();
resourceProvider = null;
}
MarketplaceClientUiPlugin.bundleContext = null;
super.stop(context);
debugTrace = null;
instance = null;
}

/**
* Get the singleton instance. Prefer {@link MarketplaceClientUi} where possible.
*/
public static MarketplaceClientUiPlugin getInstance() {
return instance;
}

@Override
protected ImageRegistry createImageRegistry() {
ImageRegistry imageRegistry = super.createImageRegistry();
imageRegistry.put(NO_ICON_PROVIDED,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/noiconprovided.png") //$NON-NLS-1$
.get());
imageRegistry.put(NO_ICON_PROVIDED_CATALOG,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/noiconprovided32.png").get()); //$NON-NLS-1$
imageRegistry.put(DEFAULT_MARKETPLACE_ICON,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/marketplace_banner.png").get()); //$NON-NLS-1$
imageRegistry.put(IU_ICON, imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/iu_obj.png").get()); //$NON-NLS-1$
imageRegistry.put(IU_ICON_UPDATE,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/iu_update_obj.png").get()); //$NON-NLS-1$
imageRegistry.put(IU_ICON_INSTALL,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/iu_install_obj.png").get()); //$NON-NLS-1$
imageRegistry.put(IU_ICON_UNINSTALL,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/iu_uninstall_obj.png").get()); //$NON-NLS-1$
imageRegistry.put(IU_ICON_DISABLED,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/iu_disabled_obj.png").get()); //$NON-NLS-1$
{
ImageDescriptor errorOverlay = PlatformUI.getWorkbench()
.getSharedImages()
.getImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR);
Image iuImage = imageRegistry.get(IU_ICON);
DecorationOverlayIcon iuErrorIcon = new DecorationOverlayIcon(iuImage, errorOverlay,
IDecoration.BOTTOM_RIGHT);
imageRegistry.put(IU_ICON_ERROR, iuErrorIcon);
}

imageRegistry.put(NEWS_ICON_UPDATE,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/news_update.png").get()); //$NON-NLS-1$
imageRegistry.put(ITEM_ICON_STAR,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/star.png").get()); //$NON-NLS-1$
imageRegistry.put(ITEM_ICON_STAR_SELECTED,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/star-selected.png").get()); //$NON-NLS-1$
imageRegistry.put(ITEM_ICON_SHARE,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/share.png").get()); //$NON-NLS-1$
imageRegistry.put(ACTION_ICON_FAVORITES,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/action-item-favorites.png").get()); //$NON-NLS-1$
imageRegistry.put(ACTION_ICON_LOGIN,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/action-item-login.png").get()); //$NON-NLS-1$
imageRegistry.put(ACTION_ICON_WARNING,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/action-item-warning.png").get()); //$NON-NLS-1$
imageRegistry.put(ACTION_ICON_UPDATE,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/action-item-update.png").get()); //$NON-NLS-1$
imageRegistry.put(FAVORITES_LIST_ICON,
imageDescriptorFromBundle(getBundle().getSymbolicName(), "icons/favorites-list.png").get()); //$NON-NLS-1$
return imageRegistry;
}

public IMarketplaceClientService getClientService() {
return clientServiceTracker == null ? null : clientServiceTracker.getService();
}

public ResourceProvider getResourceProvider() {
return resourceProvider;
}

public static BundleContext getBundleContext() {
return bundleContext;
}

public static void trace(String option, String message) {
Expand All @@ -240,4 +123,21 @@ public static void trace(String option, String message, Object... parameters) {
DebugTraceUtil.trace(trace, option, message, parameters);
}
}

@Component(name = "org.eclipse.epp.mpc.ui.debug.options", property = {
"listener.symbolic.name=org.eclipse.epp.mpc.ui" })
public static class DebugOptionsInitializer implements DebugOptionsListener {

@Override
public void optionsChanged(DebugOptions options) {
DebugTrace debugTrace = null;
boolean debug = options.getBooleanOption(MarketplaceClientUi.BUNDLE_ID + DEBUG_OPTION, false);
if (debug) {
debugTrace = options.newDebugTrace(MarketplaceClientUi.BUNDLE_ID);
}
DEBUG = debug;
MarketplaceClientUiPlugin.debugTrace = debugTrace;
}

}
}

0 comments on commit f99217c

Please sign in to comment.