diff options
author | Lars Vogel | 2019-09-03 15:01:33 +0000 |
---|---|---|
committer | Lars Vogel | 2019-09-25 17:38:53 +0000 |
commit | ddeb5172326d921c1cbbf8f660691f8fc419de01 (patch) | |
tree | b9180ca03a6fcb3fe56c3272b6ac6c747f89b9b3 | |
parent | 50a40ab72125046bf41df4f4a388be4f1972497e (diff) | |
download | rt.equinox.p2-ddeb5172326d921c1cbbf8f660691f8fc419de01.tar.gz rt.equinox.p2-ddeb5172326d921c1cbbf8f660691f8fc419de01.tar.xz rt.equinox.p2-ddeb5172326d921c1cbbf8f660691f8fc419de01.zip |
Bug 550646 - Improve ConfigApplier#refreshPackages readability
By using CountDownLatch the code gets easier to read.
Change-Id: Ifa936c6fc17a9c142c2beb980b19403beaea412b
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r-- | bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java index e6c0a4437..92d488fa1 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java @@ -18,6 +18,7 @@ package org.eclipse.equinox.internal.simpleconfigurator; import java.io.*; import java.net.*; import java.util.*; +import java.util.concurrent.CountDownLatch; import org.eclipse.equinox.internal.simpleconfigurator.utils.*; import org.osgi.framework.*; import org.osgi.framework.namespace.*; @@ -396,26 +397,21 @@ class ConfigApplier { } } - final boolean[] flag = new boolean[] {false}; + CountDownLatch latch = new CountDownLatch(1); FrameworkListener listener = event -> { if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) { - synchronized (flag) { - flag[0] = true; - flag.notifyAll(); - } + latch.countDown(); } }; context.addFrameworkListener(listener); packageAdminService.refreshPackages(allSameBSNs.toArray(new Bundle[0])); - synchronized (flag) { - while (!flag[0]) { - try { - flag.wait(); - } catch (InterruptedException e) { - //ignore - } - } + + try { + latch.await(); + } catch (InterruptedException e) { + // ignore } + // if (DEBUG) { // for (int i = 0; i < bundles.length; i++) { // System.out.println(SimpleConfiguratorUtils.getBundleStateString(bundles[i])); |