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


Java PublishSubject.onComplete方法代碼示例

本文整理匯總了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());

    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:ReplayExampleActivity.java

示例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();
    }
}
 
開發者ID:ChangWeiBa,項目名稱:AesExoPlayer,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例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();
    }
}
 
開發者ID:xiaoyaoyou1212,項目名稱:XSnow,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例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();
    }
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例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();
    }
}
 
開發者ID:CodyyAndroid,項目名稱:RxPermissions,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例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();
  }
}
 
開發者ID:vanniktech,項目名稱:RxPermission,代碼行數:26,代碼來源:RealRxPermission.java

示例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();
}
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:29,代碼來源:PublishSubjectExampleActivity.java

示例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;
        }
    }
}
 
開發者ID:Microsoft,項目名稱:java-debug,代碼行數:24,代碼來源:ProcessConsole.java

示例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();
    }
}
 
開發者ID:paozhuanyinyu,項目名稱:XPermission,代碼行數:37,代碼來源:XPermissionActivity.java

示例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();
}
 
開發者ID:email2liyang,項目名稱:grpc-mate,代碼行數:42,代碼來源:ProductDao.java

示例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();
}
 
開發者ID:email2liyang,項目名稱:grpc-mate,代碼行數:15,代碼來源:ProductDaoTest.java

示例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();
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Programming-With-Java-9,代碼行數:41,代碼來源:Demo_PublishSubject.java

示例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();

    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:PublishSubjectExampleActivity.java


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