本文整理汇总了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;
}
}
}