All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hu.akarnokd.rxjava3.swing.RxSwingPlugins Maven / Gradle / Ivy

/*
 * Copyright 2017-2018 David Karnok
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package hu.akarnokd.rxjava3.swing;

import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.internal.util.ExceptionHelper;

/**
 * Static methods to override some of the RxSwing infrastructure, such as
 * the scheduler and task hook.
 */
public final class RxSwingPlugins {

    private static volatile Function onSchedule;

    private static volatile Function onEdtScheduler;

    @SuppressWarnings("rawtypes")
    private static volatile Function onAssembly;

    /** Utility class. */
    private RxSwingPlugins() {
        throw new IllegalStateException("No instances!");
    }

    public static Runnable onSchedule(Runnable run) {
        Function f = onSchedule;
        if (f == null) {
            return run;
        }
        try {
            return f.apply(run);
        } catch (Throwable ex) {
            throw ExceptionHelper.wrapOrThrow(ex);
        }
    }

    public static Scheduler onEdtScheduler(Scheduler original) {
        Function f = onEdtScheduler;
        if (f == null) {
            return original;
        }
        try {
            return f.apply(original);
        } catch (Throwable ex) {
            throw ExceptionHelper.wrapOrThrow(ex);
        }
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static  Observable onAssembly(Observable original) {
        Function f = onAssembly;
        if (f == null) {
            return original;
        }
        try {
            return f.apply(original);
        } catch (Throwable ex) {
            throw ExceptionHelper.wrapOrThrow(ex);
        }
    }

    public static Function getOnSchedule() {
        return onSchedule;
    }

    public static void setOnSchedule(Function handler) {
        onSchedule = handler;
    }

    public static Function getOnEdtScheduler() {
        return onEdtScheduler;
    }

    public static void setOnEdtScheduler(Function handler) {
        onEdtScheduler = handler;
    }

    @SuppressWarnings("rawtypes")
    public static Function getOnAssembly() {
        return onAssembly;
    }

    @SuppressWarnings("rawtypes")
    public static void setOnAssembly(Function handler) {
        onAssembly = handler;
    }

    public static void reset() {
        onSchedule = null;
        onEdtScheduler = null;
        onAssembly = null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy