本文整理汇总了Java中io.reactivex.subjects.PublishSubject.onComplete方法的典型用法代码示例。如果您正苦于以下问题:Java PublishSubject.onComplete方法的具体用法?Java PublishSubject.onComplete怎么用?Java PublishSubject.onComplete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.subjects.PublishSubject
的用法示例。
在下文中一共展示了PublishSubject.onComplete方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doSomeWork
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
private void doSomeWork() {
PublishSubject<Integer> source = PublishSubject.create();
ConnectableObservable<Integer> connectableObservable = source.replay(3); // bufferSize = 3 to retain 3 values to replay
connectableObservable.connect(); // connecting the connectableObservable
connectableObservable.subscribe(getFirstObserver());
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onNext(4);
source.onComplete();
/*
* it will emit 2, 3, 4 as (count = 3), retains the 3 values for replay
*/
connectableObservable.subscribe(getSecondObserver());
}
示例2: onRequestPermissionsResult
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
for (int i = 0, size = permissions.length; i < size; i++) {
Log.i("","onRequestPermissionsResult " + permissions[i]);
// Find the corresponding subject
PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
if (subject == null) {
// No subject found
Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
return;
}
mSubjects.remove(permissions[i]);
boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
subject.onComplete();
}
}
示例3: onRequestPermissionsResult
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
for (int i = 0, size = permissions.length; i < size; i++) {
ViseLog.i("onRequestPermissionsResult " + permissions[i]);
// Find the corresponding subject
PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
if (subject == null) {
// No subject found
Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
return;
}
mSubjects.remove(permissions[i]);
boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
subject.onComplete();
}
}
示例4: onRequestPermissionsResult
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
for (int i = 0, size = permissions.length; i < size; i++) {
log("onRequestPermissionsResult " + permissions[i]);
// Find the corresponding subject
PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
if (subject == null) {
// No subject found
Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
return;
}
mSubjects.remove(permissions[i]);
boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
subject.onComplete();
}
}
示例5: onRequestPermissionsResult
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
for (int i = 0, size = permissions.length; i < size; i++) {
log("onRequestPermissionsResult " + permissions[i]);
// Find the corresponding subject
PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
if (subject == null) {
// No subject found
Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
return;
}
mSubjects.remove(permissions[i]);
boolean granted = (grantResults[i] == PackageManager.PERMISSION_GRANTED) && (PermissionChecker.checkSelfPermission(getContext(), permissions[i]) == PermissionChecker.PERMISSION_GRANTED);
subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
subject.onComplete();
}
}
示例6: onRequestPermissionsResult
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
void onRequestPermissionsResult(@NonNull final int[] grantResults, @NonNull final boolean[] rationale, @NonNull final boolean[] rationaleAfter, @NonNull final String... permissions) {
final int size = permissions.length;
for (int i = 0; i < size; i++) {
final PublishSubject<Permission> subject = currentPermissionRequests.get(permissions[i]);
if (subject == null) {
throw new IllegalStateException("RealRxPermission.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
}
currentPermissionRequests.remove(permissions[i]);
final boolean granted = grantResults[i] == PERMISSION_GRANTED;
if (granted) {
subject.onNext(Permission.granted(permissions[i]));
} else if (!rationale[i] && !rationaleAfter[i]) {
subject.onNext(Permission.deniedNotShown(permissions[i]));
} else {
subject.onNext(Permission.denied(permissions[i]));
}
subject.onComplete();
}
}
示例7: doSomeWork
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
/**
* PublishSubject只会把在订阅发生的时间点之后来自原始Observable的数据发射给观察者。
* 需要注意的是,PublishSubject可能会一创建完成就立刻开始发射数据(除非你可以阻止它发生),
* 因此这里有一个风险:在Subject被创建后到有观察者订阅它之前这个时间段内,一个或多个数据可能会丢失。
* 如果要确保来自原始Observable的所有数据都被分发:
* 1.使用Create创建那个Observable以便手动给它引入"冷"Observable的行为(当所有观察者都已经订阅时才开始发射数据)
* 2.改用ReplaySubject。
*
* 如果原始的Observable因为发生了一个错误而终止,PublishSubject将不会发射任何数据,只是简单的向前传递这个错误通知。
*/
private void doSomeWork() {
PublishSubject<Integer> source = PublishSubject.create();
source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4 and onComplete
source.onNext(1);
source.onNext(2);
source.onNext(3);
/*
* it will emit 4 and onComplete for second observer also.
*/
source.subscribe(getSecondObserver());
source.onNext(4);
source.onComplete();
}
示例8: monitor
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
private void monitor(InputStream input, PublishSubject<String> subject) {
BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding));
final int BUFFERSIZE = 4096;
char[] buffer = new char[BUFFERSIZE];
while (true) {
try {
if (Thread.interrupted()) {
subject.onComplete();
return;
}
int read = reader.read(buffer, 0, BUFFERSIZE);
if (read == -1) {
subject.onComplete();
return;
}
subject.onNext(new String(buffer, 0, read));
} catch (IOException e) {
subject.onError(e);
return;
}
}
}
示例9: onRequestPermissionsResult
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
for (int i = 0, size = permissions.length; i < size; i++) {
log("onRequestPermissionsResult " + permissions[i]);
// Find the corresponding subject
PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
if (subject == null) {
// No subject found
log("XPermission.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
return;
}
mSubjects.remove(permissions[i]);
boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
boolean showRequestPermissionRationale = shouldShowRequestPermissionRationale[i];
log("granted: " + granted + "; showRequestPermissionRationale: " + showRequestPermissionRationale);
if(Manifest.permission.WRITE_SETTINGS.equals(permissions[i]) || Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permissions[i])){
granted = PermissionsChecker.isPermissionGranted(this,permissions[i],false);
}else{
if(granted){
if(PermissionsChecker.isPermissionGranted(this,permissions[i],true)){
granted = true;
}else{
granted = false;
showRequestPermissionRationale = false;
}
}else if(showRequestPermissionRationale){
if(PermissionsChecker.isPermissionGranted(this,permissions[i],false)){
granted = true;
}else{
granted = false;
}
}
}
subject.onNext(new Permission(permissions[i], granted, showRequestPermissionRationale));
subject.onComplete();
}
}
示例10: downloadProducts
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
/**
* Download product from given category.
*
* @param request which contains query category
* @param productPublishSubject the subject which downloaded product should publish to
*/
public void downloadProducts(DownloadProductsRequest request, PublishSubject<Product> productPublishSubject) {
QueryBuilder queryBuilder = QueryBuilders.termQuery("category", request.getCategory());
SearchResponse scrollResponse =
esClient
.prepareSearch(INDEX)
.setScroll(DEFAULT_SCROLL_TIME_VALUE)
.setTypes(TYPE)
.setQuery(queryBuilder)
.setSize(SCROLL_SIZE)
.get();
do {
scrollResponse.getHits().forEach(hit -> {
try {
Product.Builder builder = Product.newBuilder();
jsonParser.merge(hit.sourceAsString(), builder);
productPublishSubject.onNext(builder.build());
} catch (IOException ioe) {
// Don't fail the whole stream
log.error("Unable to read product record", ioe);
productPublishSubject.onError(ioe);
throw new IllegalStateException(ioe);
}
});
// Fetch next batch of cite group records
scrollResponse =
esClient
.prepareSearchScroll(scrollResponse.getScrollId())
.setScroll(DEFAULT_SCROLL_TIME_VALUE)
.execute()
.actionGet();
} while (scrollResponse.getHits().getHits().length != 0);
productPublishSubject.onComplete();
}
示例11: calculateProductScore
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
@Test
public void calculateProductScore() throws Exception {
PublishSubject<CalculateProductScoreResponse> publishSubject = PublishSubject.create();
List<CalculateProductScoreResponse> responses = Lists.newArrayList();
publishSubject
.doOnNext(response -> responses.add(response))
.subscribe();
Product product = createProduct("category");
productDao.calculateProductScore(product, publishSubject);
assertThat(responses.size()).isEqualTo(1);
publishSubject.onComplete();
}
示例12: main
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Observer<Long> observer=new Observer<Long>() {
@Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("It's Done");
}
@Override
public void onError(Throwable throwable) {
// TODO Auto-generated method stub
throwable.printStackTrace();
}
@Override
public void onNext(Long value) {
// TODO Auto-generated method stub
System.out.println(":"+value);
}
@Override
public void onSubscribe(Disposable disposable) {
// TODO Auto-generated method stub
System.out.println("onSubscribe");
}
};
PublishSubject< Long> publishSubject=PublishSubject.create();
publishSubject.onNext(1L);
publishSubject.onNext(2l);
publishSubject.subscribe(observer);
publishSubject.onNext(10l);
publishSubject.onNext(20l);
publishSubject.onComplete();
}
示例13: doSomeWork
import io.reactivex.subjects.PublishSubject; //导入方法依赖的package包/类
private void doSomeWork() {
PublishSubject<Integer> source = PublishSubject.create();
source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4 and onComplete
source.onNext(1);
source.onNext(2);
source.onNext(3);
/*
* it will emit 4 and onComplete for second observer also.
*/
source.subscribe(getSecondObserver());
source.onNext(4);
source.onComplete();
}