54
54
import rx .operators .OperationFilter ;
55
55
import rx .operators .OperationFinally ;
56
56
import rx .operators .OperationFlatMap ;
57
- import rx .operators .OperationGroupBy ;
57
+ import rx .operators .OperatorGroupBy ;
58
58
import rx .operators .OperationGroupByUntil ;
59
59
import rx .operators .OperationGroupJoin ;
60
60
import rx .operators .OperationInterval ;
159
159
*/
160
160
public class Observable <T > {
161
161
162
- final Action2 < Observer <? super T >, OperatorSubscription > f ;
162
+ final Action1 < Operator <? super T >> f ;
163
163
164
164
/**
165
165
* Observable with Function to execute when subscribed to.
@@ -171,7 +171,7 @@ public class Observable<T> {
171
171
* @param onSubscribe
172
172
* {@link OnSubscribeFunc} to be executed when {@link #subscribe(Observer)} is called
173
173
*/
174
- protected Observable (Action2 < Observer <? super T >, OperatorSubscription > f ) {
174
+ protected Observable (Action1 < Operator <? super T >> f ) {
175
175
this .f = f ;
176
176
}
177
177
@@ -189,31 +189,6 @@ public static interface OnSubscribeFunc<T> extends Function {
189
189
public Subscription onSubscribe (Observer <? super T > t1 );
190
190
}
191
191
192
- public static class OperatorSubscription implements Subscription {
193
-
194
- private final CompositeSubscription cs = new CompositeSubscription ();
195
-
196
- @ Override
197
- public void unsubscribe () {
198
- cs .unsubscribe ();
199
- }
200
-
201
- public static OperatorSubscription create (Subscription s ) {
202
- OperatorSubscription _s = new OperatorSubscription ();
203
- _s .add (s );
204
- return _s ;
205
- }
206
-
207
- public boolean isUnsubscribed () {
208
- return cs .isUnsubscribed ();
209
- }
210
-
211
- public void add (Subscription s ) {
212
- cs .add (s );
213
- }
214
-
215
- }
216
-
217
192
private final static RxJavaObservableExecutionHook hook = RxJavaPlugins .getInstance ().getObservableExecutionHook ();
218
193
219
194
/**
@@ -260,27 +235,27 @@ protected Observable(Action2<Observer<? super T>, OperatorSubscription> f) {
260
235
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#create">RxJava Wiki: create()</a>
261
236
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.create.aspx">MSDN: Observable.Create</a>
262
237
*/
263
- public final static <T > Observable <T > create (final Action2 < Observer <? super T >, OperatorSubscription > f ) {
238
+ public final static <T > Observable <T > create (final Action1 < Operator <? super T >> f ) {
264
239
return new Observable <T >(f );
265
240
}
266
241
267
242
public final static <T > Observable <T > create (final OnSubscribeFunc <T > func ) {
268
- return new Observable <T >(new Action2 < Observer <? super T >, OperatorSubscription >() {
243
+ return new Observable <T >(new Action1 < Operator <? super T >>() {
269
244
270
245
@ Override
271
- public void call (Observer <? super T > o , OperatorSubscription s ) {
272
- s .add (func .onSubscribe (o ));
246
+ public void call (Operator <? super T > o ) {
247
+ o .add (func .onSubscribe (o ));
273
248
}
274
249
275
250
});
276
251
}
277
252
278
- public <R > Observable <R > bind (final Func2 < Observer <? super R >, OperatorSubscription , Observer <? super T >> bind ) {
279
- return new Observable <R >(new Action2 < Observer <? super R >, OperatorSubscription >() {
253
+ public <R > Observable <R > bind (final Func1 < Operator <? super R >, Operator <? super T >> bind ) {
254
+ return new Observable <R >(new Action1 < Operator <? super R >>() {
280
255
281
256
@ Override
282
- public void call (Observer <? super R > o , OperatorSubscription s ) {
283
- f . call (bind .call (o , s ), s );
257
+ public void call (Operator <? super R > o ) {
258
+ subscribe (bind .call (o ) );
284
259
}
285
260
});
286
261
}
@@ -2878,7 +2853,7 @@ public final static <T> Observable<T> synchronize(Observable<T> source) {
2878
2853
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229435.aspx">MSDN: Observable.Timer</a>
2879
2854
*/
2880
2855
public final static Observable <Long > timer (long initialDelay , long period , TimeUnit unit ) {
2881
- return timer (initialDelay , period , unit , Schedulers .threadPoolForComputation ());
2856
+ return timer (initialDelay , period , unit , Schedulers .computation ());
2882
2857
}
2883
2858
2884
2859
/**
@@ -2917,7 +2892,7 @@ public final static Observable<Long> timer(long initialDelay, long period, TimeU
2917
2892
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#timer">RxJava wiki: timer()</a>
2918
2893
*/
2919
2894
public final static Observable <Long > timer (long delay , TimeUnit unit ) {
2920
- return timer (delay , unit , Schedulers .threadPoolForComputation ());
2895
+ return timer (delay , unit , Schedulers .computation ());
2921
2896
}
2922
2897
2923
2898
/**
@@ -4299,7 +4274,7 @@ public final <U> Observable<T> delay(Func1<? super T, ? extends Observable<U>> i
4299
4274
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229810.aspx">MSDN: Observable.Delay</a>
4300
4275
*/
4301
4276
public final Observable <T > delay (long delay , TimeUnit unit ) {
4302
- return OperationDelay .delay (this , delay , unit , Schedulers .threadPoolForComputation ());
4277
+ return OperationDelay .delay (this , delay , unit , Schedulers .computation ());
4303
4278
}
4304
4279
4305
4280
/**
@@ -4336,7 +4311,7 @@ public final Observable<T> delay(long delay, TimeUnit unit, Scheduler scheduler)
4336
4311
* amount
4337
4312
*/
4338
4313
public final Observable <T > delaySubscription (long delay , TimeUnit unit ) {
4339
- return delaySubscription (delay , unit , Schedulers .threadPoolForComputation ());
4314
+ return delaySubscription (delay , unit , Schedulers .computation ());
4340
4315
}
4341
4316
4342
4317
/**
@@ -4795,7 +4770,7 @@ public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? e
4795
4770
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#groupby-and-groupbyuntil">RxJava Wiki: groupBy</a>
4796
4771
*/
4797
4772
public final <K > Observable <GroupedObservable <K , T >> groupBy (final Func1 <? super T , ? extends K > keySelector ) {
4798
- return create ( OperationGroupBy . groupBy ( this , keySelector ));
4773
+ return bind ( new OperatorGroupBy < K , T >( keySelector ));
4799
4774
}
4800
4775
4801
4776
/**
@@ -4819,7 +4794,7 @@ public final <K> Observable<GroupedObservable<K, T>> groupBy(final Func1<? super
4819
4794
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#groupby-and-groupbyuntil">RxJava Wiki: groupBy</a>
4820
4795
*/
4821
4796
public final <K , R > Observable <GroupedObservable <K , R >> groupBy (final Func1 <? super T , ? extends K > keySelector , final Func1 <? super T , ? extends R > elementSelector ) {
4822
- return create ( OperationGroupBy . groupBy ( this , keySelector , elementSelector )) ;
4797
+ return null ;
4823
4798
}
4824
4799
4825
4800
/**
@@ -5936,7 +5911,7 @@ public final Subject<T, T> call() {
5936
5911
* @see <a href="http://msdn.microsoft.com/en-us/library/hh228952.aspx">MSDN: Observable.Replay</a>
5937
5912
*/
5938
5913
public final <R > Observable <R > replay (Func1 <? super Observable <T >, ? extends Observable <R >> selector , int bufferSize , long time , TimeUnit unit ) {
5939
- return replay (selector , bufferSize , time , unit , Schedulers .threadPoolForComputation ());
5914
+ return replay (selector , bufferSize , time , unit , Schedulers .computation ());
5940
5915
}
5941
5916
5942
5917
/**
@@ -6036,7 +6011,7 @@ public final Subject<T, T> call() {
6036
6011
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229526.aspx">MSDN: Observable.Replay</a>
6037
6012
*/
6038
6013
public final <R > Observable <R > replay (Func1 <? super Observable <T >, ? extends Observable <R >> selector , long time , TimeUnit unit ) {
6039
- return replay (selector , time , unit , Schedulers .threadPoolForComputation ());
6014
+ return replay (selector , time , unit , Schedulers .computation ());
6040
6015
}
6041
6016
6042
6017
/**
@@ -6139,7 +6114,7 @@ public final ConnectableObservable<T> replay(int bufferSize) {
6139
6114
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229874.aspx">MSDN: Observable.Replay</a>
6140
6115
*/
6141
6116
public final ConnectableObservable <T > replay (int bufferSize , long time , TimeUnit unit ) {
6142
- return replay (bufferSize , time , unit , Schedulers .threadPoolForComputation ());
6117
+ return replay (bufferSize , time , unit , Schedulers .computation ());
6143
6118
}
6144
6119
6145
6120
/**
@@ -6209,7 +6184,7 @@ public final ConnectableObservable<T> replay(int bufferSize, Scheduler scheduler
6209
6184
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229232.aspx">MSDN: Observable.Replay</a>
6210
6185
*/
6211
6186
public final ConnectableObservable <T > replay (long time , TimeUnit unit ) {
6212
- return replay (time , unit , Schedulers .threadPoolForComputation ());
6187
+ return replay (time , unit , Schedulers .computation ());
6213
6188
}
6214
6189
6215
6190
/**
@@ -6516,7 +6491,7 @@ public final Observable<T> skip(int num) {
6516
6491
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#skip">RxJava Wiki: skip()</a>
6517
6492
*/
6518
6493
public final Observable <T > skip (long time , TimeUnit unit ) {
6519
- return skip (time , unit , Schedulers .threadPoolForComputation ());
6494
+ return skip (time , unit , Schedulers .computation ());
6520
6495
}
6521
6496
6522
6497
/**
@@ -6578,7 +6553,7 @@ public final Observable<T> skipLast(int count) {
6578
6553
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211750.aspx">MSDN: Observable.SkipLast</a>
6579
6554
*/
6580
6555
public final Observable <T > skipLast (long time , TimeUnit unit ) {
6581
- return skipLast (time , unit , Schedulers .threadPoolForComputation ());
6556
+ return skipLast (time , unit , Schedulers .computation ());
6582
6557
}
6583
6558
6584
6559
/**
@@ -6929,8 +6904,8 @@ public final Observable<T> startWith(T[] values, Scheduler scheduler) {
6929
6904
}
6930
6905
6931
6906
// TODO should this be called `observe` instead of `subscribe`?
6932
- public final void subscribe (Observer <? super T > o , Func0 < OperatorSubscription > sf ) {
6933
- f .call (o , sf . call () );
6907
+ public final void subscribe (Operator <? super T > o ) {
6908
+ f .call (o );
6934
6909
}
6935
6910
6936
6911
/**
@@ -7166,7 +7141,7 @@ public final Subscription subscribe(final Action1<? super T> onNext, Scheduler s
7166
7141
*/
7167
7142
public final Subscription subscribe (Observer <? super T > observer ) {
7168
7143
// allow the hook to intercept and/or decorate
7169
- Action2 < Observer <? super T >, OperatorSubscription > onSubscribeFunction = hook .onSubscribeStart (this , f );
7144
+ Action1 < Operator <? super T >> onSubscribeFunction = hook .onSubscribeStart (this , f );
7170
7145
// validate and proceed
7171
7146
if (observer == null ) {
7172
7147
throw new IllegalArgumentException ("observer can not be null" );
@@ -7176,17 +7151,20 @@ public final Subscription subscribe(Observer<? super T> observer) {
7176
7151
// the subscribe function can also be overridden but generally that's not the appropriate approach so I won't mention that in the exception
7177
7152
}
7178
7153
try {
7179
- OperatorSubscription os = new OperatorSubscription () ;
7154
+ Operator <? super T > op = null ;
7180
7155
/**
7181
7156
* See https://github.com/Netflix/RxJava/issues/216 for discussion on "Guideline 6.4: Protect calls to user code from within an operator"
7182
7157
*/
7183
7158
if (isInternalImplementation (observer )) {
7184
- onSubscribeFunction .call (observer , os );
7159
+ op = Operator .create (observer , new CompositeSubscription ());
7160
+ onSubscribeFunction .call (op );
7185
7161
} else {
7186
- SafeObservableSubscription subscription = new SafeObservableSubscription (os );
7187
- onSubscribeFunction .call (new SafeObserver <T >(subscription , observer ), os );
7162
+ // TODO this doesn't seem correct any longer with the Operator and injecting of CompositeSubscription
7163
+ SafeObservableSubscription subscription = new SafeObservableSubscription (op );
7164
+ op = Operator .create (new SafeObserver <T >(subscription , observer ), new CompositeSubscription ());
7165
+ onSubscribeFunction .call (op );
7188
7166
}
7189
- return hook .onSubscribeReturn (this , os );
7167
+ return hook .onSubscribeReturn (this , op );
7190
7168
} catch (OnErrorNotImplementedException e ) {
7191
7169
// special handling when onError is not implemented ... we just rethrow
7192
7170
throw e ;
@@ -7426,7 +7404,7 @@ public final Observable<T> take(final int num) {
7426
7404
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#take">RxJava Wiki: take()</a>
7427
7405
*/
7428
7406
public final Observable <T > take (long time , TimeUnit unit ) {
7429
- return take (time , unit , Schedulers .threadPoolForComputation ());
7407
+ return take (time , unit , Schedulers .computation ());
7430
7408
}
7431
7409
7432
7410
/**
@@ -7517,7 +7495,7 @@ public final Observable<T> takeLast(final int count) {
7517
7495
* were emitted in a specified window of time before the Observable completed.
7518
7496
*/
7519
7497
public final Observable <T > takeLast (int count , long time , TimeUnit unit ) {
7520
- return takeLast (count , time , unit , Schedulers .threadPoolForComputation ());
7498
+ return takeLast (count , time , unit , Schedulers .computation ());
7521
7499
}
7522
7500
7523
7501
/**
@@ -7560,7 +7538,7 @@ public final Observable<T> takeLast(int count, long time, TimeUnit unit, Schedul
7560
7538
* the window of time before the Observable completed specified by {@code time}
7561
7539
*/
7562
7540
public final Observable <T > takeLast (long time , TimeUnit unit ) {
7563
- return takeLast (time , unit , Schedulers .threadPoolForComputation ());
7541
+ return takeLast (time , unit , Schedulers .computation ());
7564
7542
}
7565
7543
7566
7544
/**
@@ -8735,10 +8713,10 @@ public final <T2, R> Observable<R> zip(Observable<? extends T2> other, Func2<? s
8735
8713
*/
8736
8714
private static class NeverObservable <T > extends Observable <T > {
8737
8715
public NeverObservable () {
8738
- super (new Action2 < Observer <? super T >, OperatorSubscription >() {
8716
+ super (new Action1 < Operator <? super T >>() {
8739
8717
8740
8718
@ Override
8741
- public void call (Observer <? super T > observer , OperatorSubscription t2 ) {
8719
+ public void call (Operator <? super T > observer ) {
8742
8720
// do nothing
8743
8721
}
8744
8722
@@ -8756,7 +8734,7 @@ public void call(Observer<? super T> observer, OperatorSubscription t2) {
8756
8734
private static class ThrowObservable <T > extends Observable <T > {
8757
8735
8758
8736
public ThrowObservable (final Throwable exception ) {
8759
- super (new Action2 < Observer <? super T >, OperatorSubscription >() {
8737
+ super (new Action1 < Operator <? super T >>() {
8760
8738
8761
8739
/**
8762
8740
* Accepts an {@link Observer} and calls its {@link Observer#onError onError} method.
@@ -8766,14 +8744,15 @@ public ThrowObservable(final Throwable exception) {
8766
8744
* @return a reference to the subscription
8767
8745
*/
8768
8746
@ Override
8769
- public void call (Observer <? super T > observer , OperatorSubscription t2 ) {
8747
+ public void call (Operator <? super T > observer ) {
8770
8748
observer .onError (exception );
8771
8749
}
8772
8750
8773
8751
});
8774
8752
}
8775
8753
}
8776
8754
8755
+ @ SuppressWarnings ("rawtypes" )
8777
8756
private final static ConcurrentHashMap <Class , Boolean > internalClassMap = new ConcurrentHashMap <Class , Boolean >();
8778
8757
8779
8758
/**
0 commit comments