• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Cancellable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中rx.functions.Cancellable的典型用法代码示例。如果您正苦于以下问题:Java Cancellable类的具体用法?Java Cancellable怎么用?Java Cancellable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Cancellable类属于rx.functions包,在下文中一共展示了Cancellable类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: queue

import rx.functions.Cancellable; //导入依赖的package包/类
@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public <T> Observable<T> queue(final Operation<T> operation) {
    return Observable.create(new Action1<Emitter<T>>() {
        @Override
        public void call(Emitter<T> tEmitter) {
            final FIFORunnableEntry entry = new FIFORunnableEntry<>(operation, tEmitter);
            tEmitter.setCancellation(new Cancellable() {
                @Override
                public void cancel() throws Exception {
                    if (queue.remove(entry)) {
                        logOperationRemoved(operation);
                    }
                }
            });
            logOperationQueued(operation);
            queue.add(entry);
        }
    }, Emitter.BackpressureMode.NONE);
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:21,代码来源:ClientOperationQueueImpl.java


示例2: queue

import rx.functions.Cancellable; //导入依赖的package包/类
@Override
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public synchronized <T> Observable<T> queue(final Operation<T> operation) {
    if (!shouldRun) {
        return Observable.error(disconnectionException);
    }
    return Observable.create(new Action1<Emitter<T>>() {
        @Override
        public void call(Emitter<T> tEmitter) {
            final FIFORunnableEntry entry = new FIFORunnableEntry<>(operation, tEmitter);

            tEmitter.setCancellation(new Cancellable() {
                @Override
                public void cancel() throws Exception {
                    if (queue.remove(entry)) {
                        logOperationRemoved(operation);
                    }
                }
            });

            logOperationQueued(operation);
            queue.add(entry);
        }
    }, Emitter.BackpressureMode.NONE);
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:26,代码来源:ConnectionOperationQueueImpl.java


示例3: protectedRun

import rx.functions.Cancellable; //导入依赖的package包/类
@Override
final protected void protectedRun(final Emitter<SCAN_RESULT_TYPE> emitter, QueueReleaseInterface queueReleaseInterface) {

    final SCAN_CALLBACK_TYPE scanCallback = createScanCallback(emitter);

    try {
        emitter.setCancellation(new Cancellable() {
            @Override
            public void cancel() throws Exception {
                RxBleLog.i("Scan operation is requested to stop.");
                stopScan(rxBleAdapterWrapper, scanCallback);
            }
        });
        RxBleLog.i("Scan operation is requested to start.");
        boolean startLeScanStatus = startScan(rxBleAdapterWrapper, scanCallback);

        if (!startLeScanStatus) {
            emitter.onError(new BleScanException(BleScanException.BLUETOOTH_CANNOT_START));
        }
    } catch (Throwable throwable) {
        RxBleLog.e(throwable, "Error while calling the start scan function");
        emitter.onError(new BleScanException(BleScanException.BLUETOOTH_CANNOT_START));
    } finally {
        queueReleaseInterface.release();
    }
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:27,代码来源:ScanOperation.java


示例4: visitStream

import rx.functions.Cancellable; //导入依赖的package包/类
public static Observable<Visit> visitStream(final Ahoy ahoy) {
    return Observable.create(new Action1<Emitter<Visit>>() {
        @Override public void call(final Emitter<Visit> emitter) {
            final VisitListener listener = new VisitListener() {
                @Override public void onVisitUpdated(Visit visit) {
                    emitter.onNext(visit);
                }
            };

            ahoy.addVisitListener(listener);

            emitter.setCancellation(new Cancellable() {
                @Override public void cancel() throws Exception {
                    ahoy.removeVisitListener(listener);
                }
            });
        }
    }, BackpressureMode.LATEST);
}
 
开发者ID:instacart,项目名称:ahoy-android,代码行数:20,代码来源:RxAhoy.java


示例5: call

import rx.functions.Cancellable; //导入依赖的package包/类
@Override
public void call(final Emitter<AppState> appStateEmitter) {
  final AppStateListener appStateListener = new AppStateListener() {
    @Override
    public void onAppDidEnterForeground() {
      appStateEmitter.onNext(FOREGROUND);
    }

    @Override
    public void onAppDidEnterBackground() {
      appStateEmitter.onNext(BACKGROUND);
    }
  };

  appStateEmitter.setCancellation(new Cancellable() {
    @Override
    public void cancel() throws Exception {
      recognizer.removeListener(appStateListener);
      recognizer.stop();
    }
  });

  recognizer.addListener(appStateListener);
  recognizer.start();
}
 
开发者ID:jenzz,项目名称:RxAppState,代码行数:26,代码来源:AppStateEmitter.java


示例6: toObservable

import rx.functions.Cancellable; //导入依赖的package包/类
public static <T> Observable<T> toObservable(final ObservableField<T> observableField, final boolean emitCurrent) {

        return Observable.create(new Action1<Emitter<T>>() {
            @Override
            public void call(final Emitter<T> emitter) {

                if (emitCurrent && observableField.get() != null) {
                    emitter.onNext(observableField.get());
                }
                final OnPropertyChangedCallback callback = new OnPropertyChangedCallback() {
                    @Override
                    public void onPropertyChanged(android.databinding.Observable dataBindingObservable, int propertyId) {
                        if (dataBindingObservable == observableField) {
                            emitter.onNext(observableField.get());
                        }
                    }
                };

                observableField.addOnPropertyChangedCallback(callback);

                emitter.setCancellation(new Cancellable() {
                    @Override
                    public void cancel() throws Exception {
                        observableField.removeOnPropertyChangedCallback(callback);
                    }
                });

            }
        }, Emitter.BackpressureMode.BUFFER);
    }
 
开发者ID:christophwidulle,项目名称:Raclette,代码行数:31,代码来源:Value.java


示例7: from

import rx.functions.Cancellable; //导入依赖的package包/类
/**
 * Converts an {@link ApolloQueryWatcher} into an Observable.
 *
 * @param watcher          the ApolloQueryWatcher to convert
 * @param backpressureMode the back pressure strategy to apply to the observable source.
 * @param <T>              the value type
 * @return the converted Observable
 */
@Nonnull public static <T> Observable<Response<T>> from(@Nonnull final ApolloQueryWatcher<T> watcher,
    @Nonnull Emitter.BackpressureMode backpressureMode) {
  checkNotNull(backpressureMode, "backpressureMode == null");
  checkNotNull(watcher, "watcher == null");
  return Observable.create(new Action1<Emitter<Response<T>>>() {
    @Override public void call(final Emitter<Response<T>> emitter) {
      final AtomicBoolean canceled = new AtomicBoolean();
      emitter.setCancellation(new Cancellable() {
        @Override public void cancel() throws Exception {
          canceled.set(true);
          watcher.cancel();
        }
      });
      watcher.enqueueAndWatch(new ApolloCall.Callback<T>() {
        @Override public void onResponse(@Nonnull Response<T> response) {
          if (!canceled.get()) {
            emitter.onNext(response);
          }
        }

        @Override public void onFailure(@Nonnull ApolloException e) {
          Exceptions.throwIfFatal(e);
          if (!canceled.get()) {
            emitter.onError(e);
          }
        }
      });
    }
  }, backpressureMode);
}
 
开发者ID:apollographql,项目名称:apollo-android,代码行数:39,代码来源:RxApollo.java


示例8: createCancellable

import rx.functions.Cancellable; //导入依赖的package包/类
private Cancellable createCancellable() {
    return new Cancellable() {
        @Override
        public void cancel() throws Exception {
            merlin.unbind();
        }
    };
}
 
开发者ID:novoda,项目名称:merlin,代码行数:9,代码来源:MerlinAction.java


示例9: getConnectedBluetoothGatt

import rx.functions.Cancellable; //导入依赖的package包/类
/**
 * Emits BluetoothGatt and completes after connection is established.
 *
 * @return BluetoothGatt after connection reaches {@link com.polidea.rxandroidble.RxBleConnection.RxBleConnectionState#CONNECTED}
 * state.
 * @throws com.polidea.rxandroidble.exceptions.BleDisconnectedException if connection was disconnected/failed before it was established.
 */
@NonNull
private Observable<BluetoothGatt> getConnectedBluetoothGatt() {
    // start connecting the BluetoothGatt
    // note: Due to different Android BLE stack implementations it is not certain whether `connectGatt()` or `BluetoothGattCallback`
    // will emit BluetoothGatt first
    return Observable.create(
            new Action1<Emitter<BluetoothGatt>>() {
                @Override
                public void call(Emitter<BluetoothGatt> emitter) {
                    final Subscription connectedBluetoothGattSubscription = Observable.fromCallable(new Func0<BluetoothGatt>() {
                        @Override
                        public BluetoothGatt call() {
                            connectionStateChangedAction.onConnectionStateChange(CONNECTED);
                            return bluetoothGattProvider.getBluetoothGatt();
                        }
                    })
                            // when the connected state will be emitted bluetoothGattProvider should contain valid Gatt
                            .delaySubscription(
                                    rxBleGattCallback
                                            .getOnConnectionStateChange()
                                            .takeFirst(new Func1<RxBleConnection.RxBleConnectionState, Boolean>() {
                                                @Override
                                                public Boolean call(RxBleConnection.RxBleConnectionState rxBleConnectionState) {
                                                    return rxBleConnectionState == CONNECTED;
                                                }
                                            })
                            )
                            // disconnect may happen even if the connection was not established yet
                            .mergeWith(rxBleGattCallback.<BluetoothGatt>observeDisconnect())
                            .take(1)
                            .subscribe(emitter);

                    emitter.setCancellation(new Cancellable() {
                        @Override
                        public void cancel() throws Exception {
                            connectedBluetoothGattSubscription.unsubscribe();
                        }
                    });

                    connectionStateChangedAction.onConnectionStateChange(CONNECTING);

                    /*
                    * Apparently the connection may be established fast enough to introduce a race condition so the subscription
                    * must be established first before starting the connection.
                    * https://github.com/Polidea/RxAndroidBle/issues/178
                    * */

                    final BluetoothGatt bluetoothGatt = connectionCompat
                            .connectGatt(bluetoothDevice, autoConnect, rxBleGattCallback.getBluetoothGattCallback());
                    /*
                    * Update BluetoothGatt when connection is initiated. It is not certain
                    * if this or RxBleGattCallback.onConnectionStateChange will be first.
                    * */
                    bluetoothGattProvider.updateBluetoothGatt(bluetoothGatt);
                }
            },
            Emitter.BackpressureMode.NONE
    );
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:67,代码来源:ConnectOperation.java


示例10: ClientStateObservable

import rx.functions.Cancellable; //导入依赖的package包/类
@Inject
protected ClientStateObservable(
        final RxBleAdapterWrapper rxBleAdapterWrapper,
        final Observable<RxBleAdapterStateObservable.BleAdapterState> bleAdapterStateObservable,
        @Named(ClientComponent.NamedBooleanObservables.LOCATION_SERVICES_OK) final Observable<Boolean> locationServicesOkObservable,
        final LocationServicesStatus locationServicesStatus,
        @Named(ClientComponent.NamedSchedulers.TIMEOUT) final Scheduler timerScheduler
) {
    super(new OnSubscribeCreate<>(
            new Action1<Emitter<RxBleClient.State>>() {
                @Override
                public void call(Emitter<RxBleClient.State> emitter) {
                    if (!rxBleAdapterWrapper.hasBluetoothAdapter()) {
                        emitter.onCompleted();
                        return;
                    }

                    final Subscription changingStateSubscription = checkPermissionUntilGranted(locationServicesStatus, timerScheduler)
                            .flatMapObservable(new Func1<Boolean, Observable<RxBleClient.State>>() {
                                @Override
                                public Observable<RxBleClient.State> call(Boolean permissionWasInitiallyGranted) {
                                    return checkAdapterAndServicesState(
                                            permissionWasInitiallyGranted,
                                            rxBleAdapterWrapper,
                                            bleAdapterStateObservable,
                                            locationServicesOkObservable
                                    );
                                }
                            })
                            .distinctUntilChanged()
                            .subscribe(emitter);

                    emitter.setCancellation(new Cancellable() {
                        @Override
                        public void cancel() throws Exception {
                            changingStateSubscription.unsubscribe();
                        }
                    });
                }
            },
            Emitter.BackpressureMode.LATEST
    ));
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:44,代码来源:ClientStateObservable.java


示例11: setsCancellation

import rx.functions.Cancellable; //导入依赖的package包/类
@Test
public void setsCancellation() {
  verify(mockEmitter).setCancellation(any(Cancellable.class));
}
 
开发者ID:jenzz,项目名称:RxAppState,代码行数:5,代码来源:AppStateEmitterTest.java


示例12: get

import rx.functions.Cancellable; //导入依赖的package包/类
@Override
public Observable<T> get(String id) {
  LoggerHelper.logDebug("local:" + this.getClass().toString() + " get:" + id);
  return database
      .get()
      .createQuery(getTableName(), "SELECT * FROM " + getTableName() + " WHERE id = ?", id)
      .take(1)
      .switchMap(
          new Func1<SqlBrite.Query, Observable<? extends T>>() {
            @Override
            public Observable<? extends T> call(final SqlBrite.Query map) {
              return Observable.create(
                  new Action1<Emitter<T>>() {
                    @Override
                    public void call(Emitter<T> emitter) {
                      final Cursor cursor = map.run();
                      emitter.setCancellation(
                          new Cancellable() {
                            @Override
                            public void cancel() throws Exception {
                              cursor.close();
                            }
                          });
                      if (!cursor.isClosed() && cursor.moveToFirst()) {
                        try {
                          emitter.onNext(
                              JsonMapper.INSTANCE.fromJson(
                                  cursor.getString(DATA_COLUMN),
                                  LocalStorageRepoImpl.this.getType()));
                        } catch (IOException e) {
                          emitter.onError(e);
                          return;
                        }
                      }
                      emitter.onCompleted();
                    }
                  },
                  Emitter.BackpressureMode.LATEST);
            }
          });
}
 
开发者ID:jszczygiel,项目名称:android-common,代码行数:42,代码来源:LocalStorageRepoImpl.java


示例13: getAll

import rx.functions.Cancellable; //导入依赖的package包/类
@Override
public Observable<T> getAll() {
  LoggerHelper.logDebug("local:" + this.getClass().toString() + " getAll");
  return database
      .get()
      .createQuery(getTableName(), "SELECT * FROM " + getTableName())
      .take(1)
      .switchMap(
          new Func1<SqlBrite.Query, Observable<? extends T>>() {
            @Override
            public Observable<? extends T> call(final SqlBrite.Query map) {
              return Observable.create(
                  new Action1<Emitter<T>>() {
                    @Override
                    public void call(Emitter<T> emitter) {
                      final Cursor cursor = map.run();
                      emitter.setCancellation(
                          new Cancellable() {
                            @Override
                            public void cancel() throws Exception {
                              cursor.close();
                            }
                          });
                      while (!cursor.isClosed() && cursor.moveToNext()) {
                        try {
                          emitter.onNext(
                              JsonMapper.INSTANCE.fromJson(
                                  cursor.getString(DATA_COLUMN),
                                  LocalStorageRepoImpl.this.getType()));
                        } catch (IOException e) {
                          emitter.onError(e);
                          return;
                        }
                      }
                      emitter.onCompleted();
                    }
                  },
                  Emitter.BackpressureMode.BUFFER);
            }
          });
}
 
开发者ID:jszczygiel,项目名称:android-common,代码行数:42,代码来源:LocalStorageRepoImpl.java



注:本文中的rx.functions.Cancellable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EnterMappingDialog类代码示例发布时间:2022-05-22
下一篇:
Java MaterialSpinner类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap