@Override public void call(Subscriber<? super Response<T>> subscriber) { // Since Call is a one-shot type, clone it for each new subscriber. Call<T> call = originalCall.clone(); final CallArbiter<T> arbiter = new CallArbiter<>(call, subscriber); subscriber.add(arbiter); subscriber.setProducer(arbiter); call.enqueue(new Callback<T>() { @Override public void onResponse(Call<T> call, Response<T> response) { arbiter.emitResponse(response); } @Override public void onFailure(Call<T> call, Throwable t) { Exceptions.throwIfFatal(t); arbiter.emitError(t); } }); } }
@Override protected void onNewReadSubscriber(Subscriber<? super R> subscriber) { // Unsubscribe from the input closes the connection as there can only be one subscriber to the // input and, if nothing is read, it means, nobody is using the connection. // For fire-and-forget usecases, one should explicitly ignore content on the connection which // adds a discard all subscriber that never unsubscribes. For this case, then, the close becomes // explicit. subscriber.add(Subscriptions.create(new ExecuteInEventloopAction(channel) { @Override public void run() { if (!connectionInputSubscriberExists(channel)) { Connection<?, ?> connection = channel.attr(Connection.CONNECTION_ATTRIBUTE_KEY).get(); if (null != connection) { connection.closeNow(); } } } })); }
/** * Bridges the passed subscriber and future, which means the following: * * <ul> <li>Add this listener to the passed future.</li> <li>Add a callback to the subscriber, such that on unsubscribe this listener is removed from the future.</li> </ul> * * @param future Future to bridge. * @param subscriber Subscriber to connect to the future. */ public void bridge(final ChannelFuture future, Subscriber<?> subscriber) { future.addListener(this); subscriber.add(Subscriptions.create(new Action0() { @Override public void call() { future.removeListener(SubscriberToChannelFutureBridge.this); } })); } }
@Override public void call(Subscriber<? super T> subscriber) { switch (request.getRequestType()) { case RequestType.SIMPLE: ANResolver<T> anResolver = new ANResolver<>(request, subscriber); subscriber.add(anResolver); subscriber.setProducer(anResolver); break; case RequestType.DOWNLOAD: DownloadANResolver<T> downloadANResolver = new DownloadANResolver<>(request, subscriber); subscriber.add(downloadANResolver); subscriber.setProducer(downloadANResolver); break; case RequestType.MULTIPART: MultipartANResolver<T> multipartANResolver = new MultipartANResolver<>(request, subscriber); subscriber.add(multipartANResolver); subscriber.setProducer(multipartANResolver); break; } } }
@Override public void call(Subscriber<? super Response<T>> subscriber) { // Since Call is a one-shot type, clone it for each new subscriber. Call<T> call = originalCall.clone(); CallArbiter<T> arbiter = new CallArbiter<>(call, subscriber); subscriber.add(arbiter); subscriber.setProducer(arbiter); Response<T> response; try { response = call.execute(); } catch (Throwable t) { Exceptions.throwIfFatal(t); arbiter.emitError(t); return; } arbiter.emitResponse(response); } }
subscriber.add(Subscriptions.create(new Action0() { @Override public void call() {
@Override public void call( final Subscriber<? super T> outerOperation ) { CompositeSubscription csub = new CompositeSubscription(); //when a subscription is received, we need to subscribe on each observable SubscriberCoordinator coordinator = new SubscriberCoordinator( comparator, outerOperation, observables.length ); InnerObserver<T>[] innerObservers = new InnerObserver[observables.length]; //we have to do this in 2 steps to get the synchronization correct. We must set up our total inner observers //before starting subscriptions otherwise our assertions for completion or starting won't work properly for ( int i = 0; i < observables.length; i++ ) { //subscribe to each one and add it to the composite //create a new inner and subscribe final InnerObserver<T> inner = new InnerObserver<T>( coordinator, maxBufferSize, i ); coordinator.add( inner ); innerObservers[i] = inner; } /** * Once we're set up, begin the subscription to sub observables */ for ( int i = 0; i < observables.length; i++ ) { //subscribe after setting them up //add our subscription to the composite for future cancellation Subscription subscription = observables[i].subscribe( innerObservers[i] ); csub.add( subscription ); //add the internal composite subscription outerOperation.add( csub ); } }
subscriber.add(arbiter); subscriber.setProducer(arbiter);
subscriber.add(Subscriptions.create(new Action0() { @Override public void call() {
final CompositeSubscription s = new CompositeSubscription(); child.add(s);
@Override public void call(Subscriber<? super Response<T>> subscriber) { // Since Call is a one-shot type, clone it for each new subscriber. Call<T> call = originalCall.clone(); CallArbiter<T> arbiter = new CallArbiter<>(call, subscriber); subscriber.add(arbiter); subscriber.setProducer(arbiter); Response<T> response; try { response = call.execute(); } catch (Throwable t) { Exceptions.throwIfFatal(t); arbiter.emitError(t); return; } arbiter.emitNext(response); arbiter.emitComplete(); } }
private static <T> void setupUnsubscription(Subscriber<T> subscriber, final State state) { subscriber.add(Subscriptions.create(new Action0() { @Override public void call() { closeQuietly(state); } })); }
@Override public void call(rx.Subscriber<? super T> t) { hu.akarnokd.rxjava.interop.FlowableV2ToObservableV1.SourceSubscriber<T> parent = new hu.akarnokd.rxjava.interop.FlowableV2ToObservableV1.SourceSubscriber<T>(t); t.add(parent); t.setProducer(parent); processor.subscribe(parent); }
@Override public void call(rx.Subscriber<? super T> t) { SourceObserver<T> parent = new SourceObserver<T>(t); t.add(parent); t.setProducer(parent); subject.subscribe(parent); }
@Override public void call(rx.Subscriber<? super T> t) { SourceSubscriber<T> parent = new SourceSubscriber<T>(t); t.add(parent); t.setProducer(parent); source.subscribe(parent); }
@Override public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) { if (!subscriber.isUnsubscribed()) { FutureTask<Bitmap> futureTask = new FutureTask<>(PaintBlurOnSubscribe.this.futureRunnable(bitmap, subscriber), null); ioExecutor.execute(futureTask); subscriber.add(Subscriptions.from(futureTask)); } }
@Override public void call(Subscriber<? super T> subscriber) { final State state = new State(); try { if (isBeginTransaction()) performBeginTransaction(subscriber); else { query.context().setupBatching(); getConnection(state); subscriber.add(createUnsubscriptionAction(state)); if (isCommit()) performCommit(subscriber, state); else if (isRollback()) performRollback(subscriber, state); else performUpdate(subscriber, state); } } catch (Throwable e) { query.context().endTransactionObserve(); query.context().endTransactionSubscribe(); try { close(state); } finally { handleException(e, subscriber); } } }
@Override public void call(Subscriber<? super T> child) { final MapLastSubscriber<T> parent = new MapLastSubscriber<T>(child, function); child.add(parent); child.setProducer(new Producer() { @Override public void request(long n) { parent.requestMore(n); } }); source.unsafeSubscribe(parent); }
@Override public Subscriber<? super T> call(Subscriber<? super R> subscriber) { final ParentSubscriber<T> parent = new ParentSubscriber<T>(); Observable<T> middle = Observable.create(new ForwarderOnSubscribe<T>(parent)); subscriber.add(parent); operation.call(middle).unsafeSubscribe(subscriber); return parent; }