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


Java FlowableEmitter類代碼示例

本文整理匯總了Java中io.reactivex.FlowableEmitter的典型用法代碼示例。如果您正苦於以下問題:Java FlowableEmitter類的具體用法?Java FlowableEmitter怎麽用?Java FlowableEmitter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FlowableEmitter類屬於io.reactivex包,在下文中一共展示了FlowableEmitter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: emmit

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
private void emmit(FlowableEmitter<Message> emitter, String roomId) throws Exception {
    SSLContext sslCtx = SSLContext.getDefault();
    SSLEngine sslEngine = sslCtx.createSSLEngine("stream.gitter.im", 443);
    sslEngine.setUseClientMode(true);

    HttpClient
            .newClient("stream.gitter.im", 443)
            .secure(sslEngine)
            .createGet("/v1/rooms/" + roomId + "/chatMessages")
            .addHeader("Authorization", "Bearer 3cd4820adf59b6a7116f99d92f68a1b786895ce7")
            .flatMap(HttpClientResponse::getContent)
            .filter(bb -> bb.capacity() > 2)
            .map(MessageEncoder::mapToMessage)
            .doOnNext(m -> System.out.println("Log Emit: " + m))
            .subscribe(emitter::onNext, emitter::onError, emitter::onComplete);
}
 
開發者ID:OlegDokuka,項目名稱:reactive-playing,代碼行數:17,代碼來源:RxGitterClient.java

示例2: getTiles

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
/**
 * @param path the root directory containing files to be emitted
 * @param depth offset, where 1 == data directory, 2 == zoom directory, 3 == row, 4 == column
 * @return a stream of file references to data structured as the Google tiling scheme.
 */
public static Observable<File> getTiles(String path, int depth) {
  // programmer's note:
  // https://medium.com/we-are-yammer/converting-callback-async-calls-to-rxjava-ebc68bde5831
  // http://vlkan.com/blog/post/2016/07/20/rxjava-backpressure/
  // Essentially lots of way to skin this cat - e.g. onBackpressureBlock /
  // reactive pull

  return Flowable.create(new FlowableOnSubscribe<File>() {
    @Override
    public void subscribe(FlowableEmitter<File> subscriber) throws Exception {
      try {
        // warning: depth 4 is not really walking (semantics)
        walk(path, depth, subscriber);
        if (!subscriber.isCancelled()) {
          subscriber.onComplete();
        }
      } catch (final Exception ex) {
        if (!subscriber.isCancelled()) {
          subscriber.onError(ex);
        }
      }
    }
  }, BackpressureStrategy.BUFFER).toObservable();
}
 
開發者ID:OrdnanceSurvey,項目名稱:vt-support,代碼行數:30,代碼來源:FilesystemUtil.java

示例3: createListItemEmitter

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
static <T> void createListItemEmitter(final Query<T> query, final FlowableEmitter<T> emitter) {
    final DataSubscription dataSubscription = query.subscribe().observer(new DataObserver<List<T>>() {
        @Override
        public void onData(List<T> data) {
            for (T datum : data) {
                if (emitter.isCancelled()) {
                    return;
                } else {
                    emitter.onNext(datum);
                }
            }
            if (!emitter.isCancelled()) {
                emitter.onComplete();
            }
        }
    });
    emitter.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            dataSubscription.cancel();
        }
    });
}
 
開發者ID:greenrobot,項目名稱:ObjectBoxRxJava,代碼行數:24,代碼來源:RxQuery.java

示例4: subscribe

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
@Override
public final void subscribe(FlowableEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            if (apiClient.isConnected()) {
                RxLocationFlowableOnSubscribe.this.onUnsubscribed(apiClient);
            }

            apiClient.disconnect();
        }
    });
}
 
開發者ID:TechIsFun,項目名稱:RxJava2-weather-example,代碼行數:22,代碼來源:RxLocationFlowableOnSubscribe.java

示例5: insertSystemAlbumAndRefresh

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
/**
 * 插入到係統相冊, 並刷新係統相冊
 * @param imageUrl
 */
private static void insertSystemAlbumAndRefresh(final String imageUrl) {
    Flowable.create(new FlowableOnSubscribe<Object>() {
        @Override
        public void subscribe(FlowableEmitter<Object> e) throws Exception {
            File file = FileUtils.createFileFrom(imageUrl);
            String imageUri = MediaStore.Images.Media.insertImage(ApplicationProvider.IMPL.getApp().getContentResolver(), file.getAbsolutePath(), file.getName(), "圖片: " + file.getName());
            Log.d("_stone_", "insertSystemAlbumAndRefresh-subscribe: imageUri=" + imageUri);


            //講數據插入到係統圖庫, 在係統相冊APP中就可以看到保存的圖片了.
            //為了保險起見, 再同步一下係統圖庫
            syncAlbum(imageUrl);
        }
    }, BackpressureStrategy.BUFFER)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe();
}
 
開發者ID:stone100,項目名稱:SaveImage2SystemAlbum,代碼行數:23,代碼來源:AlbumManager.java

示例6: SimpleRemoteSourceMapper

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
public SimpleRemoteSourceMapper(FlowableEmitter<Resource<T>> emitter) {
    emitter.onNext(Resource.loading(null));
    // since realm instance was created on Main Thread, so if we need to touch on realm database after calling
    // api (such as save response data to local database, we must make request on main thread
    // by setting shouldUpdateUi params = true
    Disposable disposable = RestHelper.makeRequest(getRemote(), true, response -> {
        Log.d(TAG, "SimpleRemoteSourceMapper: call API success!");
        saveCallResult(response);
        emitter.onNext(Resource.success(response));
    }, errorEntity -> {
        Log.d(TAG, "SimpleRemoteSourceMapper: call API error: " + errorEntity.getMessage());
        emitter.onNext(Resource.error(errorEntity.getMessage(), null));
    });

    // set emitter disposable to ensure that when it is going to be disposed, our api request should be disposed as well
    emitter.setDisposable(disposable);
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:18,代碼來源:SimpleRemoteSourceMapper.java

示例7: ListDataNetworkBounceResource

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
public ListDataNetworkBounceResource(FlowableEmitter<Resource<LocalType>> emitter) {
    emitter.onNext(Resource.success(getLocal()));

    emitter.onNext(Resource.loading(null));

    // since realm instance was created on Main Thread, so if we need to touch on realm database after calling
    // api (such as save response data to local database, we must make request on main thread
    // by setting shouldUpdateUi params = true
    Disposable disposable = RestHelper.makeRequest(getRemote(), true, response -> {
        Single.just(response)
                .map(mapper())
                .subscribe(localData -> {
                    Log.d(TAG, "SimpleRemoteSourceMapper: call API success!");
                    saveCallResult(localData);
                    emitter.onNext(Resource.success(localData));
                });
    }, errorEntity -> {
        Log.d(TAG, "SimpleRemoteSourceMapper: call API error: " + errorEntity.getMessage());
        emitter.onNext(Resource.error(errorEntity.getMessage(), null));
    });

    // set emitter disposable to ensure that when it is going to be disposed, our api request should be disposed as well
    emitter.setDisposable(disposable);
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:25,代碼來源:ListDataNetworkBounceResource.java

示例8: processImage

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
private void processImage(@NonNull final Bitmap bitmap) {
    //Create observable
    Flowable<List<Classifier.Recognition>> observable = Flowable
            .create(new FlowableOnSubscribe<List<Classifier.Recognition>>() {
                @Override
                public void subscribe(FlowableEmitter<List<Classifier.Recognition>> emitter) throws Exception {
                    emitter.onNext(mTensorFlowImageClassifier.recognizeImage(bitmap));
                }
            }, BackpressureStrategy.MISSING);

    //Create observer
    Consumer<List<Classifier.Recognition>> mTfProcessorObserver = new Consumer<List<Classifier.Recognition>>() {
        @Override
        public void accept(@io.reactivex.annotations.NonNull List<Classifier.Recognition> recognitions) throws Exception {
            //Write the result on socket.
            String resultStr = "";
            for (Classifier.Recognition result : recognitions)
                resultStr = resultStr + result.getTitle() + " " + result.getConfidence() + "<br/>";
            mSocketWriter.writeMessage(resultStr);

            //Remove previous disposables.
            mCompositeDisposable.clear();
        }
    };

    //Start the observable
    mCompositeDisposable.add(observable.observeOn(Schedulers.io())
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe(mTfProcessorObserver));
}
 
開發者ID:kevalpatel2106,項目名稱:robo-car,代碼行數:31,代碼來源:Controller.java

示例9: initializeSensorEventListenerFor

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
private SensorEventListener initializeSensorEventListenerFor(final FlowableEmitter<SensorRecord> subscriber) {
    return new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            subscriber.onNext(createSensorRecordFrom(event));
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {}
    };
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:13,代碼來源:IMUSensorGatherer.java

示例10: defineBroadcastReceiverFor

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
private BroadcastReceiver defineBroadcastReceiverFor(final FlowableEmitter<SensorRecord> subscriber){
    return new BroadcastReceiver() {
        Timer timer = new Timer();
        long prevCallTime = new Date().getTime();

        @Override
        public void onReceive(Context context, Intent intent) {
            long actualTime = new Date().getTime();
            long delay = calculateDiffDelay(prevCallTime, actualTime);
            prevCallTime = actualTime;

            subscriber.onNext(new WifiMeasurementsRecord(wifiManager.getScanResults()));

            if (delay > 0)
                timer.schedule(createScanTask(), delay);
            else
                createScanTask().run();
        }
    };
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:21,代碼來源:WifiMeasurementsGatherer.java

示例11: subscribe

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
@Override
public void subscribe(FlowableEmitter<T> e) throws Exception {
	try {
		Response response = call.execute();

		if (!e.isCancelled()) {
			if (response.isSuccessful()) {
				e.onNext(rxEasyConverter.convert(response.body().string()));
			} else {
				e.onError(new Throwable("response is unsuccessful"));
			}
		}
	} catch (Throwable t) {
		if (!e.isCancelled()) {
			e.onError(t);
		}
	} finally {
		e.onComplete();
	}
}
 
開發者ID:LaurenceYang,項目名稱:EasyHttp,代碼行數:21,代碼來源:RxEasyHttpManager.java

示例12: asyncMethod

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
private void asyncMethod(final ProceedingJoinPoint joinPoint) throws Throwable {

        Flowable.create(new FlowableOnSubscribe<Object>() {
                            @Override
                            public void subscribe(FlowableEmitter<Object> e) throws Exception {
                                Looper.prepare();
                                try {
                                    joinPoint.proceed();
                                } catch (Throwable throwable) {
                                    throwable.printStackTrace();
                                }
                                Looper.loop();
                            }
                        }
                , BackpressureStrategy.BUFFER)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe();
    }
 
開發者ID:fengzhizi715,項目名稱:SAF-AOP,代碼行數:20,代碼來源:AsyncAspect.java

示例13: doPullStreamPost

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
@Override
public Flowable doPullStreamPost(final IRequestEntity requestEntity, final File file) {

    Flowable flowable = DefaultFlowable.create(new FlowableOnSubscribe() {
        @Override
        public void subscribe(FlowableEmitter emitter) throws Exception {
            final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
            Gson gson = new Gson();
            String json = gson.toJson(requestEntity);
            RequestBody body = RequestBody.create(JSON, json);
            Request request = new Request.Builder()
                    .url(mUrl)
                    .post(body)
                    .build();
            Response response = mClient.newCall(request).execute();
            if (response == null) {
                emitter.onError(new EmptyException());
                return;
            }
            recvFile(emitter, response, file);
            emitter.onComplete();
        }
    });
    return flowable;
}
 
開發者ID:xiaoxige,項目名稱:AutoNet,代碼行數:26,代碼來源:AutoNetRepoImpl.java

示例14: createYourOwnTibco

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
@Test
public void createYourOwnTibco() throws Exception {
    Flowable<String> flowable = Flowable.create(new FlowableOnSubscribe<String>() {
        @Override
        public void subscribe(FlowableEmitter<String> e) throws Exception {
            while (!e.isCancelled()) {
                long numberRecords = e.requested();
                System.out.println(numberRecords);
                if (numberRecords > 0) {
                }
            }
        }
    }, BackpressureStrategy.BUFFER);


    flowable.map(x -> x + "Yay!").subscribe(System.out::println);
}
 
開發者ID:dhinojosa,項目名稱:rxjavatraining,代碼行數:18,代碼來源:TibcoObservableTest.java

示例15: subscribe

import io.reactivex.FlowableEmitter; //導入依賴的package包/類
@Override
public final void subscribe(FlowableEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(() -> {
        if (apiClient.isConnected()) {
            onUnsubscribed(apiClient);
        }

        apiClient.disconnect();
    });
}
 
開發者ID:florent37,項目名稱:RxGps,代碼行數:19,代碼來源:RxLocationFlowableOnSubscribe.java


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