ReactiveX / RxJavaReactiveStreams

Adapter between RxJava and ReactiveStreams

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OSGi Split Packages

fakeh opened this issue · comments

commented

Hi! And firstly, thanks for this project, really helpful being able to design for future standards.
Also, I really appreciate that you ship your bundles with OSGi headers, it makes it much easier to use in these environments!

The RxReactiveStreams class is in package rx, but unfortunately this causes a split package between this bundle and the main RxJava distribution. http://wiki.osgi.org/wiki/Split_Packages. This means the bundle doesn't resolve:

Error executing command: Uses constraint violation. Unable to resolve resource io.reactivex.rxjava-reactive-streams [io.reactivex.rxjava-reactive-streams/1.0.1] because it exports package 'rx' and is also exposed to it from resource io.reactivex.rxjava [io.reactivex.rxjava/1.0.14] via the following dependency chain:

  io.reactivex.rxjava-reactive-streams [io.reactivex.rxjava-reactive-streams/1.0.1]
    import: (&(osgi.wiring.package=rx.internal.operators)(version>=1.0.0)(!(version>=2.0.0)))
     |
    export: osgi.wiring.package: rx.internal.operators; uses:=rx
    export: osgi.wiring.package=rx
  io.reactivex.rxjava [io.reactivex.rxjava/1.0.14]

Thanks, Dan.

Unfortunately, we can't change the package naming for the 1.x version.

I'm closing this issue due to inactivity. If you have further input on the issue, don't hesitate to reopen this issue or post a new one.

Is there any workaround for this?

I don't know about any workaround.

commented

a) upgrade to v2!
b) Most classes are fine, because they're in rx.internal. I used BND with a configuration like:

Export-Package: utility.rx.*
Private-Package: rx.internal.reactivestreams.*

And have a utility.rx.Reactives class which has the static helpers:

package utility.rx;

import org.reactivestreams.Publisher;

import rx.Observable;
import rx.internal.reactivestreams.PublisherAdapter;
import rx.internal.reactivestreams.SubscriberAdapter;

public class Reactives {
	private Reactives() {}
	
    /**
     * Convert a Rx {@link Observable} into a Reactive Streams {@link Publisher}.
     * <p/>
     * Use this method when you have an RxJava observable, that you want to be consumed by another library.
     *
     * @param observable the {@link Observable} to convert
     * @return the converted {@link Publisher}
     */
    public static <T> Publisher<T> toPublisher(Observable<T> observable) {
        return new PublisherAdapter<T>(observable);
    }

    /**
     * Convert a Reactive Streams {@link Publisher} into a Rx {@link Observable}.
     * <p/>
     * Use this method when you have a stream from another library, that you want to be consume as an RxJava observable.
     *
     * @param publisher the {@link Publisher} to convert.
     * @return the converted {@link Observable}
     */
    public static <T> Observable<T> toObservable(final Publisher<T> publisher) {
        return Observable.create(new Observable.OnSubscribe<T>() {
            @Override
            public void call(final rx.Subscriber<? super T> rxSubscriber) {
                publisher.subscribe(toSubscriber(rxSubscriber));
            }
        });
    }

    /**
     * Convert an RxJava {@link rx.Subscriber} into a Reactive Streams {@link org.reactivestreams.Subscriber}.
     *
     * @param rxSubscriber an RxJava subscriber
     * @return a Reactive Streams subscriber
     */
    public static <T> org.reactivestreams.Subscriber<T> toSubscriber(final rx.Subscriber<T> rxSubscriber) {
        return new SubscriberAdapter<T>(rxSubscriber);
    }
}