Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2017-08-22 12:45:55 +0000
committerThomas Watson2017-08-22 12:49:54 +0000
commit18b75ba105ec2e868cb0c13dff1662e73813b678 (patch)
tree44a294cac6f394b34718ec24819d3370dd3e049d /bundles/org.eclipse.osgi.util
parente47a6cbd20d91e10988d4432e449d6ed4663f320 (diff)
downloadrt.equinox.framework-18b75ba105ec2e868cb0c13dff1662e73813b678.tar.gz
rt.equinox.framework-18b75ba105ec2e868cb0c13dff1662e73813b678.tar.xz
rt.equinox.framework-18b75ba105ec2e868cb0c13dff1662e73813b678.zip
Change-Id: Id406562887a18b3afb377f0b8cfa38dddefd837f Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles/org.eclipse.osgi.util')
-rw-r--r--bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Measurement.java10
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/State.java7
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Unit.java25
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/package-info.java5
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/packageinfo1
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/position/package-info.java5
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/position/packageinfo1
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Deferred.java46
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/PromiseImpl.java247
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Promises.java138
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/XMLParserActivator.java67
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/package-info.java5
-rw-r--r--bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/packageinfo1
14 files changed, 375 insertions, 185 deletions
diff --git a/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF
index f58db0c5e..fd4880949 100644
--- a/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi.util/META-INF/MANIFEST.MF
@@ -9,7 +9,7 @@ Bundle-Localization: plugin
Bundle-DocUrl: http://www.eclipse.org
Bundle-ContactAddress: www.eclipse.org
Export-Package: org.osgi.util.function;version="1.1",
- org.osgi.util.measurement;version="1.0.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.xml;version="1.0.1";uses:="org.osgi.framework,javax.xml.parsers"
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Measurement.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Measurement.java
index 5d6be0f87..4a8cf6629 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Measurement.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Measurement.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2002, 2013). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2002, 2016). 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.
@@ -47,7 +47,7 @@ package org.osgi.util.measurement;
* @Immutable
* @author $Id$
*/
-public class Measurement implements Comparable {
+public class Measurement implements Comparable<Object> {
private final double value;
private final double error;
private final long time;
@@ -362,10 +362,11 @@ public class Measurement implements Comparable {
* @return a {@code String} object representing this {@code Measurement}
* object.
*/
+ @Override
public String toString() {
String result = name;
if (result == null) {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append(value);
if (error != 0.0d) {
sb.append(" +/- ");
@@ -408,6 +409,7 @@ public class Measurement implements Comparable {
* {@code Measurement} object is not equal to the {@code Unit}
* object of this object.
*/
+ @Override
public int compareTo(Object obj) {
if (this == obj) {
return 0;
@@ -437,6 +439,7 @@ public class Measurement implements Comparable {
*
* @return A hash code value for this object.
*/
+ @Override
public int hashCode() {
int h = hashCode;
if (h == 0) {
@@ -463,6 +466,7 @@ public class Measurement implements Comparable {
* @return {@code true} if this object is equal to the specified object;
* {@code false} otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/State.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/State.java
index 415613f39..e9fcca59e 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/State.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/State.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2002, 2013). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2002, 2016). 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.
@@ -91,8 +91,9 @@ public class State {
*
* @return a {@code String} object representing this object.
*/
+ @Override
public String toString() {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append(value);
if (name != null) {
sb.append(" \"");
@@ -107,6 +108,7 @@ public class State {
*
* @return A hash code value for this object.
*/
+ @Override
public int hashCode() {
int hash = 31 * 17 + value;
if (name != null) {
@@ -123,6 +125,7 @@ public class State {
* @return {@code true} if this object is equal to the specified object;
* {@code false} otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Unit.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Unit.java
index e97563d26..64d749c23 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Unit.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/Unit.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2002, 2013). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2002, 2016). 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.
@@ -16,7 +16,8 @@
package org.osgi.util.measurement;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
/**
* A unit system for measurements.
@@ -250,8 +251,8 @@ public class Unit {
*/
private final static Unit[] allUnits = new Unit[] {m, s, kg, K, A, mol, cd, rad, m_s, m_s2, m2, m3, Hz, N, Pa, J, W, C, V, F, Ohm, S, Wb, T, lx, Gy, kat, unity};
- /* @GuardedBy("this") */
- private static Hashtable base;
+ /* @GuardedBy("Unit.class") */
+ private static Map<Unit, Unit> base;
private final String name;
private final long type;
@@ -289,6 +290,7 @@ public class Unit {
* @return true if the specified {@code Unit} object is equal to this
* {@code Unit} object.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -304,6 +306,7 @@ public class Unit {
*
* @return This object's hash code.
*/
+ @Override
public int hashCode() {
return 31 * 17 + (int) (type ^ (type >>> 32));
}
@@ -399,13 +402,13 @@ public class Unit {
static synchronized Unit find(long type) {
if (base == null) {
int size = allUnits.length;
- base = new Hashtable(size << 1);
+ base = new HashMap<>(size << 1);
for (int i = 0; i < size; i++) {
base.put(allUnits[i], allUnits[i]);
}
}
Unit unit = new Unit(null, type);
- Unit out = (Unit) base.get(unit);
+ Unit out = base.get(unit);
if (out == null) {
base.put(unit, unit);
out = unit;
@@ -418,6 +421,7 @@ public class Unit {
*
* @return A {@code String} object representing the {@code Unit}
*/
+ @Override
public String toString() {
return name;
}
@@ -431,8 +435,8 @@ public class Unit {
int _mol = (int) (((type >> mol_SHIFT) & MASK) - ZERO);
int _cd = (int) (((type >> cd_SHIFT) & MASK) - ZERO);
int _rad = (int) (((type >> rad_SHIFT) & MASK) - ZERO);
- StringBuffer numerator = new StringBuffer();
- StringBuffer denominator = new StringBuffer();
+ StringBuilder numerator = new StringBuilder();
+ StringBuilder denominator = new StringBuilder();
addSIname(_m, "m", numerator, denominator);
addSIname(_s, "s", numerator, denominator);
addSIname(_kg, "kg", numerator, denominator);
@@ -451,9 +455,10 @@ public class Unit {
return numerator.toString();
}
- private static void addSIname(int si, String name, StringBuffer numerator, StringBuffer denominator) {
+ private static void addSIname(int si, String name, StringBuilder numerator,
+ StringBuilder denominator) {
if (si != 0) {
- StringBuffer sb = (si > 0) ? numerator : denominator;
+ StringBuilder sb = (si > 0) ? numerator : denominator;
if (sb.length() > 0) {
sb.append("*");
}
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/package-info.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/package-info.java
index 7603bac0b..bac289ab2 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/package-info.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2010, 2013). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2010, 2016). 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.
@@ -26,9 +26,10 @@
* <p>
* {@code Import-Package: org.osgi.util.measurement; version="[1.0,2.0)"}
*
- * @version 1.0.1
* @author $Id$
*/
+@Version("1.0.2")
package org.osgi.util.measurement;
+import org.osgi.annotation.versioning.Version;
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/packageinfo b/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/packageinfo
deleted file mode 100644
index c2664475c..000000000
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/measurement/packageinfo
+++ /dev/null
@@ -1 +0,0 @@
-version 1.0.1 \ No newline at end of file
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/position/package-info.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/position/package-info.java
index 63af1b6e6..b67b8069b 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/position/package-info.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/position/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2010, 2013). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2010, 2016). 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.
@@ -26,9 +26,10 @@
* <p>
* {@code Import-Package: org.osgi.util.position; version="[1.0,2.0)"}
*
- * @version 1.0.1
* @author $Id$
*/
+@Version("1.0.1")
package org.osgi.util.position;
+import org.osgi.annotation.versioning.Version;
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/position/packageinfo b/bundles/org.eclipse.osgi.util/src/org/osgi/util/position/packageinfo
deleted file mode 100644
index c2664475c..000000000
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/position/packageinfo
+++ /dev/null
@@ -1 +0,0 @@
-version 1.0.1 \ No newline at end of file
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Deferred.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Deferred.java
index 004925fa1..25c7442d3 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Deferred.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Deferred.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2014, 2016). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2014, 2017). 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.
@@ -16,7 +16,10 @@
package org.osgi.util.promise;
-import static org.osgi.util.promise.PromiseImpl.requireNonNull;
+import static java.util.Objects.requireNonNull;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ScheduledExecutorService;
/**
* A Deferred Promise resolution.
@@ -42,14 +45,49 @@ public class Deferred<T> {
private final PromiseImpl<T> promise;
/**
- * Create a new Deferred with an associated Promise.
+ * Create a new Deferred.
+ * <p>
+ * The default callback executor and default scheduled executor will be
+ * used.
*/
public Deferred() {
- promise = new PromiseImpl<>();
+ this(null, null);
+ }
+
+ /**
+ * Create a new Deferred with the specified callback executor.
+ * <p>
+ * The default scheduled executor will be used.
+ *
+ * @param callbackExecutor The executor to use for callbacks. {@code null}
+ * can be specified for the default callback executor.
+ * @since 1.1
+ */
+ public Deferred(Executor callbackExecutor) {
+ this(callbackExecutor, null);
+ }
+
+ /**
+ * Create a new Deferred with the specified callback and scheduled
+ * executors.
+ *
+ * @param callbackExecutor The executor to use for callbacks. {@code null}
+ * can be specified for the default callback executor.
+ * @param scheduledExecutor The scheduled executor for use for scheduled
+ * operations. {@code null} can be specified for the default
+ * scheduled executor.
+ * @since 1.1
+ */
+ public Deferred(Executor callbackExecutor,
+ ScheduledExecutorService scheduledExecutor) {
+ promise = new PromiseImpl<>(callbackExecutor, scheduledExecutor);
}
/**
* Returns the Promise associated with this Deferred.
+ * <p>
+ * All Promise objects created by the associated Promise will use the
+ * executors of the associated Promise.
*
* @return The Promise associated with this Deferred.
*/
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 2afb3771f..1a65fc8ef 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, 2016). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2014, 2017). 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.
@@ -16,6 +16,8 @@
package org.osgi.util.promise;
+import static java.util.Objects.requireNonNull;
+
import java.lang.reflect.InvocationTargetException;
import java.util.NoSuchElementException;
import java.util.concurrent.BlockingQueue;
@@ -23,11 +25,13 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.RunnableScheduledFuture;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.SynchronousQueue;
@@ -42,18 +46,26 @@ import org.osgi.util.function.Predicate;
/**
* Promise implementation.
- *
* <p>
* This class is not used directly by clients. Clients should use
* {@link Deferred} to create a resolvable {@link Promise}.
*
* @param <T> The result type associated with the Promise.
- *
* @ThreadSafe
* @author $Id$
*/
final class PromiseImpl<T> implements Promise<T> {
/**
+ * The executor to use for callbacks. If {@code null}, the default callback
+ * executor is used.
+ */
+ private final Executor callbackExecutor;
+ /**
+ * The executor to use for scheduled operations. If {@code null}, the
+ * default scheduled executor is used.
+ */
+ private final ScheduledExecutorService scheduledExecutor;
+ /**
* A ConcurrentLinkedQueue to hold the callbacks for this Promise, so no
* additional synchronization is required to write to or read from the
* queue.
@@ -91,8 +103,17 @@ final class PromiseImpl<T> implements Promise<T> {
/**
* Initialize this Promise.
+ *
+ * @param callbackExecutor The executor to use for callbacks. {@code null}
+ * can be specified for the default callback executor.
+ * @param scheduledExecutor The scheduled executor for use for scheduled
+ * operations. {@code null} can be specified for the default
+ * scheduled executor.
*/
- PromiseImpl() {
+ PromiseImpl(Executor callbackExecutor,
+ ScheduledExecutorService scheduledExecutor) {
+ this.callbackExecutor = callbackExecutor;
+ this.scheduledExecutor = scheduledExecutor;
callbacks = new ConcurrentLinkedQueue<>();
resolved = new CountDownLatch(1);
}
@@ -102,13 +123,21 @@ final class PromiseImpl<T> implements Promise<T> {
*
* @param v The value of this resolved Promise.
* @param f The failure of this resolved Promise.
+ * @param callbackExecutor The executor to use for callbacks. {@code null}
+ * can be specified for the default callback executor.
+ * @param scheduledExecutor The scheduled executor for use for scheduled
+ * operations. {@code null} can be specified for the default
+ * scheduled executor.
*/
- PromiseImpl(T v, Throwable f) {
+ PromiseImpl(T v, Throwable f, Executor callbackExecutor,
+ ScheduledExecutorService scheduledExecutor) {
if (f == null) {
value = v;
} else {
fail = f;
}
+ this.callbackExecutor = callbackExecutor;
+ this.scheduledExecutor = scheduledExecutor;
callbacks = new ConcurrentLinkedQueue<>();
resolved = new CountDownLatch(0);
}
@@ -164,24 +193,6 @@ final class PromiseImpl<T> implements Promise<T> {
}
/**
- * Call any registered callbacks if this Promise is resolved.
- */
- private void notifyCallbacks() {
- if (resolved.getCount() != 0) {
- return; // return if not resolved
- }
-
- /*
- * Note: multiple threads can be in this method removing callbacks from
- * the queue and executing them, so the order in which callbacks are
- * executed cannot be specified.
- */
- for (Runnable callback = callbacks.poll(); callback != null; callback = callbacks.poll()) {
- Callbacks.execute(callback);
- }
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -245,17 +256,65 @@ final class PromiseImpl<T> implements Promise<T> {
}
/**
+ * Call any registered callbacks if this Promise is resolved.
+ */
+ private void notifyCallbacks() {
+ if (resolved.getCount() != 0) {
+ return; // return if not resolved
+ }
+
+ /*
+ * Note: multiple threads can be in this method removing callbacks from
+ * the queue and executing them, so the order in which callbacks are
+ * executed cannot be specified.
+ */
+ Executor executor = callbackExecutor;
+ for (Runnable callback = callbacks.poll(); callback != null; callback = callbacks.poll()) {
+ if (executor == null) {
+ executor = DefaultExecutors.callbackExecutor();
+ }
+ try {
+ try {
+ executor.execute(callback);
+ } catch (RejectedExecutionException e) {
+ callback.run();
+ }
+ } catch (Throwable t) {
+ uncaughtException(t);
+ }
+ }
+ }
+
+ /**
+ * Handle an uncaught exception from a Runnable.
+ *
+ * @param t The uncaught exception.
+ * @since 1.1
+ */
+ static void uncaughtException(Throwable t) {
+ try {
+ Thread thread = Thread.currentThread();
+ thread.getUncaughtExceptionHandler().uncaughtException(thread, t);
+ } catch (Throwable ignored) {
+ // we ignore this
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
public <R> Promise<R> then(Success<? super T, ? extends R> success, Failure failure) {
- PromiseImpl<R> chained = new PromiseImpl<>();
+ PromiseImpl<R> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(chained.new Then<>(this, success, failure));
return chained;
}
/**
* {@inheritDoc}
+ *
+ * @since 1.1
*/
@Override
public <R> Promise<R> then(Success<? super T, ? extends R> success) {
@@ -263,6 +322,17 @@ final class PromiseImpl<T> implements Promise<T> {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public Promise<T> then(Callback callback) {
+ PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
+ onResolve(chained.new Chain(this, callback));
+ return chained;
+ }
+
+ /**
* A callback used to chain promises for the {@link #then(Success, Failure)}
* method.
*
@@ -357,16 +427,6 @@ final class PromiseImpl<T> implements Promise<T> {
}
/**
- * {@inheritDoc}
- */
- @Override
- public Promise<T> then(Callback callback) {
- PromiseImpl<T> chained = new PromiseImpl<>();
- onResolve(chained.new Chain(this, callback));
- return chained;
- }
-
- /**
* Resolve this Promise with the specified Promise.
*
* <p>
@@ -386,7 +446,8 @@ final class PromiseImpl<T> implements Promise<T> {
* resolved.
*/
Promise<Void> resolveWith(Promise<? extends T> with) {
- PromiseImpl<Void> chained = new PromiseImpl<>();
+ PromiseImpl<Void> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
with.onResolve(new ResolveWith(with, chained));
return chained;
}
@@ -424,7 +485,8 @@ final class PromiseImpl<T> implements Promise<T> {
*/
@Override
public Promise<T> filter(Predicate<? super T> predicate) {
- PromiseImpl<T> chained = new PromiseImpl<>();
+ PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(chained.new Filter(this, predicate));
return chained;
}
@@ -464,7 +526,8 @@ final class PromiseImpl<T> implements Promise<T> {
*/
@Override
public <R> Promise<R> map(Function<? super T, ? extends R> mapper) {
- PromiseImpl<R> chained = new PromiseImpl<>();
+ PromiseImpl<R> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(chained.new Map<>(this, mapper));
return chained;
}
@@ -504,7 +567,8 @@ final class PromiseImpl<T> implements Promise<T> {
*/
@Override
public <R> Promise<R> flatMap(Function<? super T, Promise<? extends R>> mapper) {
- PromiseImpl<R> chained = new PromiseImpl<>();
+ PromiseImpl<R> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(chained.new FlatMap<>(this, mapper));
return chained;
}
@@ -548,7 +612,8 @@ final class PromiseImpl<T> implements Promise<T> {
*/
@Override
public Promise<T> recover(Function<Promise<?>, ? extends T> recovery) {
- PromiseImpl<T> chained = new PromiseImpl<>();
+ PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(chained.new Recover(this, recovery));
return chained;
}
@@ -591,7 +656,8 @@ final class PromiseImpl<T> implements Promise<T> {
*/
@Override
public Promise<T> recoverWith(Function<Promise<?>, Promise<? extends T>> recovery) {
- PromiseImpl<T> chained = new PromiseImpl<>();
+ PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(chained.new RecoverWith(this, recovery));
return chained;
}
@@ -635,7 +701,8 @@ final class PromiseImpl<T> implements Promise<T> {
*/
@Override
public Promise<T> fallbackTo(Promise<? extends T> fallback) {
- PromiseImpl<T> chained = new PromiseImpl<>();
+ PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(chained.new FallbackTo(this, fallback));
return chained;
}
@@ -666,13 +733,37 @@ final class PromiseImpl<T> implements Promise<T> {
}
/**
+ * Schedule a operation on the scheduled executor.
+ *
+ * @since 1.1
+ */
+ ScheduledFuture< ? > schedule(Runnable operation, long delay,
+ TimeUnit unit) {
+ ScheduledExecutorService executor = scheduledExecutor;
+ if (executor == null) {
+ executor = DefaultExecutors.scheduledExecutor();
+ }
+ try {
+ try {
+ return executor.schedule(operation, delay, unit);
+ } catch (RejectedExecutionException e) {
+ operation.run();
+ }
+ } catch (Throwable t) {
+ uncaughtException(t);
+ }
+ return null;
+ }
+
+ /**
* {@inheritDoc}
*
* @since 1.1
*/
@Override
public Promise<T> timeout(long millis) {
- PromiseImpl<T> chained = new PromiseImpl<>();
+ PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
if (!isDone()) {
onResolve(chained.new Timeout(millis, TimeUnit.MILLISECONDS));
}
@@ -691,7 +782,7 @@ final class PromiseImpl<T> implements Promise<T> {
private final ScheduledFuture< ? > future;
Timeout(long timeout, TimeUnit unit) {
- future = Callbacks.schedule(new TimeoutAction(), timeout, unit);
+ future = schedule(new TimeoutAction(), timeout, unit);
}
@Override
@@ -701,15 +792,16 @@ final class PromiseImpl<T> implements Promise<T> {
}
}
}
-
+
/**
* Callback used to fail the Promise if the timeout expires.
*
* @Immutable
+ * @since 1.1
*/
private final class TimeoutAction implements Runnable {
TimeoutAction() {}
-
+
@Override
public void run() {
tryResolve(null, new TimeoutException());
@@ -723,7 +815,8 @@ final class PromiseImpl<T> implements Promise<T> {
*/
@Override
public Promise<T> delay(long millis) {
- PromiseImpl<T> chained = new PromiseImpl<>();
+ PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
+ scheduledExecutor);
onResolve(new Delay(chained.new Chain(this), millis,
TimeUnit.MILLISECONDS));
return chained;
@@ -736,76 +829,54 @@ final class PromiseImpl<T> implements Promise<T> {
* @Immutable
* @since 1.1
*/
- private static final class Delay implements Runnable {
- private final Runnable callback;
+ private final class Delay implements Runnable {
+ private final Runnable operation;
private final long delay;
private final TimeUnit unit;
- Delay(Runnable callback, long delay, TimeUnit unit) {
- this.callback = callback;
+ Delay(Runnable operation, long delay, TimeUnit unit) {
+ this.operation = operation;
this.delay = delay;
this.unit = unit;
}
@Override
public void run() {
- Callbacks.schedule(callback, delay, unit);
+ schedule(operation, delay, unit);
}
}
/**
- * Callback handler used to asynchronously execute callbacks.
+ * Default executors for callbacks.
*
* @Immutable
* @since 1.1
*/
- private static final class Callbacks
+ private static final class DefaultExecutors
implements ThreadFactory, RejectedExecutionHandler, Runnable {
- private static final Callbacks callbacks;
+ private static final DefaultExecutors callbacks;
private static final ScheduledExecutor scheduledExecutor;
private static final ThreadPoolExecutor callbackExecutor;
static {
- callbacks = new Callbacks();
+ callbacks = new DefaultExecutors();
scheduledExecutor = new ScheduledExecutor(2, callbacks);
callbackExecutor = new ThreadPoolExecutor(0, 64, 60L,
TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
callbacks, callbacks);
}
- /**
- * Schedule a callback on the scheduled executor
- */
- static ScheduledFuture< ? > schedule(Runnable callback, long delay,
- TimeUnit unit) {
- try {
- return scheduledExecutor.schedule(callback, delay, unit);
- } catch (RejectedExecutionException e) {
- callbacks.rejectedExecution(callback, scheduledExecutor);
- return null;
- }
+ static Executor callbackExecutor() {
+ return callbackExecutor;
}
- /**
- * Execute a callback on the callback executor
- */
- static void execute(Runnable callback) {
- callbackExecutor.execute(callback);
- }
-
- static void uncaughtException(Throwable t) {
- try {
- Thread thread = Thread.currentThread();
- thread.getUncaughtExceptionHandler().uncaughtException(thread,
- t);
- } catch (Throwable ignored) {
- // we ignore this
- }
+ static ScheduledExecutorService scheduledExecutor() {
+ return scheduledExecutor;
}
private final AtomicBoolean shutdownHookInstalled;
private final ThreadFactory delegateThreadFactory;
- private Callbacks() {
+ private DefaultExecutors() {
shutdownHookInstalled = new AtomicBoolean();
delegateThreadFactory = Executors.defaultThreadFactory();
}
@@ -929,13 +1000,14 @@ final class PromiseImpl<T> implements Promise<T> {
* A holder of the result of a promise.
*
* @NotThreadSafe
+ * @since 1.1
*/
static final class Result<P> {
Throwable fail;
P value;
-
+
Result() {}
-
+
static <R> Result<R> collect(Promise< ? extends R> promise) {
Result<R> result = new Result<>();
final boolean interrupted = Thread.interrupted();
@@ -954,11 +1026,4 @@ final class PromiseImpl<T> implements Promise<T> {
return result;
}
}
-
- static <V> V requireNonNull(V value) {
- if (value != null) {
- return value;
- }
- throw new NullPointerException();
- }
}
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Promises.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Promises.java
index 7067fe50a..394bce4bb 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Promises.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/promise/Promises.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2014, 2016). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2014, 2017). 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.
@@ -16,7 +16,7 @@
package org.osgi.util.promise;
-import static org.osgi.util.promise.PromiseImpl.requireNonNull;
+import static java.util.Objects.requireNonNull;
import java.util.ArrayList;
import java.util.Arrays;
@@ -38,43 +38,42 @@ public class Promises {
}
/**
- * Create a new Promise that has been resolved with the specified value.
+ * Returns a new Promise that has been resolved with the specified value.
*
* @param <T> The value type associated with the returned Promise.
* @param value The value of the resolved Promise.
* @return A new Promise that has been resolved with the specified value.
*/
public static <T> Promise<T> resolved(T value) {
- return new PromiseImpl<>(value, null);
+ return new PromiseImpl<>(value, null, null, null);
}
/**
- * Create a new Promise that has been resolved with the specified failure.
+ * Returns a new Promise that has been resolved with the specified failure.
*
* @param <T> The value type associated with the returned Promise.
* @param failure The failure of the resolved Promise. Must not be
- * {@code null}.
+ * {@code null}.
* @return A new Promise that has been resolved with the specified failure.
*/
public static <T> Promise<T> failed(Throwable failure) {
- return new PromiseImpl<>(null, requireNonNull(failure));
+ return new PromiseImpl<>(null, requireNonNull(failure), null, null);
}
/**
- * Create a new Promise that is a latch on the resolution of the specified
+ * Returns a new Promise that is a latch on the resolution of the specified
* Promises.
- *
* <p>
- * The new Promise acts as a gate and must be resolved after all of the
+ * The returned Promise acts as a gate and must be resolved after all of the
* specified Promises are resolved.
*
* @param <T> The value type of the List value associated with the returned
- * Promise.
+ * Promise.
* @param <S> A subtype of the value type of the List value associated with
- * the returned Promise.
+ * the returned Promise.
* @param promises The Promises which must be resolved before the returned
- * Promise must be resolved. Must not be {@code null} and all of the
- * elements in the collection must not be {@code null}.
+ * Promise must be resolved. Must not be {@code null} and all of
+ * the elements in the collection must not be {@code null}.
* @return A Promise that is resolved only when all the specified Promises
* are resolved. The returned Promise must be successfully resolved
* with a List of the values in the order of the specified Promises
@@ -87,33 +86,67 @@ public class Promises {
* Promises which resolved with a failure.
*/
public static <T, S extends T> Promise<List<T>> all(Collection<Promise<S>> promises) {
+ return all(new Deferred<List<T>>(), promises);
+ }
+
+ /**
+ * Resolves the Promise returned by the specified Deferred when the
+ * specified Promises are all resolved.
+ * <p>
+ * The returned Promise acts as a gate and must be resolved after all of the
+ * specified Promises are resolved.
+ *
+ * @param <T> The value type of the List value associated with the returned
+ * Promise.
+ * @param <S> A subtype of the value type of the List value associated with
+ * the returned Promise.
+ * @param deferred The specified Deferred is used to obtain and resolve the
+ * returned Promise. Must not be {@code null} and must not have
+ * already resolved the returned Promise.
+ * @param promises The Promises which must be resolved before the returned
+ * Promise must be resolved. Must not be {@code null} and all of
+ * the elements in the collection must not be {@code null}.
+ * @return The Promise from the specified Deferred. It is resolved only when
+ * all the specified Promises are resolved. The returned Promise
+ * must be successfully resolved with a List of the values in the
+ * order of the specified Promises if all the specified Promises are
+ * successfully resolved. The List in the returned Promise is the
+ * property of the caller and is modifiable. The returned Promise
+ * must be resolved with a failure of
+ * {@link FailedPromisesException} if any of the specified Promises
+ * are resolved with a failure. The failure
+ * {@link FailedPromisesException} must contain all of the specified
+ * Promises which resolved with a failure.
+ * @since 1.1
+ */
+ public static <T, S extends T> Promise<List<T>> all(
+ Deferred<List<T>> deferred, Collection<Promise<S>> promises) {
if (promises.isEmpty()) {
List<T> result = new ArrayList<>();
- return resolved(result);
- }
- /* make a copy and capture the ordering */
- List<Promise< ? extends T>> list = new ArrayList<Promise< ? extends T>>(
- promises);
- PromiseImpl<List<T>> chained = new PromiseImpl<>();
- All<T> all = new All<>(chained, list);
- for (Promise<? extends T> promise : list) {
- promise.onResolve(all);
+ deferred.resolve(result);
+ } else {
+ /* make a copy and capture the ordering */
+ List<Promise< ? extends T>> list = new ArrayList<Promise< ? extends T>>(
+ promises);
+ All<T> all = new All<>(deferred, list);
+ for (Promise< ? extends T> promise : list) {
+ promise.onResolve(all);
+ }
}
- return chained;
+ return deferred.getPromise();
}
/**
- * Create a new Promise that is a latch on the resolution of the specified
+ * Returns a new Promise that is a latch on the resolution of the specified
* Promises.
- *
* <p>
* The new Promise acts as a gate and must be resolved after all of the
* specified Promises are resolved.
*
* @param <T> The value type associated with the specified Promises.
* @param promises The Promises which must be resolved before the returned
- * Promise must be resolved. Must not be {@code null} and all of the
- * arguments must not be {@code null}.
+ * Promise must be resolved. Must not be {@code null} and all of
+ * the arguments must not be {@code null}.
* @return A Promise that is resolved only when all the specified Promises
* are resolved. The returned Promise must be successfully resolved
* with a List of the values in the order of the specified Promises
@@ -133,17 +166,55 @@ public class Promises {
}
/**
- * A callback used to resolve a Promise when the specified list of Promises
+ * Resolves the Promise returned by the specified Deferred when the
+ * specified Promises are all resolved.
+ * <p>
+ * The new Promise acts as a gate and must be resolved after all of the
+ * specified Promises are resolved.
+ *
+ * @param <T> The value type associated with the specified Promises.
+ * @param deferred The specified Deferred is used to obtain and resolve the
+ * returned Promise. Must not be {@code null} and must not have
+ * already resolved the returned Promise.
+ * @param promises The Promises which must be resolved before the returned
+ * Promise must be resolved. Must not be {@code null} and all of
+ * the arguments must not be {@code null}.
+ * @return The Promise from the specified Deferred. It is resolved only when
+ * all the specified Promises are resolved. The returned Promise
+ * must be successfully resolved with a List of the values in the
+ * order of the specified Promises if all the specified Promises are
+ * successfully resolved. The List in the returned Promise is the
+ * property of the caller and is modifiable. The returned Promise
+ * must be resolved with a failure of
+ * {@link FailedPromisesException} if any of the specified Promises
+ * are resolved with a failure. The failure
+ * {@link FailedPromisesException} must contain all of the specified
+ * Promises which resolved with a failure.
+ * @since 1.1
+ */
+ @SafeVarargs
+ public static <T> Promise<List<T>> all(Deferred<List<T>> deferred,
+ Promise< ? extends T>... promises) {
+ @SuppressWarnings("unchecked")
+ List<Promise<T>> list = Arrays.asList((Promise<T>[]) promises);
+ return all(deferred, list);
+ }
+
+ /**
+ * A callback used to resolve a Deferred when the specified list of Promises
* are resolved for the {@link Promises#all(Collection)} method.
*
* @ThreadSafe
*/
private static final class All<T> implements Runnable {
- private final PromiseImpl<List<T>> chained;
+ private final Deferred<List<T>> chained;
private final List<Promise<? extends T>> promises;
private final AtomicInteger promiseCount;
- All(PromiseImpl<List<T>> chained, List<Promise<? extends T>> promises) {
+ All(Deferred<List<T>> chained, List<Promise< ? extends T>> promises) {
+ if (chained.getPromise().isDone()) {
+ throw new IllegalStateException("Already resolved");
+ }
this.chained = chained;
this.promises = promises;
this.promiseCount = new AtomicInteger(promises.size());
@@ -169,10 +240,9 @@ public class Promises {
}
}
if (failed.isEmpty()) {
- chained.tryResolve(value, null);
+ chained.resolve(value);
} else {
- chained.tryResolve(null,
- new FailedPromisesException(failed, cause));
+ chained.fail(new FailedPromisesException(failed, cause));
}
}
}
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/XMLParserActivator.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/XMLParserActivator.java
index c73b3c061..64be3f5cf 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/XMLParserActivator.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/XMLParserActivator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2002, 2013). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2002, 2015). 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.
@@ -91,9 +91,9 @@ import org.osgi.framework.ServiceRegistration;
* @ThreadSafe
* @author $Id$
*/
-public class XMLParserActivator implements BundleActivator, ServiceFactory {
+public class XMLParserActivator implements BundleActivator, ServiceFactory<Object> {
/** Context of this bundle */
- private volatile BundleContext context;
+ private volatile BundleContext bundleContext;
/**
* Filename containing the SAX Parser Factory Class name. Also used as the
* basis for the {@code SERVICE_PID} registration property.
@@ -150,8 +150,9 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* bundle's listeners, unregister all services registered by this
* bundle, and release all services used by this bundle.
*/
+ @Override
public void start(BundleContext context) throws Exception {
- this.context = context;
+ this.bundleContext = context;
Bundle parserBundle = context.getBundle();
// check for sax parsers
registerSAXParsers(getParserFactoryClassNames(parserBundle.getResource(SAXCLASSFILE)));
@@ -169,6 +170,7 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* the bundle's listeners, unregister all services registered by the
* bundle, and release all services used by the bundle.
*/
+ @Override
public void stop(BundleContext context) throws Exception {
// framework will automatically unregister the parser services
}
@@ -183,11 +185,11 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* @return A List of strings containing the parser class names.
* @throws IOException if there is a problem reading the URL input stream
*/
- private List getParserFactoryClassNames(URL parserUrl) throws IOException {
+ private List<String> getParserFactoryClassNames(URL parserUrl) throws IOException {
if (parserUrl == null) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
- List v = new ArrayList(1);
+ List<String> v = new ArrayList<String>(1);
String parserFactoryClassName = null;
InputStream is = parserUrl.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
@@ -220,17 +222,17 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* containing the names of the parser Factory Classes
* @throws FactoryConfigurationError if thrown from {@code getFactory}
*/
- private void registerSAXParsers(List parserFactoryClassNames) throws FactoryConfigurationError {
- Iterator e = parserFactoryClassNames.iterator();
+ private void registerSAXParsers(List<String> parserFactoryClassNames) throws FactoryConfigurationError {
+ Iterator<String> e = parserFactoryClassNames.iterator();
int index = 0;
while (e.hasNext()) {
- String parserFactoryClassName = (String) e.next();
+ String parserFactoryClassName = e.next();
// create a sax parser factory just to get it's default
// properties. It will never be used since
// this class will operate as a service factory and give each
// service requestor it's own SaxParserFactory
SAXParserFactory factory = (SAXParserFactory) getFactory(parserFactoryClassName);
- Hashtable properties = new Hashtable(7);
+ Hashtable<String, Object> properties = new Hashtable<String, Object>(7);
// figure out the default properties of the parser
setDefaultSAXProperties(factory, properties, index);
// store the parser factory class name in the properties so that
@@ -238,7 +240,7 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
// to return a parser factory
properties.put(FACTORYNAMEKEY, parserFactoryClassName);
// register the factory as a service
- context.registerService(SAXFACTORYNAME, this, properties);
+ bundleContext.registerService(SAXFACTORYNAME, this, properties);
index++;
}
}
@@ -259,9 +261,9 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* @param factory The {@code SAXParserFactory} object
* @param props {@code Hashtable} of service properties.
*/
- private void setDefaultSAXProperties(SAXParserFactory factory, Hashtable props, int index) {
+ private void setDefaultSAXProperties(SAXParserFactory factory, Hashtable<String, Object> props, int index) {
props.put(Constants.SERVICE_DESCRIPTION, SAXFACTORYDESCRIPTION);
- props.put(Constants.SERVICE_PID, SAXFACTORYNAME + "." + context.getBundle().getBundleId() + "." + index);
+ props.put(Constants.SERVICE_PID, SAXFACTORYNAME + "." + bundleContext.getBundle().getBundleId() + "." + index);
setSAXProperties(factory, props);
}
@@ -285,7 +287,7 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* @param factory - the SAXParserFactory object
* @param properties - the properties object for the service
*/
- public void setSAXProperties(SAXParserFactory factory, Hashtable properties) {
+ public void setSAXProperties(SAXParserFactory factory, Hashtable<String, Object> properties) {
// check if this parser can be configured to validate
boolean validating = true;
factory.setValidating(true);
@@ -308,8 +310,8 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
factory.setValidating(validating);
factory.setNamespaceAware(namespaceaware);
// set the OSGi service properties
- properties.put(PARSER_NAMESPACEAWARE, new Boolean(namespaceaware));
- properties.put(PARSER_VALIDATING, new Boolean(validating));
+ properties.put(PARSER_NAMESPACEAWARE, Boolean.valueOf(namespaceaware));
+ properties.put(PARSER_VALIDATING, Boolean.valueOf(validating));
}
/**
@@ -319,17 +321,17 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* containing the names of the parser Factory Classes
* @throws FactoryConfigurationError if thrown from {@code getFactory}
*/
- private void registerDOMParsers(List parserFactoryClassNames) throws FactoryConfigurationError {
- Iterator e = parserFactoryClassNames.iterator();
+ private void registerDOMParsers(List<String> parserFactoryClassNames) throws FactoryConfigurationError {
+ Iterator<String> e = parserFactoryClassNames.iterator();
int index = 0;
while (e.hasNext()) {
- String parserFactoryClassName = (String) e.next();
+ String parserFactoryClassName = e.next();
// create a dom parser factory just to get it's default
// properties. It will never be used since
// this class will operate as a service factory and give each
// service requestor it's own DocumentBuilderFactory
DocumentBuilderFactory factory = (DocumentBuilderFactory) getFactory(parserFactoryClassName);
- Hashtable properties = new Hashtable(7);
+ Hashtable<String, Object> properties = new Hashtable<String, Object>(7);
// figure out the default properties of the parser
setDefaultDOMProperties(factory, properties, index);
// store the parser factory class name in the properties so that
@@ -337,7 +339,7 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
// to return a parser factory
properties.put(FACTORYNAMEKEY, parserFactoryClassName);
// register the factory as a service
- context.registerService(DOMFACTORYNAME, this, properties);
+ bundleContext.registerService(DOMFACTORYNAME, this, properties);
index++;
}
}
@@ -356,9 +358,9 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* @param factory The {@code DocumentBuilderFactory} object
* @param props {@code Hashtable} of service properties.
*/
- private void setDefaultDOMProperties(DocumentBuilderFactory factory, Hashtable props, int index) {
+ private void setDefaultDOMProperties(DocumentBuilderFactory factory, Hashtable<String, Object> props, int index) {
props.put(Constants.SERVICE_DESCRIPTION, DOMFACTORYDESCRIPTION);
- props.put(Constants.SERVICE_PID, DOMFACTORYNAME + "." + context.getBundle().getBundleId() + "." + index);
+ props.put(Constants.SERVICE_PID, DOMFACTORYNAME + "." + bundleContext.getBundle().getBundleId() + "." + index);
setDOMProperties(factory, props);
}
@@ -382,7 +384,7 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* @param factory - the DocumentBuilderFactory object
* @param props - Hashtable of service properties.
*/
- public void setDOMProperties(DocumentBuilderFactory factory, Hashtable props) {
+ public void setDOMProperties(DocumentBuilderFactory factory, Hashtable<String, Object> props) {
// check if this parser can be configured to validate
boolean validating = true;
factory.setValidating(true);
@@ -405,8 +407,8 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
factory.setValidating(validating);
factory.setNamespaceAware(namespaceaware);
// set the OSGi service properties
- props.put(PARSER_VALIDATING, new Boolean(validating));
- props.put(PARSER_NAMESPACEAWARE, new Boolean(namespaceaware));
+ props.put(PARSER_VALIDATING, Boolean.valueOf(validating));
+ props.put(PARSER_NAMESPACEAWARE, Boolean.valueOf(namespaceaware));
}
/**
@@ -419,7 +421,7 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
*/
private Object getFactory(String parserFactoryClassName) throws FactoryConfigurationError {
try {
- return context.getBundle().loadClass(parserFactoryClassName).newInstance();
+ return bundleContext.getBundle().loadClass(parserFactoryClassName).newInstance();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
@@ -448,8 +450,9 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* @return A new, configured XML Parser Factory object or null if a
* configuration error was encountered
*/
- public Object getService(Bundle bundle, ServiceRegistration registration) {
- ServiceReference sref = registration.getReference();
+ @Override
+ public Object getService(Bundle bundle, ServiceRegistration<Object> registration) {
+ ServiceReference<Object> sref = registration.getReference();
String parserFactoryClassName = (String) sref.getProperty(FACTORYNAMEKEY);
// need to set factory properties
Object factory = getFactory(parserFactoryClassName);
@@ -474,6 +477,8 @@ public class XMLParserActivator implements BundleActivator, ServiceFactory {
* @param service The XML Parser Factory object returned by a previous call
* to the {@code getService} method.
*/
- public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+ @Override
+ public void ungetService(Bundle bundle, ServiceRegistration<Object> registration, Object service) {
+ // nothing to do
}
}
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/package-info.java b/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/package-info.java
index 8d3c57bb5..1f05ed780 100644
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/package-info.java
+++ b/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2010, 2013). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2010, 2016). 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.
@@ -26,9 +26,10 @@
* <p>
* {@code Import-Package: org.osgi.util.xml; version="[1.0,2.0)"}
*
- * @version 1.0.1
* @author $Id$
*/
+@Version("1.0.1")
package org.osgi.util.xml;
+import org.osgi.annotation.versioning.Version;
diff --git a/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/packageinfo b/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/packageinfo
deleted file mode 100644
index c2664475c..000000000
--- a/bundles/org.eclipse.osgi.util/src/org/osgi/util/xml/packageinfo
+++ /dev/null
@@ -1 +0,0 @@
-version 1.0.1 \ No newline at end of file

Back to the top