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