├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── mindorks
│ │ │ └── sample
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── mindorks
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── mindorks
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── rxps
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── mindorks
│ └── scheduler
│ ├── Priority.java
│ ├── internal
│ ├── InternalRunnable.java
│ ├── PrioritySchedulerWorker.java
│ └── CustomPriorityScheduler.java
│ └── RxPS.java
├── settings.gradle
├── assets
└── rxps.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── CONTRIBUTING.md
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rxps/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':rxps'
2 |
--------------------------------------------------------------------------------
/assets/rxps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/assets/rxps.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amitshekhariitbhu/RxJavaPriorityScheduler/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 | /.idea
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/rxps/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | api 'io.reactivex.rxjava2:rxjava:2.1.16'
6 | }
7 |
8 | sourceCompatibility = "1.7"
9 | targetCompatibility = "1.7"
10 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | 1. Fork it!
4 | 2. Checkout the development branch: `git checkout development`
5 | 3. Create your feature branch: `git checkout -b my-new-feature`
6 | 4. Add your changes to the index: `git add .`
7 | 5. Commit your changes: `git commit -m 'Add some feature'`
8 | 6. Push to the branch: `git push origin my-new-feature`
9 | 7. Submit a pull request against the `development` branch
--------------------------------------------------------------------------------
/rxps/src/main/java/com/mindorks/scheduler/Priority.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.mindorks.scheduler;
4 |
5 | public enum Priority {
6 |
7 | /**
8 | * Lowest priority level.
9 | */
10 | LOW,
11 |
12 | /**
13 | * Medium priority level.
14 | */
15 | MEDIUM,
16 |
17 | /**
18 | * Highest priority level.
19 | */
20 | HIGH,
21 |
22 | /**
23 | * Immediate priority level.
24 | */
25 | IMMEDIATE
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/test/java/com/mindorks/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.mindorks.sample;
4 |
5 | import org.junit.Test;
6 |
7 | import static org.junit.Assert.*;
8 |
9 | /**
10 | * Example local unit test, which will execute on the development machine (host).
11 | *
12 | * @see Testing documentation
13 | */
14 | public class ExampleUnitTest {
15 | @Test
16 | public void addition_isCorrect() {
17 | assertEquals(4, 2 + 2);
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | RxJavaPriorityScheduler
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/mindorks/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.mindorks.sample;
4 |
5 | import android.content.Context;
6 | import android.support.test.InstrumentationRegistry;
7 | import android.support.test.runner.AndroidJUnit4;
8 |
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 |
12 | import static org.junit.Assert.*;
13 |
14 | /**
15 | * Instrumented test, which will execute on an Android device.
16 | *
17 | * @see Testing documentation
18 | */
19 | @RunWith(AndroidJUnit4.class)
20 | public class ExampleInstrumentedTest {
21 | @Test
22 | public void useAppContext() {
23 | // Context of the app under test.
24 | Context appContext = InstrumentationRegistry.getTargetContext();
25 |
26 | assertEquals("com.mindorks.sample", appContext.getPackageName());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #3F51B5
20 | #303F9F
21 | #FF4081
22 |
23 |
--------------------------------------------------------------------------------
/rxps/src/main/java/com/mindorks/scheduler/internal/InternalRunnable.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.mindorks.scheduler.internal;
4 |
5 | import com.mindorks.scheduler.Priority;
6 |
7 | public final class InternalRunnable implements Runnable, Comparable {
8 |
9 | private final Runnable runnable;
10 | private final Priority priority;
11 | private final int sequenceNumber;
12 |
13 | InternalRunnable(Runnable runnable, Priority priority, int sequenceNumber) {
14 | this.runnable = runnable;
15 | this.priority = priority;
16 | this.sequenceNumber = sequenceNumber;
17 | }
18 |
19 | @Override
20 | public void run() {
21 | runnable.run();
22 | }
23 |
24 | @Override
25 | public int compareTo(InternalRunnable other) {
26 | return (priority == other.priority ? sequenceNumber - other.sequenceNumber
27 | : other.priority.ordinal() - priority.ordinal());
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.mindorks.sample"
7 | minSdkVersion 19
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
25 | implementation project(':rxps')
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2018 MINDORKS NEXTGEN PRIVATE LIMITED
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | # Project-wide Gradle settings.
18 | # IDE (e.g. Android Studio) users:
19 | # Gradle settings configured through the IDE *will override*
20 | # any settings specified in this file.
21 | # For more details on how to configure your build environment visit
22 | # http://www.gradle.org/docs/current/userguide/build_environment.html
23 | # Specifies the JVM arguments used for the daemon process.
24 | # The setting is particularly useful for tweaking memory settings.
25 | org.gradle.jvmargs=-Xmx1536m
26 | # When configured, Gradle will run in incubating parallel mode.
27 | # This option should only be used with decoupled projects. More details, visit
28 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
29 | # org.gradle.parallel=true
30 |
--------------------------------------------------------------------------------
/rxps/src/main/java/com/mindorks/scheduler/RxPS.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.mindorks.scheduler;
4 |
5 | import com.mindorks.scheduler.internal.CustomPriorityScheduler;
6 |
7 | import io.reactivex.Scheduler;
8 |
9 | public final class RxPS {
10 |
11 | private static RxPS instance;
12 | private CustomPriorityScheduler priorityScheduler;
13 |
14 | private RxPS() {
15 | this.priorityScheduler = CustomPriorityScheduler.create();
16 | }
17 |
18 | private static RxPS getInstance() {
19 | if (instance == null) {
20 | synchronized (RxPS.class) {
21 | if (instance == null) {
22 | instance = new RxPS();
23 | }
24 | }
25 | }
26 | return instance;
27 | }
28 |
29 | private CustomPriorityScheduler getPriorityScheduler() {
30 | return priorityScheduler;
31 | }
32 |
33 | public static Scheduler get(Priority priority) {
34 | return getInstance().getPriorityScheduler().get(priority);
35 | }
36 |
37 | public static Scheduler low() {
38 | return get(Priority.LOW);
39 | }
40 |
41 | public static Scheduler medium() {
42 | return get(Priority.MEDIUM);
43 | }
44 |
45 | public static Scheduler high() {
46 | return get(Priority.HIGH);
47 | }
48 |
49 | public static Scheduler immediate() {
50 | return get(Priority.IMMEDIATE);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
33 |
34 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mindorks/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindorks.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 |
7 | import com.mindorks.scheduler.RxPS;
8 |
9 | import io.reactivex.Observable;
10 | import io.reactivex.ObservableEmitter;
11 | import io.reactivex.ObservableOnSubscribe;
12 | import io.reactivex.Observer;
13 | import io.reactivex.disposables.Disposable;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | private static final String TAG = "MainActivity";
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 |
24 | // simulate so many long tasks
25 | for (int i = 0; i <= 10; i++) {
26 | getObservable("low-priority-task : " + i)
27 | .subscribeOn(RxPS.low())
28 | .subscribe(getObserver());
29 |
30 | getObservable("medium-priority-task : " + i)
31 | .subscribeOn(RxPS.medium())
32 | .subscribe(getObserver());
33 |
34 | getObservable("high-priority-task : " + i)
35 | .subscribeOn(RxPS.high())
36 | .subscribe(getObserver());
37 |
38 | getObservable("immediate-priority-task : " + i)
39 | .subscribeOn(RxPS.immediate())
40 | .subscribe(getObserver());
41 | }
42 | }
43 |
44 | private Observable getObservable(final String value) {
45 | return Observable.create(new ObservableOnSubscribe() {
46 | @Override
47 | public void subscribe(ObservableEmitter emitter) throws Exception {
48 | // simulate long task
49 | Thread.sleep(3000);
50 | emitter.onNext(value);
51 | emitter.onComplete();
52 | }
53 | });
54 | }
55 |
56 | private Observer getObserver() {
57 | return new Observer() {
58 | @Override
59 | public void onSubscribe(Disposable d) {
60 |
61 | }
62 |
63 | @Override
64 | public void onNext(String value) {
65 | Log.d(TAG, "onNext : The value is " + value);
66 | }
67 |
68 | @Override
69 | public void onError(Throwable e) {
70 |
71 | }
72 |
73 | @Override
74 | public void onComplete() {
75 |
76 | }
77 | };
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
28 |
29 |
35 |
38 |
41 |
42 |
43 |
44 |
50 |
51 |
--------------------------------------------------------------------------------
/rxps/src/main/java/com/mindorks/scheduler/internal/PrioritySchedulerWorker.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.mindorks.scheduler.internal;
4 |
5 |
6 | import com.mindorks.scheduler.Priority;
7 |
8 | import java.util.concurrent.Future;
9 | import java.util.concurrent.PriorityBlockingQueue;
10 | import java.util.concurrent.TimeUnit;
11 |
12 | import io.reactivex.Scheduler;
13 | import io.reactivex.disposables.CompositeDisposable;
14 | import io.reactivex.disposables.Disposable;
15 | import io.reactivex.internal.schedulers.ScheduledRunnable;
16 |
17 | public final class PrioritySchedulerWorker extends Scheduler.Worker {
18 |
19 | private final CompositeDisposable compositeDisposable = new CompositeDisposable();
20 | private final PriorityBlockingQueue priorityBlockingQueue;
21 | private final Priority priority;
22 | private final int sequenceNumber;
23 |
24 | PrioritySchedulerWorker(PriorityBlockingQueue priorityBlockingQueue, Priority priority, int sequenceNumber) {
25 | this.priorityBlockingQueue = priorityBlockingQueue;
26 | this.priority = priority;
27 | this.sequenceNumber = sequenceNumber;
28 | }
29 |
30 | @Override
31 | public Disposable schedule(Runnable action) {
32 | return schedule(action, 0, TimeUnit.MILLISECONDS);
33 | }
34 |
35 | @Override
36 | public Disposable schedule(Runnable run, long delayTime, TimeUnit unit) {
37 |
38 | final InternalRunnable comparableRunnable = new InternalRunnable(run, priority, sequenceNumber);
39 |
40 | final ScheduledRunnable scheduledRunnable = new ScheduledRunnable(comparableRunnable, compositeDisposable);
41 | scheduledRunnable.setFuture(new Future