Search in sources :

Example 21 with NonNull

use of io.reactivex.annotations.NonNull in project RxJava by ReactiveX.

the class ExecutorScheduler method scheduleDirect.

@NonNull
@Override
public Disposable scheduleDirect(@NonNull Runnable run, final long delay, final TimeUnit unit) {
    final Runnable decoratedRun = RxJavaPlugins.onSchedule(run);
    if (executor instanceof ScheduledExecutorService) {
        try {
            Future<?> f = ((ScheduledExecutorService) executor).schedule(decoratedRun, delay, unit);
            return Disposables.fromFuture(f);
        } catch (RejectedExecutionException ex) {
            RxJavaPlugins.onError(ex);
            return EmptyDisposable.INSTANCE;
        }
    }
    final DelayedRunnable dr = new DelayedRunnable(decoratedRun);
    Disposable delayed = HELPER.scheduleDirect(new DelayedDispose(dr), delay, unit);
    dr.timed.replace(delayed);
    return dr;
}
Also used : BooleanRunnable(io.reactivex.internal.schedulers.ExecutorScheduler.ExecutorWorker.BooleanRunnable) NonNull(io.reactivex.annotations.NonNull)

Example 22 with NonNull

use of io.reactivex.annotations.NonNull in project RxJava by ReactiveX.

the class ExecutorScheduler method scheduleDirect.

@NonNull
@Override
public Disposable scheduleDirect(@NonNull Runnable run) {
    Runnable decoratedRun = RxJavaPlugins.onSchedule(run);
    try {
        if (executor instanceof ExecutorService) {
            Future<?> f = ((ExecutorService) executor).submit(decoratedRun);
            return Disposables.fromFuture(f);
        }
        BooleanRunnable br = new BooleanRunnable(decoratedRun);
        executor.execute(br);
        return br;
    } catch (RejectedExecutionException ex) {
        RxJavaPlugins.onError(ex);
        return EmptyDisposable.INSTANCE;
    }
}
Also used : BooleanRunnable(io.reactivex.internal.schedulers.ExecutorScheduler.ExecutorWorker.BooleanRunnable) BooleanRunnable(io.reactivex.internal.schedulers.ExecutorScheduler.ExecutorWorker.BooleanRunnable) NonNull(io.reactivex.annotations.NonNull)

Example 23 with NonNull

use of io.reactivex.annotations.NonNull in project RxJava by ReactiveX.

the class Scheduler method schedulePeriodicallyDirect.

/**
     * Schedules a periodic execution of the given task with the given initial delay and period.
     *
     * <p>
     * This method is safe to be called from multiple threads but there are no
     * ordering guarantees between tasks.
     *
     * <p>
     * The periodic execution is at a fixed rate, that is, the first execution will be after the initial
     * delay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.
     *
     * @param run the task to schedule
     * @param initialDelay the initial delay amount, non-positive values indicate non-delayed scheduling
     * @param period the period at which the task should be re-executed
     * @param unit the unit of measure of the delay amount
     * @return the Disposable that let's one cancel this particular delayed task.
     * @since 2.0
     */
@NonNull
public Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initialDelay, long period, @NonNull TimeUnit unit) {
    final Worker w = createWorker();
    final Runnable decoratedRun = RxJavaPlugins.onSchedule(run);
    PeriodicDirectTask periodicTask = new PeriodicDirectTask(decoratedRun, w);
    Disposable d = w.schedulePeriodically(periodicTask, initialDelay, period, unit);
    if (d == EmptyDisposable.INSTANCE) {
        return d;
    }
    return periodicTask;
}
Also used : Disposable(io.reactivex.disposables.Disposable) NonNull(io.reactivex.annotations.NonNull)

Example 24 with NonNull

use of io.reactivex.annotations.NonNull in project RxFacebook by YouClap.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    callbackManager = CallbackManager.Factory.create();
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            List<String> perm = new ArrayList<>();
            perm.add("email");
            perm.add("public_profile");
            RxFacebookLogin.logInWithReadPermissions(perm).subscribe(new Consumer<LoginResult>() {

                @Override
                public void accept(@NonNull LoginResult loginResult) throws Exception {
                    Log.d(LOG_TAG, "accept " + loginResult.getAccessToken());
                }
            }, new Consumer<Throwable>() {

                @Override
                public void accept(@NonNull Throwable throwable) throws Exception {
                    Log.e(LOG_TAG, "error ", throwable);
                }
            }, new Action() {

                @Override
                public void run() throws Exception {
                    Log.e(LOG_TAG, "onCompleted");
                }
            });
        }
    });
}
Also used : Action(io.reactivex.functions.Action) Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) LoginResult(com.facebook.login.LoginResult) FloatingActionButton(android.support.design.widget.FloatingActionButton) ArrayList(java.util.ArrayList) List(java.util.List) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 25 with NonNull

use of io.reactivex.annotations.NonNull in project Varis-Android by dkhmelenko.

the class BuildsDetailsPresenter method startLoadingData.

/**
     * Starts loading data
     *
     * @param intentUrl Intent URL
     * @param repoSlug  Repository slug
     * @param buildId   Build ID
     */
public void startLoadingData(String intentUrl, String repoSlug, long buildId) {
    mRepoSlug = repoSlug;
    mBuildId = buildId;
    Single<BuildDetails> buildDetailsSingle;
    if (!TextUtils.isEmpty(intentUrl)) {
        buildDetailsSingle = mRawClient.singleRequest(intentUrl).doOnSuccess(response -> {
            String redirectUrl = intentUrl;
            if (response.isRedirect()) {
                redirectUrl = response.header("Location", "");
            }
            parseIntentUrl(redirectUrl);
        }).flatMap(new Function<okhttp3.Response, SingleSource<BuildDetails>>() {

            @Override
            public SingleSource<BuildDetails> apply(@NonNull okhttp3.Response response) throws Exception {
                return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
            }
        });
    } else {
        buildDetailsSingle = mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
    }
    Disposable subscription = buildDetailsSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
        if (throwable == null) {
            handleBuildDetails(buildDetails);
        } else {
            handleLoadingFailed(throwable);
        }
    });
    mSubscriptions.add(subscription);
    getView().showProgress();
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull)

Aggregations

NonNull (io.reactivex.annotations.NonNull)39 Disposable (io.reactivex.disposables.Disposable)17 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)15 Consumer (io.reactivex.functions.Consumer)14 Function (io.reactivex.functions.Function)13 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)6 OnClick (butterknife.OnClick)5 List (java.util.List)5 RequestBody (okhttp3.RequestBody)5 ObservableEmitter (io.reactivex.ObservableEmitter)4 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Headers (okhttp3.Headers)3 View (android.view.View)2 ANError (com.androidnetworking.error.ANError)2 User (com.khmelenko.lab.varis.network.response.User)2 LzyResponse (com.lzy.demo.model.LzyResponse)2 ServerModel (com.lzy.demo.model.ServerModel)2 Action (io.reactivex.functions.Action)2