diff options
author | Lars Vogel | 2019-08-27 09:18:04 +0000 |
---|---|---|
committer | Lars Vogel | 2020-04-27 12:43:25 +0000 |
commit | e06fd29caa802553d4efcc36c86812e4f910d4b7 (patch) | |
tree | f5f40bacba35e2932edea6caf4346b41b20f7614 | |
parent | ecdcce0a50cf785ce73407aae221ffee755eed2c (diff) | |
download | rt.equinox.p2-e06fd29caa802553d4efcc36c86812e4f910d4b7.tar.gz rt.equinox.p2-e06fd29caa802553d4efcc36c86812e4f910d4b7.tar.xz rt.equinox.p2-e06fd29caa802553d4efcc36c86812e4f910d4b7.zip |
Bug 443809 - Reduce work in AutomaticUpdateScheduler
Profile ID is always IProfileRegistry.SELF so use constant instead of
assigning it to variable.
Remove frequent access to IProvisioningAgent by passing it a field
Rename garbageCollect method to something more telling
(removeUnusedPlugins)
Move session creation to plugin at first access instead of eager loading
Remove profileId== null check as this never can happen
(IProfileRegistry.SELF) is always used
Remove constructor and move logic to earlyStartup method
Read and check PREF_AUTO_UPDATE_SCHEDULE only in schedule
Move checker initialization to the scheduleUpdate method where it is
used
Change-Id: Ib02744583ef6d285262e494211f85e461376f274
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
2 files changed, 34 insertions, 51 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java index 5b5bc9ba6..a2241a7b0 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java @@ -83,8 +83,6 @@ public class AutomaticUpdatePlugin extends AbstractUIPlugin { super.start(bundleContext); plugin = this; context = bundleContext; - IProvisioningAgent agent = ServiceHelper.getService(getContext(), IProvisioningAgent.class); - session = new ProvisioningSession(agent); } @Override @@ -104,8 +102,9 @@ public class AutomaticUpdatePlugin extends AbstractUIPlugin { public AutomaticUpdateScheduler getScheduler() { // If the scheduler was disabled, it does not get initialized - if (scheduler == null) + if (scheduler == null) { scheduler = new AutomaticUpdateScheduler(); + } return scheduler; } @@ -181,6 +180,12 @@ public class AutomaticUpdatePlugin extends AbstractUIPlugin { } public ProvisioningSession getSession() { + if (session == null) { + synchronized (this) { + IProvisioningAgent agent = ServiceHelper.getService(getContext(), IProvisioningAgent.class); + session = new ProvisioningSession(agent); + } + } return session; } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java index 12aba4601..604b6a292 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java @@ -53,60 +53,39 @@ public class AutomaticUpdateScheduler implements IStartup { private IUpdateListener listener = null; private IUpdateChecker checker = null; - String profileId; - /** - * The constructor. - */ - public AutomaticUpdateScheduler() { - AutomaticUpdatePlugin.getDefault().setScheduler(this); - IProvisioningAgent agent = ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), - IProvisioningAgent.class); - checker = agent.getService(IUpdateChecker.class); - if (checker == null) { - // Something did not initialize properly - IStatus status = new Status(IStatus.ERROR, AutomaticUpdatePlugin.PLUGIN_ID, - AutomaticUpdateMessages.AutomaticUpdateScheduler_UpdateNotInitialized); - StatusManager.getManager().handle(status, StatusManager.LOG); - return; - } - profileId = IProfileRegistry.SELF; - } + private IProvisioningAgent agent; @Override public void earlyStartup() { - IProvisioningAgent agent = ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), - IProvisioningAgent.class); + AutomaticUpdatePlugin.getDefault().setScheduler(this); + agent = ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), IProvisioningAgent.class); IProfileRegistry registry = agent.getService(IProfileRegistry.class); - IProfile currentProfile = registry.getProfile(profileId); - if (currentProfile != null && new MigrationSupport().performMigration(agent, registry, currentProfile)) + IProfile currentProfile = registry.getProfile(IProfileRegistry.SELF); + if (currentProfile != null && new MigrationSupport().performMigration(agent, registry, currentProfile)) { return; + } - garbageCollect(); + removeUnusedPlugins(registry); scheduleUpdate(); } /** * Invokes the garbage collector to discard unused plugins, if specified by a * corresponding preference. + * */ - private void garbageCollect() { - // Nothing to do if we don't know what profile we are checking - if (profileId == null) - return; + private void removeUnusedPlugins(IProfileRegistry registry) { // check if gc is enabled IPreferenceStore pref = AutomaticUpdatePlugin.getDefault().getPreferenceStore(); - if (!pref.getBoolean(PreferenceConstants.PREF_GC_ON_STARTUP)) + if (!pref.getBoolean(PreferenceConstants.PREF_GC_ON_STARTUP)) { return; - IProvisioningAgent agent = ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), - IProvisioningAgent.class); + } GarbageCollector collector = agent.getService(GarbageCollector.class); - if (collector == null) - return; - IProfileRegistry registry = agent.getService(IProfileRegistry.class); - if (registry == null) + if (collector == null || registry == null) { return; - IProfile profile = registry.getProfile(profileId); + } + IProfile profile = registry.getProfile(IProfileRegistry.SELF); if (profile == null) return; collector.runGC(profile); @@ -118,25 +97,15 @@ public class AutomaticUpdateScheduler implements IStartup { public void rescheduleUpdate() { removeUpdateListener(); - IPreferenceStore pref = AutomaticUpdatePlugin.getDefault().getPreferenceStore(); - String schedule = pref.getString(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE); - // See if we have a scheduled check or startup only. If it is - // startup only, there is nothing more to do now, a listener will - // be created on the next startup. - if (schedule.equals(PreferenceConstants.PREF_UPDATE_ON_STARTUP)) { - return; - } scheduleUpdate(); } private void scheduleUpdate() { - // Nothing to do if we don't know what profile we are checking - if (profileId == null) - return; IPreferenceStore pref = AutomaticUpdatePlugin.getDefault().getPreferenceStore(); // See if automatic search is enabled at all - if (!pref.getBoolean(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED)) + if (!pref.getBoolean(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED)) { return; + } String schedule = pref.getString(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE); long delay = IUpdateChecker.ONE_TIME_CHECK; long poll = IUpdateChecker.ONE_TIME_CHECK; @@ -161,7 +130,16 @@ public class AutomaticUpdateScheduler implements IStartup { AutomaticUpdatePlugin.getDefault().getAutomaticUpdater().checkingForUpdates(); } }; - checker.addUpdateCheck(profileId, getProfileQuery(), delay, poll, listener); + + checker = agent.getService(IUpdateChecker.class); + if (checker == null) { + // Something did not initialize properly + IStatus status = new Status(IStatus.ERROR, AutomaticUpdatePlugin.PLUGIN_ID, + AutomaticUpdateMessages.AutomaticUpdateScheduler_UpdateNotInitialized); + StatusManager.getManager().handle(status, StatusManager.LOG); + return; + } + checker.addUpdateCheck(IProfileRegistry.SELF, getProfileQuery(), delay, poll, listener); } |