Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseFactory.java')
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseFactory.java32
1 files changed, 20 insertions, 12 deletions
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseFactory.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseFactory.java
index 16820b27f..23eb0cc47 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseFactory.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2017). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2017, 2018). All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
package org.osgi.util.promise;
import static java.util.Objects.requireNonNull;
-import static org.osgi.util.promise.PromiseImpl.*;
+import static org.osgi.util.promise.PromiseImpl.uncaughtException;
import java.util.ArrayList;
import java.util.Collection;
@@ -64,8 +64,8 @@ public class PromiseFactory {
null, null);
/**
- * The executor to use for callbacks. If {@code null}, the default
- * callback executor is used.
+ * The executor to use for callbacks. If {@code null}, the default callback
+ * executor is used.
*/
private final Executor callbackExecutor;
/**
@@ -74,6 +74,7 @@ public class PromiseFactory {
*/
private final ScheduledExecutorService scheduledExecutor;
+ private final boolean allowCurrentThread;
/**
* Create a new PromiseFactory with the specified callback executor.
@@ -101,6 +102,10 @@ public class PromiseFactory {
ScheduledExecutorService scheduledExecutor) {
this.callbackExecutor = callbackExecutor;
this.scheduledExecutor = scheduledExecutor;
+ allowCurrentThread = Boolean.parseBoolean(System.getProperty(
+ "org.osgi.util.promise.allowCurrentThread",
+ Boolean.TRUE.toString()));
+
}
/**
@@ -151,7 +156,7 @@ public class PromiseFactory {
* Returns a new Promise that has been resolved with the specified value.
* <p>
* The returned Promise uses the callback executor and scheduled executor of
- * this PromiseFactory object
+ * this PromiseFactory object.
* <p>
* Use this method instead of {@link Promises#resolved(Object)} to create a
* Promise which uses executors other than the default executors.
@@ -168,7 +173,7 @@ public class PromiseFactory {
* Returns a new Promise that has been resolved with the specified failure.
* <p>
* The returned Promise uses the callback executor and scheduled executor of
- * this PromiseFactory object
+ * this PromiseFactory object.
* <p>
* Use this method instead of {@link Promises#failed(Throwable)} to create a
* Promise which uses executors other than the default executors.
@@ -186,7 +191,7 @@ public class PromiseFactory {
* Returns a new Promise that will hold the result of the specified task.
* <p>
* The returned Promise uses the callback executor and scheduled executor of
- * this PromiseFactory object
+ * this PromiseFactory object.
* <p>
* The specified task will be executed on the {@link #executor() callback
* executor}.
@@ -212,7 +217,7 @@ public class PromiseFactory {
* Promises.
* <p>
* The returned Promise uses the callback executor and scheduled executor of
- * this PromiseFactory object
+ * this PromiseFactory object.
* <p>
* The returned Promise acts as a gate and must be resolved after all of the
* specified Promises are resolved.
@@ -247,7 +252,7 @@ public class PromiseFactory {
DeferredPromiseImpl<List<T>> chained = new DeferredPromiseImpl<>(this);
All<T,S> all = new All<>(chained, list);
for (Promise<S> p : list) {
- chain(p, all);
+ p.onResolve(all);
}
return chained.orDone();
}
@@ -264,8 +269,7 @@ public class PromiseFactory {
private final List<Promise<S>> promises;
private final AtomicInteger promiseCount;
- All(DeferredPromiseImpl<List<T>> chained,
- List<Promise<S>> promises) {
+ All(DeferredPromiseImpl<List<T>> chained, List<Promise<S>> promises) {
this.chained = requireNonNull(chained);
this.promises = requireNonNull(promises);
this.promiseCount = new AtomicInteger(promises.size());
@@ -310,6 +314,10 @@ public class PromiseFactory {
return new InlineExecutor();
}
+ boolean allowCurrentThread() {
+ return allowCurrentThread;
+ }
+
/**
* An Executor implementation which executes the task immediately on the
* thread calling the {@code Executor.execute} method.
@@ -360,7 +368,7 @@ public class PromiseFactory {
}
/**
- * Executor threads should not prevent VM from exiting
+ * Executor threads should not prevent VM from exiting.
*/
@Override
public Thread newThread(Runnable r) {

Back to the top