com.github.davidmoten.rx.SingleSubscribeSubject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava-jdbc Show documentation
Show all versions of rxjava-jdbc Show documentation
rx-java Observables for jdbc
package com.github.davidmoten.rx;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
public final class SingleSubscribeSubject extends Observable implements
Observer {
//Visible for testing
static final String ONLY_ONE_SUBSCRIPTION_IS_ALLOWED = "only one subscription is allowed";
private final SingleSubscribeOnSubscribe subscriberHolder;
private SingleSubscribeSubject(SingleSubscribeOnSubscribe onSubscribe) {
super(onSubscribe);
subscriberHolder = onSubscribe;
}
private SingleSubscribeSubject() {
this(new SingleSubscribeOnSubscribe());
}
public static SingleSubscribeSubject create(){
return new SingleSubscribeSubject();
}
@Override
public void onCompleted() {
if (subscriberHolder.subscriber != null) {
subscriberHolder.subscriber.onCompleted();
}
}
@Override
public void onError(Throwable e) {
if (subscriberHolder.subscriber != null)
subscriberHolder.subscriber.onError(e);
}
@Override
public void onNext(T t) {
if (subscriberHolder.subscriber != null)
subscriberHolder.subscriber.onNext(t);
}
private static class SingleSubscribeOnSubscribe implements
OnSubscribe {
volatile Subscriber super T> subscriber;
@Override
public void call(Subscriber super T> subscriber) {
if (this.subscriber != null)
throw new RuntimeException(ONLY_ONE_SUBSCRIPTION_IS_ALLOWED);
this.subscriber = subscriber;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy