26
26
import java .util .concurrent .locks .ReentrantLock ;
27
27
28
28
import rx .Observable ;
29
+ import rx .Observable .OnSubscribeFunc ;
29
30
import rx .Observer ;
30
31
import rx .Operator ;
31
32
import rx .Scheduler ;
32
33
import rx .Subscription ;
33
34
import rx .subjects .Subject ;
35
+ import rx .subscriptions .Subscriptions ;
34
36
import rx .util .Timestamped ;
35
37
import rx .util .functions .Action0 ;
36
38
import rx .util .functions .Action1 ;
37
- import rx .util .functions .Action2 ;
38
39
import rx .util .functions .Func1 ;
39
40
import rx .util .functions .Functions ;
40
41
@@ -62,8 +63,16 @@ public static <T> Subject<T, T> replayBuffered(int bufferSize) {
62
63
* propagated through the given wrapped subject.
63
64
*/
64
65
public static <T > Subject <T , T > createScheduledSubject (Subject <T , T > subject , Scheduler scheduler ) {
65
- Observable <T > observedOn = subject .observeOn (scheduler );
66
- SubjectWrapper <T > s = new SubjectWrapper <T >(subscriberOf (observedOn ), subject );
66
+ final Observable <T > observedOn = subject .observeOn (scheduler );
67
+ SubjectWrapper <T > s = new SubjectWrapper <T >(new Action1 <Operator <? super T >>() {
68
+
69
+ @ Override
70
+ public void call (Operator <? super T > o ) {
71
+ // TODO HACK between OnSubscribeFunc and Action1
72
+ subscriberOf (observedOn ).onSubscribe (o );
73
+ }
74
+
75
+ }, subject );
67
76
return s ;
68
77
}
69
78
@@ -129,19 +138,20 @@ public void call() {
129
138
state .onSubscription = state .onValueAdded ;
130
139
131
140
final CustomReplaySubject <T , Timestamped <T >, T > brs = new CustomReplaySubject <T , Timestamped <T >, T >(
132
- new CustomReplaySubjectSubscribeFunc <Timestamped <T >, T >(state ), state , timestamp );
141
+ new CustomReplaySubjectSubscribeFunc <Timestamped <T >, T >(state ), state , timestamp
142
+ );
133
143
134
144
return brs ;
135
145
}
136
146
137
147
/**
138
148
* Return an OnSubscribeFunc which delegates the subscription to the given observable.
139
149
*/
140
- public static <T > Action1 < Operator <? super T > > subscriberOf (final Observable <T > target ) {
141
- return new Action1 < Operator <? super T > >() {
150
+ public static <T > OnSubscribeFunc < T > subscriberOf (final Observable <T > target ) {
151
+ return new OnSubscribeFunc < T >() {
142
152
@ Override
143
- public void call ( Operator <? super T > t1 ) {
144
- target .subscribe (t1 );
153
+ public Subscription onSubscribe ( Observer <? super T > t1 ) {
154
+ return target .subscribe (t1 );
145
155
}
146
156
};
147
157
}
@@ -708,10 +718,17 @@ public static <T> CustomReplaySubject<T, T, T> create(int maxSize) {
708
718
protected final Func1 <? super TInput , ? extends TIntermediate > intermediateSelector ;
709
719
710
720
private CustomReplaySubject (
711
- Action1 < Operator <? super TResult > > onSubscribe ,
721
+ final Observable . OnSubscribeFunc < TResult > onSubscribe ,
712
722
ReplayState <TIntermediate , TResult > state ,
713
723
Func1 <? super TInput , ? extends TIntermediate > intermediateSelector ) {
714
- super (onSubscribe );
724
+ super (new Action1 <Operator <? super TResult >>() {
725
+
726
+ @ Override
727
+ public void call (Operator <? super TResult > o ) {
728
+ //TODO hack from OnSubscribeFunc to Action0
729
+ onSubscribe .onSubscribe (o );
730
+ }
731
+ });
715
732
this .state = state ;
716
733
this .intermediateSelector = intermediateSelector ;
717
734
}
@@ -782,7 +799,7 @@ protected void replayValues() {
782
799
* the value type of the observers subscribing to this subject
783
800
*/
784
801
protected static final class CustomReplaySubjectSubscribeFunc <TIntermediate , TResult >
785
- implements Action1 < Operator <? super TResult > > {
802
+ implements Observable . OnSubscribeFunc < TResult > {
786
803
787
804
private final ReplayState <TIntermediate , TResult > state ;
788
805
@@ -791,14 +808,14 @@ protected CustomReplaySubjectSubscribeFunc(ReplayState<TIntermediate, TResult> s
791
808
}
792
809
793
810
@ Override
794
- public void call ( Operator <? super TResult > op ) {
811
+ public Subscription onSubscribe ( Observer <? super TResult > t1 ) {
795
812
VirtualList <TIntermediate > values ;
796
813
Throwable error ;
797
814
state .lock ();
798
815
try {
799
816
if (!state .done ) {
800
817
state .onSubscription .call ();
801
- op . add ( state .addReplayer (op ) );
818
+ return state .addReplayer (t1 );
802
819
}
803
820
values = state .values ;
804
821
error = state .error ;
@@ -808,18 +825,18 @@ public void call(Operator<? super TResult> op) {
808
825
// fully replay the subject
809
826
for (int i = values .start (); i < values .end (); i ++) {
810
827
try {
811
- op .onNext (state .resultSelector .call (values .get (i )));
828
+ t1 .onNext (state .resultSelector .call (values .get (i )));
812
829
} catch (Throwable t ) {
813
- op .onError (t );
814
- return ;
830
+ t1 .onError (t );
831
+ return Subscriptions . empty () ;
815
832
}
816
833
}
817
834
if (error != null ) {
818
- op .onError (error );
835
+ t1 .onError (error );
819
836
} else {
820
- op .onCompleted ();
837
+ t1 .onCompleted ();
821
838
}
822
- return ;
839
+ return Subscriptions . empty () ;
823
840
}
824
841
}
825
842
}
0 commit comments