Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2019-01-14 14:14:38 -0500
committerThomas Watson2019-01-15 18:23:29 -0500
commit7f14d56daa4a62009312101adfc5548aaa3574f5 (patch)
tree3e50ad3a1abd743fb31e7bfa45c3ee0d59de9e03
parent59d7624cbb331dc82ef89e52a0a18ae6a786dc50 (diff)
downloadrt.equinox.framework-7f14d56daa4a62009312101adfc5548aaa3574f5.tar.gz
rt.equinox.framework-7f14d56daa4a62009312101adfc5548aaa3574f5.tar.xz
rt.equinox.framework-7f14d56daa4a62009312101adfc5548aaa3574f5.zip
Bug 538717 - Update util to final OSGi R7
Change-Id: I4fa19a9ac897285c2faa80d70b6cb3cd71483dd8 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF8
-rw-r--r--bundles/org.eclipse.osgi.util/pom.xml2
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/DeferredPromiseImpl.java12
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseFactory.java32
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseImpl.java53
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/package-info.java4
6 files changed, 55 insertions, 56 deletions
diff --git a/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF
index b17b4f30a..8f3e034ab 100644
--- a/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %osgiUtil
Bundle-SymbolicName: org.eclipse.osgi.util
-Bundle-Version: 3.5.100.qualifier
+Bundle-Version: 3.5.200.qualifier
Bundle-Description: %osgiUtilDes
Bundle-Vendor: %eclipse.org
Bundle-Localization: plugin
@@ -11,14 +11,14 @@ Bundle-ContactAddress: www.eclipse.org
Export-Package: org.osgi.util.function;version="1.1",
org.osgi.util.measurement;version="1.0.2",
org.osgi.util.position;version="1.0.1";uses:="org.osgi.util.measurement",
- org.osgi.util.promise;version="1.1";uses:="org.osgi.util.function",
+ org.osgi.util.promise;version="1.1.1";uses:="org.osgi.util.function",
org.osgi.util.xml;version="1.0.1";uses:="org.osgi.framework,javax.xml.parsers"
Import-Package: org.osgi.framework; version=1.1,
javax.xml.parsers,
org.osgi.util.function; version="[1.1, 1.2)",
- org.osgi.util.measurement; version="[1.0.1, 1.1)",
+ org.osgi.util.measurement; version="[1.0.2, 1.1)",
org.osgi.util.position; version="[1.0.1, 1.1)",
- org.osgi.util.promise; version="[1.1, 1.2)",
+ org.osgi.util.promise; version="[1.1.1, 1.2)",
org.osgi.util.xml; version="[1.0.1, 1.1)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Automatic-Module-Name: org.eclipse.osgi.util
diff --git a/bundles/org.eclipse.osgi.util/pom.xml b/bundles/org.eclipse.osgi.util/pom.xml
index 85c48c49b..059d9d6cd 100644
--- a/bundles/org.eclipse.osgi.util/pom.xml
+++ b/bundles/org.eclipse.osgi.util/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.util</artifactId>
- <version>3.5.100-SNAPSHOT</version>
+ <version>3.5.200-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/DeferredPromiseImpl.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/DeferredPromiseImpl.java
index a65f67090..dcd40c58a 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/DeferredPromiseImpl.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/DeferredPromiseImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2014, 2017). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2014, 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.
@@ -230,7 +230,7 @@ final class DeferredPromiseImpl<T> extends PromiseImpl<T> {
*/
Promise<Void> resolveWith(Promise< ? extends T> with) {
DeferredPromiseImpl<Void> chained = deferred();
- chain(with, chained.new ResolveWith<>(with, this));
+ with.onResolve(chained.new ResolveWith<>(with, this));
return chained.orDone();
}
@@ -301,7 +301,7 @@ final class DeferredPromiseImpl<T> extends PromiseImpl<T> {
result.fail = e; // propagate new exception
}
if (returned != null) {
- chain(returned, new Chain(returned));
+ returned.onResolve(new Chain(returned));
return;
}
}
@@ -462,7 +462,7 @@ final class DeferredPromiseImpl<T> extends PromiseImpl<T> {
result.fail = e;
}
if (flatmap != null) {
- chain(flatmap, new Chain(flatmap));
+ flatmap.onResolve(new Chain(flatmap));
return;
}
}
@@ -529,7 +529,7 @@ final class DeferredPromiseImpl<T> extends PromiseImpl<T> {
result.fail = e;
}
if (recovered != null) {
- chain(recovered, new Chain(recovered));
+ recovered.onResolve(new Chain(recovered));
return;
}
}
@@ -555,7 +555,7 @@ final class DeferredPromiseImpl<T> extends PromiseImpl<T> {
public void run() {
Result<T> result = promise.collect();
if (result.fail != null) {
- chain(fallback, new FallbackChain(fallback, result.fail));
+ fallback.onResolve(new FallbackChain(fallback, result.fail));
return;
}
tryResolve(result.value, null);
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) {
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseImpl.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseImpl.java
index d78ae3b66..299222bcf 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseImpl.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2014, 2017). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2014, 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.
@@ -100,8 +100,17 @@ abstract class PromiseImpl<T> implements Promise<T> {
*/
@Override
public Promise<T> onResolve(Runnable callback) {
- callbacks.offer(callback);
- notifyCallbacks(); // call any registered callbacks
+ requireNonNull(callback);
+ if (factory.allowCurrentThread() && isDone()) {
+ try {
+ callback.run();
+ } catch (Throwable t) {
+ uncaughtException(t);
+ }
+ } else {
+ callbacks.offer(callback);
+ notifyCallbacks(); // call any registered callbacks
+ }
return this;
}
@@ -166,24 +175,6 @@ abstract class PromiseImpl<T> implements Promise<T> {
}
/**
- * Run the specified chain when the specified promise is resolved.
- *
- * @param promise The promise associated with the chain.
- * @param chain The chain to run when the promise is resolved.
- */
- static <V> void chain(Promise<V> promise, Runnable chain) {
- if (promise.isDone()) {
- try {
- chain.run();
- } catch (Throwable t) {
- uncaughtException(t);
- }
- } else {
- promise.onResolve(chain);
- }
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -257,7 +248,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public <R> Promise<R> then(Success<? super T, ? extends R> success, Failure failure) {
DeferredPromiseImpl<R> chained = deferred();
- chain(this, chained.new Then<>(this, success, failure));
+ onResolve(chained.new Then<>(this, success, failure));
return chained.orDone();
}
@@ -275,7 +266,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public Promise<T> thenAccept(Consumer< ? super T> consumer) {
DeferredPromiseImpl<T> chained = deferred();
- chain(this, chained.new ThenAccept(this, consumer));
+ onResolve(chained.new ThenAccept(this, consumer));
return chained.orDone();
}
@@ -286,7 +277,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public Promise<T> filter(Predicate<? super T> predicate) {
DeferredPromiseImpl<T> chained = deferred();
- chain(this, chained.new Filter(this, predicate));
+ onResolve(chained.new Filter(this, predicate));
return chained.orDone();
}
@@ -296,7 +287,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public <R> Promise<R> map(Function<? super T, ? extends R> mapper) {
DeferredPromiseImpl<R> chained = deferred();
- chain(this, chained.new Map<>(this, mapper));
+ onResolve(chained.new Map<>(this, mapper));
return chained.orDone();
}
@@ -307,7 +298,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public <R> Promise<R> flatMap(Function<? super T, Promise<? extends R>> mapper) {
DeferredPromiseImpl<R> chained = deferred();
- chain(this, chained.new FlatMap<>(this, mapper));
+ onResolve(chained.new FlatMap<>(this, mapper));
return chained.orDone();
}
@@ -317,7 +308,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public Promise<T> recover(Function<Promise<?>, ? extends T> recovery) {
DeferredPromiseImpl<T> chained = deferred();
- chain(this, chained.new Recover(this, recovery));
+ onResolve(chained.new Recover(this, recovery));
return chained.orDone();
}
@@ -327,7 +318,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public Promise<T> recoverWith(Function<Promise<?>, Promise<? extends T>> recovery) {
DeferredPromiseImpl<T> chained = deferred();
- chain(this, chained.new RecoverWith(this, recovery));
+ onResolve(chained.new RecoverWith(this, recovery));
return chained.orDone();
}
@@ -337,7 +328,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public Promise<T> fallbackTo(Promise<? extends T> fallback) {
DeferredPromiseImpl<T> chained = deferred();
- chain(this, chained.new FallbackTo(this, fallback));
+ onResolve(chained.new FallbackTo(this, fallback));
return chained.orDone();
}
@@ -347,7 +338,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public Promise<T> timeout(long millis) {
DeferredPromiseImpl<T> chained = deferred();
- chain(this, chained.new Timeout(this, millis));
+ onResolve(chained.new Timeout(this, millis));
return chained.orDone();
}
@@ -357,7 +348,7 @@ abstract class PromiseImpl<T> implements Promise<T> {
@Override
public Promise<T> delay(long millis) {
DeferredPromiseImpl<T> chained = deferred();
- chain(this, chained.new Delay(this, millis));
+ onResolve(chained.new Delay(this, millis));
return chained.orDone();
}
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/package-info.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/package-info.java
index 56e2d8e4b..1dde8192b 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/package-info.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2014, 2016). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2014, 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.
@@ -31,7 +31,7 @@
* @author $Id$
*/
-@Version("1.1")
+@Version("1.1.1")
package org.osgi.util.promise;
import org.osgi.annotation.versioning.Version;

Back to the top