Search in sources :

Example 1 with OnSubscribeWatchServiceEvents

use of com.github.davidmoten.rx.internal.operators.OnSubscribeWatchServiceEvents in project rxjava-file by davidmoten.

the class FileObservable method from.

/**
 * Returns an {@link Observable} of {@link WatchEvent}s from a
 * {@link WatchService}.
 *
 * @param watchService
 *            WatchService to generate events from
 * @param scheduler
 *            schedules polls of the watchService
 * @param pollDuration
 *            duration of each poll
 * @param pollDurationUnit
 *            time unit for the duration of each poll
 * @param pollInterval
 *            interval between polls of the watchService
 * @param pollIntervalUnit
 *            time unit for the interval between polls
 * @param backpressureStrategy
 *            backpressures strategy to apply
 * @return an observable of WatchEvents from watchService
 */
public static final Observable<WatchEvent<?>> from(WatchService watchService, Scheduler scheduler, long pollDuration, TimeUnit pollDurationUnit, long pollInterval, TimeUnit pollIntervalUnit, BackpressureStrategy backpressureStrategy) {
    Preconditions.checkNotNull(watchService);
    Preconditions.checkNotNull(scheduler);
    Preconditions.checkNotNull(pollDurationUnit);
    Preconditions.checkNotNull(backpressureStrategy);
    Observable<WatchEvent<?>> o = Observable.create(new OnSubscribeWatchServiceEvents(watchService, scheduler, pollDuration, pollDurationUnit, pollInterval, pollIntervalUnit));
    if (backpressureStrategy == BackpressureStrategy.BUFFER) {
        return o.onBackpressureBuffer();
    } else if (backpressureStrategy == BackpressureStrategy.DROP)
        return o.onBackpressureDrop();
    else if (backpressureStrategy == BackpressureStrategy.LATEST)
        return o.onBackpressureLatest();
    else
        throw new RuntimeException("unrecognized backpressureStrategy " + backpressureStrategy);
}
Also used : OnSubscribeWatchServiceEvents(com.github.davidmoten.rx.internal.operators.OnSubscribeWatchServiceEvents) WatchEvent(java.nio.file.WatchEvent)

Aggregations

OnSubscribeWatchServiceEvents (com.github.davidmoten.rx.internal.operators.OnSubscribeWatchServiceEvents)1 WatchEvent (java.nio.file.WatchEvent)1