diff --git a/src/main/java/rx/plugins/RxJavaPlugins.java b/src/main/java/rx/plugins/RxJavaPlugins.java index 2e48305989..09e542779d 100644 --- a/src/main/java/rx/plugins/RxJavaPlugins.java +++ b/src/main/java/rx/plugins/RxJavaPlugins.java @@ -15,6 +15,7 @@ */ package rx.plugins; +import java.util.*; import java.util.concurrent.atomic.AtomicReference; /** @@ -26,7 +27,22 @@ * property names) *
In addition to the {@code rxjava.plugin.[simple classname].implementation} system properties,
+ * you can define two system property:
+ *
+ * rxjava.plugin.[index].class}
+ * rxjava.plugin.[index].impl}
+ *
+ *
+ * Where the {@code .class} property contains the simple classname from above and the {@code .impl}
+ * contains the fully qualified name of the implementation class. The {@code [index]} can be
+ * any short string or number of your chosing. For example, you can now define a custom
+ * {@code RxJavaErrorHandler} via two system property:
+ *
+ * rxjava.plugin.1.class=RxJavaErrorHandler
+ * rxjava.plugin.1.impl=some.package.MyRxJavaErrorHandler
+ *
+ *
* @see RxJava Wiki: Plugins
*/
public class RxJavaPlugins {
@@ -64,13 +80,12 @@ public static RxJavaPlugins getInstance() {
* * Override the default by calling {@link #registerErrorHandler(RxJavaErrorHandler)} or by setting the * property {@code rxjava.plugin.RxJavaErrorHandler.implementation} with the full classname to load. - * * @return {@link RxJavaErrorHandler} implementation to use */ public RxJavaErrorHandler getErrorHandler() { if (errorHandler.get() == null) { // check for an implementation from System.getProperty first - Object impl = getPluginImplementationViaProperty(RxJavaErrorHandler.class); + Object impl = getPluginImplementationViaProperty(RxJavaErrorHandler.class, System.getProperties()); if (impl == null) { // nothing set via properties so initialize with default errorHandler.compareAndSet(null, DEFAULT_ERROR_HANDLER); @@ -112,7 +127,7 @@ public void registerErrorHandler(RxJavaErrorHandler impl) { public RxJavaObservableExecutionHook getObservableExecutionHook() { if (observableExecutionHook.get() == null) { // check for an implementation from System.getProperty first - Object impl = getPluginImplementationViaProperty(RxJavaObservableExecutionHook.class); + Object impl = getPluginImplementationViaProperty(RxJavaObservableExecutionHook.class, System.getProperties()); if (impl == null) { // nothing set via properties so initialize with default observableExecutionHook.compareAndSet(null, RxJavaObservableExecutionHookDefault.getInstance()); @@ -141,15 +156,46 @@ public void registerObservableExecutionHook(RxJavaObservableExecutionHook impl) } } - private static Object getPluginImplementationViaProperty(Class> pluginClass) { - String classSimpleName = pluginClass.getSimpleName(); + /* test */ static Object getPluginImplementationViaProperty(Class> pluginClass, Properties props) { + final String classSimpleName = pluginClass.getSimpleName(); /* * Check system properties for plugin class. *
* This will only happen during system startup thus it's okay to use the synchronized * System.getProperties as it will never get called in normal operations. */ - String implementingClass = System.getProperty("rxjava.plugin." + classSimpleName + ".implementation"); + + final String pluginPrefix = "rxjava.plugin."; + + String defaultKey = pluginPrefix + classSimpleName + ".implementation"; + String implementingClass = props.getProperty(defaultKey); + + if (implementingClass == null) { + final String classSuffix = ".class"; + final String implSuffix = ".impl"; + + for (Map.Entry