當前位置: 首頁>>代碼示例>>Java>>正文


Java Subscription類代碼示例

本文整理匯總了Java中org.reactivestreams.Subscription的典型用法代碼示例。如果您正苦於以下問題:Java Subscription類的具體用法?Java Subscription怎麽用?Java Subscription使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Subscription類屬於org.reactivestreams包,在下文中一共展示了Subscription類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: subscribe

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Override
public void subscribe(Subscriber<? super E> s) {
	subscriber = s;
	s.onSubscribe(new Subscription() {
		@Override
		public void request(long n) {
			try {
				E event = dispatcher.waitFor(clazz, n);
				subscriber.onNext(event);
			} catch (InterruptedException e) {
				if (subscriber != null)
					subscriber.onError(e);
			}
		}
		
		@Override
		public void cancel() {
			dispatcher.unregisterListener(this);
		}
	});
}
 
開發者ID:Discord4J-Addons,項目名稱:D4J-Rx,代碼行數:22,代碼來源:IEventAdapter.java

示例2: cancelUpfront

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Test
public void cancelUpfront() {

    final BlockingFirstSubscriber<Integer> bf = new BlockingFirstSubscriber<Integer>();

    final AtomicBoolean b = new AtomicBoolean();

    bf.cancelled = true;

    Subscription s = new Subscription() {
        @Override
        public void request(long n) {
            b.set(true);
        }
        @Override
        public void cancel() {
        }
    };

    bf.onSubscribe(s);

    assertFalse(b.get());
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:24,代碼來源:BlockingSubscriberTest.java

示例3: fetchArticles

import org.reactivestreams.Subscription; //導入依賴的package包/類
public void fetchArticles(){
    mIacticleModel.requestData(new Subscriber<ActicleBean>() {
        @Override
        public void onSubscribe(Subscription s) {
            s.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(ActicleBean acticleBean) {
            mActicleInterface.showData(acticleBean);
        }

        @Override
        public void onError(Throwable t) {
            Log.e("ArticlePresenter",t.getMessage());
        }

        @Override
        public void onComplete() {
            mActicleInterface.hideLoading();
        }
    });

}
 
開發者ID:AnnyBaby,項目名稱:Mvp-Retrofit-Rxjava-Rxbus,代碼行數:25,代碼來源:ArticlePresenter.java

示例4: testTimedFirstNames

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Test
public void testTimedFirstNames(){
	employeeBatchStreamServiceImpl.getTimedFirstNames().subscribe(new Subscriber<String>(){

		@Override
		public void onComplete() {	}

		@Override
		public void onError(Throwable arg0) {
			System.out.println("time is out....");
		}

		@Override
		public void onNext(String data) {
			System.out.println(data);
		}

		@Override
		public void onSubscribe(Subscription subs) {
			subs.request(Long.MAX_VALUE);
		}
		
	});
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:25,代碼來源:TestEmployeeBatchStream.java

示例5: testGetValidEmployees

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Test
public void testGetValidEmployees(){
	Subscriber<String> mySubscription = new Subscriber<String>() {

		@Override
		public void onComplete() {	}

		@Override
		public void onError(Throwable e) {	}

		@Override
		public void onNext(String name) {
			System.out.format("Employee: %s \n", name);
		}

		@Override
		public void onSubscribe(Subscription subs) {
			subs.request(Long.MAX_VALUE);

		}

	};
	
	employeeStreamServiceImpl.getValidEmployees().subscribe(mySubscription);
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:26,代碼來源:TestEmployeeStreamService.java

示例6: requestDelegates

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Test
public void requestDelegates() {
    CallStreamObserver<Object> obs = mock(CallStreamObserver.class);
    Subscriber<Object> sub = mock(Subscriber.class);

    final AtomicReference<Subscription> subscription = new AtomicReference<Subscription>();
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocationOnMock) {
            subscription.set((Subscription) invocationOnMock.getArguments()[0]);
            return null;
        }
    }).when(sub).onSubscribe(any(Subscription.class));

    ReactiveStreamObserverPublisher<Object> pub = new ReactiveStreamObserverPublisher<Object>(obs);
    pub.subscribe(sub);

    assertThat(subscription.get()).isNotNull();
    subscription.get().request(10);
    verify(obs).request(10);
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:22,代碼來源:ReactiveStreamObserverPublisherTest.java

示例7: onNextKeepsPumpRunning

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Test
public void onNextKeepsPumpRunning() {
    ClientCallStreamObserver<Object> obs = mock(ClientCallStreamObserver.class);
    when(obs.isReady()).thenReturn(true);

    ReactivePublisherBackpressureOnReadyHandler<Object> handler = new ReactivePublisherBackpressureOnReadyHandler<Object>(obs);
    Subscription sub = mock(Subscription.class);

    handler.onSubscribe(sub);

    Object obj = new Object();
    handler.onNext(obj);

    verify(obs).onNext(obj);
    verify(sub).request(1);
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:17,代碼來源:ReactivePublisherBackpressureOnReadyHandlerTest.java

示例8: initSubscribe

import org.reactivestreams.Subscription; //導入依賴的package包/類
private void initSubscribe() {
    RxBus.INSTANCE.toSubscriber(TestEvent.class).subscribeWith(new Subscriber<TestEvent>() {
        @Override
        public void onSubscribe(Subscription s) {
            mSubscription = s;
            mSubscription.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(TestEvent testEvent) {
            mObjectReceive.setText(mObjectReceive.getText() + "  " + testEvent.number);
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onComplete() {
        }
    });

}
 
開發者ID:RyanHuen,項目名稱:GetStartRxJava2.0,代碼行數:24,代碼來源:HandleFragment.java

示例9: cancelAndChange

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Test
public void cancelAndChange() {
    AtomicReference<Subscription> s = new AtomicReference<Subscription>();

    SubscriptionHelper.cancel(s);

    BooleanSubscription bs1 = new BooleanSubscription();
    assertFalse(SubscriptionHelper.set(s, bs1));
    assertTrue(bs1.isCancelled());

    assertFalse(SubscriptionHelper.set(s, null));

    BooleanSubscription bs2 = new BooleanSubscription();
    assertFalse(SubscriptionHelper.replace(s, bs2));
    assertTrue(bs2.isCancelled());

    assertFalse(SubscriptionHelper.replace(s, null));
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:19,代碼來源:SubscriptionHelperTest.java

示例10: blockingGet

import org.reactivestreams.Subscription; //導入依賴的package包/類
/**
 * Block until the first value arrives and return it, otherwise
 * return null for an empty source and rethrow any exception.
 * @return the first value or null if the source is empty
 */
public final T blockingGet() {
    if (getCount() != 0) {
        try {
            BlockingHelper.verifyNonBlocking();
            await();
        } catch (InterruptedException ex) {
            Subscription s = this.s;
            this.s = SubscriptionHelper.CANCELLED;
            if (s != null) {
                s.cancel();
            }
            throw ExceptionHelper.wrapOrThrow(ex);
        }
    }

    Throwable e = error;
    if (e != null) {
        throw ExceptionHelper.wrapOrThrow(e);
    }
    return value;
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:27,代碼來源:BlockingBaseSubscriber.java

示例11: logSub

import org.reactivestreams.Subscription; //導入依賴的package包/類
private static <T> Subscriber<T> logSub() {
    return new Subscriber<T>() {

        @Override
        public void onSubscribe(Subscription subscription) {
            System.out.println("onSubscribe");
            subscription.request(Long.MAX_VALUE);

        }

        @Override
        public void onNext(T t) {
            System.out.println("on Next " + t);
        }

        @Override
        public void onError(Throwable throwable) {
            System.out.println("onError " + throwable.getMessage());
        }

        @Override
        public void onComplete() {
            System.out.println("onComplete");
        }
    };
}
 
開發者ID:sejoung,項目名稱:ReactiveTest,代碼行數:27,代碼來源:PubSub2.java

示例12: store

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Override public Publisher<Void> store(final T value) {
  return new Publisher<Void>() {
    @Override public void subscribe(final Subscriber<? super Void> s) {
      s.onSubscribe(new Subscription() {

        volatile boolean canceled = false;

        @Override public void request(long n) {
          try {
            depositor.store(value);

            if (canceled) return;
            s.onComplete();
          } catch (Exception e) {
            if (canceled) return;
            s.onError(e);
          }
        }

        @Override public void cancel() {
          canceled = true;
        }
      });
    }
  };
}
 
開發者ID:rogues-dev,項目名稱:hoard,代碼行數:27,代碼來源:DefaultReactiveStreamDepositor.java

示例13: delete

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Override public Publisher<Void> delete() {
  return new Publisher<Void>() {
    @Override public void subscribe(final Subscriber<? super Void> s) {
      s.onSubscribe(new Subscription() {

        volatile boolean canceled = false;

        @Override public void request(long n) {
          try {
            depositor.delete();
            if (canceled) return;
            s.onComplete();
          } catch (Exception e) {
            if (canceled) return;
            s.onError(e);
          }
        }

        @Override public void cancel() {
          canceled = true;
        }
      });
    }
  };
}
 
開發者ID:rogues-dev,項目名稱:hoard,代碼行數:26,代碼來源:DefaultReactiveStreamDepositor.java

示例14: cancel

import org.reactivestreams.Subscription; //導入依賴的package包/類
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
    for (;;) {
        Subscription a = s.get();
        if (a == this || a == SubscriptionHelper.CANCELLED) {
            return false;
        }

        if (s.compareAndSet(a, SubscriptionHelper.CANCELLED)) {
            if (a != null) {
                a.cancel();
            }
            countDown();
            return true;
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:18,代碼來源:FutureSubscriber.java

示例15: setResource

import org.reactivestreams.Subscription; //導入依賴的package包/類
/**
 * Sets the resource at the specified index and disposes the old resource.
 * @param index the index of the resource to set
 * @param resource the new resource
 * @return true if the resource has ben set, false if the composite has been disposed
 */
public boolean setResource(int index, Subscription resource) {
    for (;;) {
        Subscription o = get(index);
        if (o == SubscriptionHelper.CANCELLED) {
            if (resource != null) {
                resource.cancel();
            }
            return false;
        }
        if (compareAndSet(index, o, resource)) {
            if (o != null) {
                o.cancel();
            }
            return true;
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:24,代碼來源:ArrayCompositeSubscription.java


注:本文中的org.reactivestreams.Subscription類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。