当前位置: 首页>>代码示例>>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;未经允许,请勿转载。