diff options
author | Thomas Watson | 2020-06-30 14:46:20 +0000 |
---|---|---|
committer | Thomas Watson | 2020-06-30 15:19:20 +0000 |
commit | a373993f5fd26cec102fe67dce28a4359bd366a0 (patch) | |
tree | 16a7ab2bb42572395975143ee5d2e14a77c26668 /bundles | |
parent | f3e9a312f7429f65e1e9ea3f399ff7630d0d08d8 (diff) | |
download | rt.equinox.bundles-a373993f5fd26cec102fe67dce28a4359bd366a0.tar.gz rt.equinox.bundles-a373993f5fd26cec102fe67dce28a4359bd366a0.tar.xz rt.equinox.bundles-a373993f5fd26cec102fe67dce28a4359bd366a0.zip |
Bug 563987 - Use ServiceCaller instead of ServiceTracker in commonY20200701-1200Y20200701-0020I20200701-0330I20200630-1800
bundle.
Change-Id: I34936ccc46c35610e9d06065768c1b581e006c7b
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles')
-rw-r--r-- | bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java | 73 | ||||
-rw-r--r-- | bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/ServiceCaller.java | 5 |
2 files changed, 19 insertions, 59 deletions
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java index 578c365e4..a2e8f3cc3 100644 --- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java +++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java @@ -19,6 +19,7 @@ import java.util.*; import org.eclipse.core.internal.boot.PlatformURLBaseConnection; import org.eclipse.core.internal.boot.PlatformURLHandler; import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.core.runtime.ServiceCaller; import org.eclipse.equinox.log.ExtendedLogReaderService; import org.eclipse.equinox.log.ExtendedLogService; import org.eclipse.osgi.framework.log.FrameworkLog; @@ -50,13 +51,15 @@ public class Activator implements BundleActivator { private static Activator singleton; private ServiceRegistration<URLConverter> platformURLConverterService = null; private ServiceRegistration<IAdapterManager> adapterManagerService = null; - private ServiceTracker<Object, Location> installLocationTracker = null; - private ServiceTracker<Object, Location> instanceLocationTracker = null; - private ServiceTracker<Object, Location> configLocationTracker = null; - private ServiceTracker<Object, PackageAdmin> bundleTracker = null; - private ServiceTracker<Object, DebugOptions> debugTracker = null; - private ServiceTracker<Object, FrameworkLog> logTracker = null; - private ServiceTracker<Object, BundleLocalization> localizationTracker = null; + private final ServiceCaller<Location> installLocationTracker = new ServiceCaller<>(getClass(), Location.class, Location.INSTALL_FILTER); + private final ServiceCaller<Location> instanceLocationTracker = new ServiceCaller<>(getClass(), Location.class, Location.INSTANCE_FILTER); + private final ServiceCaller<Location> configLocationTracker = new ServiceCaller<>(getClass(), Location.class, Location.CONFIGURATION_FILTER); + @SuppressWarnings("deprecation") + private final ServiceCaller<PackageAdmin> bundleTracker = new ServiceCaller<>(getClass(), PackageAdmin.class); + private final ServiceCaller<DebugOptions> debugTracker = new ServiceCaller<>(getClass(), DebugOptions.class); + private final ServiceCaller<FrameworkLog> logTracker = new ServiceCaller<>(getClass(), FrameworkLog.class); + private final ServiceCaller<BundleLocalization> localizationTracker = new ServiceCaller<>(getClass(), BundleLocalization.class); + private ServiceRegistration<DebugOptionsListener> debugRegistration; /* @@ -72,14 +75,6 @@ public class Activator implements BundleActivator { bundleContext = context; singleton = this; - installLocationTracker = openServiceTracker(Location.INSTALL_FILTER); - instanceLocationTracker = openServiceTracker(Location.INSTANCE_FILTER); - configLocationTracker = openServiceTracker(Location.CONFIGURATION_FILTER); - bundleTracker = openServiceTracker(PackageAdmin.class); - debugTracker = openServiceTracker(DebugOptions.class); - logTracker = openServiceTracker(FrameworkLog.class); - localizationTracker = openServiceTracker(BundleLocalization.class); - RuntimeLog.setLogWriter(getPlatformWriter(context)); Dictionary<String, Object> urlProperties = new Hashtable<>(); urlProperties.put("protocol", "platform"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -111,28 +106,28 @@ public class Activator implements BundleActivator { * Return the configuration location service, if available. */ public Location getConfigurationLocation() { - return configLocationTracker.getService(); + return configLocationTracker.current().orElse(null); } /* * Return the debug options service, if available. */ public DebugOptions getDebugOptions() { - return debugTracker.getService(); + return debugTracker.current().orElse(null); } /* * Return the framework log service, if available. */ public FrameworkLog getFrameworkLog() { - return logTracker.getService(); + return logTracker.current().orElse(null); } /* * Return the instance location service, if available. */ public Location getInstanceLocation() { - return instanceLocationTracker.getService(); + return instanceLocationTracker.current().orElse(null); } /** @@ -160,7 +155,7 @@ public class Activator implements BundleActivator { * Return the package admin service, if available. */ private PackageAdmin getBundleAdmin() { - return bundleTracker.getService(); + return bundleTracker.current().orElse(null); } /* @@ -177,20 +172,7 @@ public class Activator implements BundleActivator { * Return the install location service if available. */ public Location getInstallLocation() { - return installLocationTracker.getService(); - } - - private <T> ServiceTracker<Object, T> openServiceTracker(String filterString) throws InvalidSyntaxException { - Filter filter = bundleContext.createFilter(filterString); - ServiceTracker<Object, T> tracker = new ServiceTracker<>(bundleContext, filter, null); - tracker.open(); - return tracker; - } - - private <T> ServiceTracker<Object, T> openServiceTracker(Class<?> clazz) { - ServiceTracker<Object, T> tracker = new ServiceTracker<>(bundleContext, clazz.getName(), null); - tracker.open(); - return tracker; + return installLocationTracker.current().orElse(null); } /** @@ -218,7 +200,7 @@ public class Activator implements BundleActivator { if (localizationTracker == null) { throw new MissingResourceException(CommonMessages.activator_resourceBundleNotStarted, bundle.getSymbolicName(), ""); //$NON-NLS-1$ } - BundleLocalization location = localizationTracker.getService(); + BundleLocalization location = localizationTracker.current().orElse(null); ResourceBundle result = null; if (location != null) result = location.getLocalization(bundle, locale); @@ -238,27 +220,6 @@ public class Activator implements BundleActivator { adapterManagerService.unregister(); adapterManagerService = null; } - if (installLocationTracker != null) { - installLocationTracker.close(); - } - if (configLocationTracker != null) { - configLocationTracker.close(); - } - if (bundleTracker != null) { - bundleTracker.close(); - } - if (debugTracker != null) { - debugTracker.close(); - } - if (logTracker != null) { - logTracker.close(); - } - if (instanceLocationTracker != null) { - instanceLocationTracker.close(); - } - if (localizationTracker != null) { - localizationTracker.close(); - } if (debugRegistration != null) { debugRegistration.unregister(); debugRegistration = null; diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/ServiceCaller.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/ServiceCaller.java index bd472f563..7afe74e6e 100644 --- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/ServiceCaller.java +++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/ServiceCaller.java @@ -78,9 +78,8 @@ import org.osgi.util.tracker.ServiceTracker; * } * </pre> * - * Note that this class is intended for simple service usage patterns only. More advanced cases that - * require tracking of service ranking or additional service property matching must use other - * mechanisms such as the {@link ServiceTracker} or declarative services. + * Note that this class is intended for simple service usage patterns only. More advanced cases + * should use other mechanisms such as the {@link ServiceTracker} or declarative services. * * @param <Service> the service type for this caller * @since 3.13 |