Class Observables


  • @Deprecated
    public final class Observables
    extends Object
    Deprecated.
    Prefer the Reactive Streams-based asynchronous driver (mongodb-driver-reactivestreams artifactId)
    Observable helpers.

    Allows async methods to be converted into event-based Observables.

    Since:
    3.1
    • Method Detail

      • observe

        public static <TResult> Observable<TResult> observe​(MongoIterable<TResult> mongoIterable)
        Deprecated.
        Convert a MongoIterable into an Observable.
        Type Parameters:
        TResult - The type of result being observed
        Parameters:
        mongoIterable - the MongoIterable to subscribe to
        Returns:
        the observable version of the mongoIterable
      • observe

        public static <TResult> Observable<TResult> observe​(Block<SingleResultCallback<TResult>> operation)
        Deprecated.
        Allows the conversion of SingleResultCallback based operations into an Observable

        Requires a Block that is passed the callback to be used with the operation. This is required to make sure that the operation only occurs once the Subscription signals for data.

        A typical example would be when wrapping callback based methods to make them observable.
        For example, converting MongoCollection.count(SingleResultCallback) into an Observable:

         
            Observable<Long> countObservable = observe(new Block<SingleResultCallback<Long>>() {
                public void apply(final SingleResultCallback<Long> callback) {
                    collection.countDocuments(callback);
                }
            });
         
         
        Type Parameters:
        TResult - The type of result being observed
        Parameters:
        operation - the block that implements the operation.
        Returns:
        the observable version of the callback based operation
      • observeAndFlatten

        public static <TResult> Observable<TResult> observeAndFlatten​(Block<SingleResultCallback<List<TResult>>> operation)
        Deprecated.
        Allows the conversion of SingleResultCallback based operations and flattens the results in an Observable.

        Requires a Block that is passed the callback to be used with the operation. This is required to make sure that the operation only occurs once the Subscription signals for data.

        Type Parameters:
        TResult - The type of result being observed
        Parameters:
        operation - the operation that is passed a callback and is used to delay execution of an operation until demanded.
        Returns:
        a subscription