File tree 5 files changed +81
-24
lines changed
5 files changed +81
-24
lines changed Original file line number Diff line number Diff line change 13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- package rx .schedulers ;
16
+ package rx .internal . schedulers ;
17
17
18
18
import java .util .concurrent .*;
19
19
import java .util .concurrent .atomic .*;
20
20
21
21
import rx .*;
22
22
import rx .functions .Action0 ;
23
- import rx .internal .schedulers .*;
24
23
import rx .internal .util .RxThreadFactory ;
25
24
import rx .subscriptions .*;
26
25
27
- /* package */ final class CachedThreadScheduler extends Scheduler implements SchedulerLifecycle {
26
+ public final class CachedThreadScheduler extends Scheduler implements SchedulerLifecycle {
28
27
private static final String WORKER_THREAD_NAME_PREFIX = "RxCachedThreadScheduler-" ;
29
28
static final RxThreadFactory WORKER_THREAD_FACTORY =
30
29
new RxThreadFactory (WORKER_THREAD_NAME_PREFIX );
@@ -234,4 +233,4 @@ public void setExpirationTime(long expirationTime) {
234
233
this .expirationTime = expirationTime ;
235
234
}
236
235
}
237
- }
236
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright 2014 Netflix, Inc.
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
+ package rx .internal .schedulers ;
17
+
18
+ import rx .Scheduler ;
19
+ import rx .internal .util .RxThreadFactory ;
20
+
21
+ /**
22
+ * Schedules work on a new thread.
23
+ */
24
+ public final class NewThreadScheduler extends Scheduler {
25
+
26
+ private static final String THREAD_NAME_PREFIX = "RxNewThreadScheduler-" ;
27
+ private static final RxThreadFactory THREAD_FACTORY = new RxThreadFactory (THREAD_NAME_PREFIX );
28
+
29
+ public NewThreadScheduler () {
30
+ }
31
+
32
+ @ Override
33
+ public Worker createWorker () {
34
+ return new NewThreadWorker (THREAD_FACTORY );
35
+ }
36
+ }
Original file line number Diff line number Diff line change 17
17
package rx .plugins ;
18
18
19
19
import rx .Scheduler ;
20
+ import rx .annotations .Experimental ;
20
21
import rx .functions .Action0 ;
22
+ import rx .internal .schedulers .CachedThreadScheduler ;
23
+ import rx .internal .schedulers .EventLoopsScheduler ;
24
+ import rx .internal .schedulers .NewThreadScheduler ;
25
+ import rx .schedulers .Schedulers ;
21
26
22
27
/**
23
28
* This plugin class provides 2 ways to customize {@link Scheduler} functionality
35
40
*/
36
41
public class RxJavaSchedulersHook {
37
42
43
+ /**
44
+ * Create an instance of the default {@link Scheduler} used for {@link Schedulers#computation()}.
45
+ */
46
+ @ Experimental
47
+ public static Scheduler createComputationScheduler () {
48
+ return new EventLoopsScheduler ();
49
+ }
50
+
51
+ /**
52
+ * Create an instance of the default {@link Scheduler} used for {@link Schedulers#io()}.
53
+ */
54
+ @ Experimental
55
+ public static Scheduler createIoScheduler () {
56
+ return new CachedThreadScheduler ();
57
+ }
58
+
59
+ /**
60
+ * Create an instance of the default {@link Scheduler} used for {@link Schedulers#newThread()}.
61
+ */
62
+ @ Experimental
63
+ public static Scheduler createNewThreadScheduler () {
64
+ return new NewThreadScheduler ();
65
+ }
66
+
38
67
protected RxJavaSchedulersHook () {
39
68
40
69
}
Original file line number Diff line number Diff line change 16
16
package rx .schedulers ;
17
17
18
18
import rx .Scheduler ;
19
- import rx .internal .schedulers .NewThreadWorker ;
20
- import rx .internal .util .RxThreadFactory ;
21
19
22
20
/**
23
- * Schedules work on a new thread .
21
+ * @deprecated This type was never publicly instantiable. Use {@link Schedulers#newThread()} .
24
22
*/
23
+ @ Deprecated
25
24
public final class NewThreadScheduler extends Scheduler {
26
-
27
- private static final String THREAD_NAME_PREFIX = "RxNewThreadScheduler-" ;
28
- private static final RxThreadFactory THREAD_FACTORY = new RxThreadFactory (THREAD_NAME_PREFIX );
29
- private static final NewThreadScheduler INSTANCE = new NewThreadScheduler ();
30
-
31
- /* package */ static NewThreadScheduler instance () {
32
- return INSTANCE ;
33
- }
34
-
35
25
private NewThreadScheduler () {
36
-
26
+ throw new AssertionError ();
37
27
}
38
28
39
29
@ Override
40
30
public Worker createWorker () {
41
- return new NewThreadWorker ( THREAD_FACTORY ) ;
31
+ return null ;
42
32
}
43
33
}
Original file line number Diff line number Diff line change 19
19
import rx .internal .schedulers .*;
20
20
import rx .internal .util .RxRingBuffer ;
21
21
import rx .plugins .RxJavaPlugins ;
22
+ import rx .plugins .RxJavaSchedulersHook ;
22
23
23
24
import java .util .concurrent .Executor ;
24
25
@@ -34,25 +35,27 @@ public final class Schedulers {
34
35
private static final Schedulers INSTANCE = new Schedulers ();
35
36
36
37
private Schedulers () {
37
- Scheduler c = RxJavaPlugins .getInstance ().getSchedulersHook ().getComputationScheduler ();
38
+ RxJavaSchedulersHook hook = RxJavaPlugins .getInstance ().getSchedulersHook ();
39
+
40
+ Scheduler c = hook .getComputationScheduler ();
38
41
if (c != null ) {
39
42
computationScheduler = c ;
40
43
} else {
41
- computationScheduler = new EventLoopsScheduler ();
44
+ computationScheduler = RxJavaSchedulersHook . createComputationScheduler ();
42
45
}
43
46
44
- Scheduler io = RxJavaPlugins . getInstance (). getSchedulersHook () .getIOScheduler ();
47
+ Scheduler io = hook .getIOScheduler ();
45
48
if (io != null ) {
46
49
ioScheduler = io ;
47
50
} else {
48
- ioScheduler = new CachedThreadScheduler ();
51
+ ioScheduler = RxJavaSchedulersHook . createIoScheduler ();
49
52
}
50
53
51
- Scheduler nt = RxJavaPlugins . getInstance (). getSchedulersHook () .getNewThreadScheduler ();
54
+ Scheduler nt = hook .getNewThreadScheduler ();
52
55
if (nt != null ) {
53
56
newThreadScheduler = nt ;
54
57
} else {
55
- newThreadScheduler = NewThreadScheduler . instance ();
58
+ newThreadScheduler = RxJavaSchedulersHook . createNewThreadScheduler ();
56
59
}
57
60
}
58
61
You can’t perform that action at this time.
0 commit comments