本文整理匯總了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);
}
});
}
示例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());
}
示例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();
}
});
}
示例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);
}
});
}
示例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);
}
示例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);
}
示例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() {
}
});
}
示例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));
}
示例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;
}
示例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");
}
};
}
示例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;
}
});
}
};
}
示例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;
}
});
}
};
}
示例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;
}
}
}
示例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;
}
}
}