This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git
The following commit(s) were added to refs/heads/master by this push:
new 5f69191 Don't block framework event thread while waiting for startup.
5f69191 is described below
commit 5f69191aab02d9a59241fa2d84990dda2c43d815
Author: Karl Pauls <[email protected]>
AuthorDate: Thu Jun 21 22:41:01 2018 +0200
Don't block framework event thread while waiting for startup.
---
.../launcher/impl/launchers/AbstractRunner.java | 55 +++++++++++++++-------
1 file changed, 38 insertions(+), 17 deletions(-)
diff --git
a/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java
b/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java
index 00ec9cb..474c4cb 100644
---
a/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java
+++
b/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java
@@ -48,6 +48,9 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -68,6 +71,8 @@ public abstract class AbstractRunner implements
Callable<Integer> {
private final AtomicInteger waitRequested = new AtomicInteger(0);
+ private volatile boolean install;
+
public AbstractRunner(final Map<String, String> frameworkProperties, final
List<Object[]> configurations, final List<File> installables) {
this.configurations = new ArrayList<>(configurations);
this.installables = installables;
@@ -155,6 +160,8 @@ public abstract class AbstractRunner implements
Callable<Integer> {
throw new BundleException("Unable to install bundles.", ioe);
}
+ // TODO: double check bundles and take installables into account
+ install = framework.getBundleContext().getBundles().length !=
bundleCount;
try
{
// TODO: double check bundles and take installables into account
@@ -192,34 +199,47 @@ public abstract class AbstractRunner implements
Callable<Integer> {
protected boolean startFramework(final Framework framework, long timeout,
TimeUnit unit) throws BundleException, InterruptedException
{
CountDownLatch latch = new CountDownLatch(1);
+
+ final Executor executor = Executors.newSingleThreadExecutor();
+
FrameworkListener listener = new FrameworkListener()
{
@Override
public void frameworkEvent(FrameworkEvent frameworkEvent)
{
if (frameworkEvent.getType() == FrameworkEvent.STARTED ||
frameworkEvent.getType() == FrameworkEvent.STARTLEVEL_CHANGED) {
- if (framework.getState() == Framework.ACTIVE &&
targetStartlevel > framework.adapt(FrameworkStartLevel.class).getStartLevel())
- {
- if (waitRequested.get() == 0) {
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e)
+ if (framework.getState() == Framework.ACTIVE &&
targetStartlevel > framework.adapt(FrameworkStartLevel.class).getStartLevel()) {
+ if (install) {
+ executor.execute(() ->
{
- e.printStackTrace();
- }
+ if (waitRequested.get() == 0) {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ while (waitRequested.get() > 0) {
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+
framework.adapt(FrameworkStartLevel.class).setStartLevel(framework.adapt(FrameworkStartLevel.class).getStartLevel()
+ 1);
+ } catch (Exception ex) {
+ latch.countDown();
+ }
+ });
}
- while (waitRequested.get() > 0) {
+ else {
try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
+
framework.adapt(FrameworkStartLevel.class).setStartLevel(targetStartlevel);
+ } catch (Exception ex) {
+ latch.countDown();
}
}
- try {
-
framework.adapt(FrameworkStartLevel.class).setStartLevel(framework.adapt(FrameworkStartLevel.class).getStartLevel()
+ 1);
- } catch (Exception ex) {
- latch.countDown();
- }
}
else {
latch.countDown();
@@ -235,6 +255,7 @@ public abstract class AbstractRunner implements
Callable<Integer> {
try {
return latch.await(timeout, unit);
} finally {
+ ((ExecutorService) executor).shutdownNow();
framework.getBundleContext().removeFrameworkListener(listener);
}
}