26
26
import rx .Observable .OnSubscribe ;
27
27
import rx .Observable .Operator ;
28
28
import rx .Subscriber ;
29
+ import rx .Subscription ;
29
30
import rx .functions .Action0 ;
30
31
import rx .observables .GroupedObservable ;
31
- import rx .subscriptions .ChainedSubscription ;
32
32
import rx .subscriptions .Subscriptions ;
33
33
34
34
public final class OperatorPivot <K1 , K2 , T > implements Operator <GroupedObservable <K2 , GroupedObservable <K1 , T >>, GroupedObservable <K1 , GroupedObservable <K2 , T >>> {
35
35
36
36
@ Override
37
37
public Subscriber <? super GroupedObservable <K1 , GroupedObservable <K2 , T >>> call (final Subscriber <? super GroupedObservable <K2 , GroupedObservable <K1 , T >>> child ) {
38
38
final AtomicReference <State > state = new AtomicReference <State >(State .create ());
39
- final PivotSubscriber <K1 , K2 , T > pivotSubscriber = new PivotSubscriber <K1 , K2 , T >(new ChainedSubscription (), child , state );
39
+ final PivotSubscriber <K1 , K2 , T > pivotSubscriber = new PivotSubscriber <K1 , K2 , T >(child , state );
40
40
child .add (Subscriptions .create (new Action0 () {
41
41
42
42
@ Override
@@ -61,21 +61,14 @@ public void call() {
61
61
}
62
62
63
63
private static final class PivotSubscriber <K1 , K2 , T > extends Subscriber <GroupedObservable <K1 , GroupedObservable <K2 , T >>> {
64
- /*
65
- * needs to decouple the subscription as the inner subscriptions need a separate lifecycle
66
- * and will unsubscribe on this parent if they are all unsubscribed
67
- */
68
- private final ChainedSubscription parentSubscription ;
69
64
private final Subscriber <? super GroupedObservable <K2 , GroupedObservable <K1 , T >>> child ;
70
65
private final AtomicReference <State > state ;
71
66
private final GroupState <K1 , K2 , T > groups ;
72
67
73
- private PivotSubscriber (ChainedSubscription parentSubscription , Subscriber <? super GroupedObservable <K2 , GroupedObservable <K1 , T >>> child , AtomicReference <State > state ) {
74
- super (parentSubscription );
75
- this .parentSubscription = parentSubscription ;
68
+ private PivotSubscriber (Subscriber <? super GroupedObservable <K2 , GroupedObservable <K1 , T >>> child , AtomicReference <State > state ) {
76
69
this .child = child ;
77
70
this .state = state ;
78
- this .groups = new GroupState <K1 , K2 , T >(parentSubscription , child );
71
+ this .groups = new GroupState <K1 , K2 , T >(this , child );
79
72
}
80
73
81
74
@ Override
@@ -102,7 +95,7 @@ public void onError(Throwable e) {
102
95
@ Override
103
96
public void onNext (final GroupedObservable <K1 , GroupedObservable <K2 , T >> k1Group ) {
104
97
groups .startK1Group (state , k1Group .getKey ());
105
- k1Group .unsafeSubscribe (new Subscriber <GroupedObservable <K2 , T >>(parentSubscription ) {
98
+ k1Group .unsafeSubscribe (new Subscriber <GroupedObservable <K2 , T >>(this ) {
106
99
107
100
@ Override
108
101
public void onCompleted () {
@@ -124,7 +117,7 @@ public void onNext(final GroupedObservable<K2, T> k2Group) {
124
117
// we have been unsubscribed
125
118
return ;
126
119
}
127
- k2Group .unsafeSubscribe (new Subscriber <T >(parentSubscription ) {
120
+ k2Group .unsafeSubscribe (new Subscriber <T >(this ) {
128
121
129
122
@ Override
130
123
public void onCompleted () {
@@ -158,16 +151,15 @@ public void onNext(T t) {
158
151
private static final class GroupState <K1 , K2 , T > {
159
152
private final ConcurrentHashMap <KeyPair <K1 , K2 >, Inner <K1 , K2 , T >> innerSubjects = new ConcurrentHashMap <KeyPair <K1 , K2 >, Inner <K1 , K2 , T >>();
160
153
private final ConcurrentHashMap <K2 , Outer <K1 , K2 , T >> outerSubjects = new ConcurrentHashMap <K2 , Outer <K1 , K2 , T >>();
161
- private final ChainedSubscription parentSubscription ;
154
+ private final Subscription parentSubscription ;
162
155
private final Subscriber <? super GroupedObservable <K2 , GroupedObservable <K1 , T >>> child ;
163
156
/** Indicates a terminal state. */
164
157
volatile int completed ;
165
158
/** Field updater for completed. */
166
159
@ SuppressWarnings ("rawtypes" )
167
- static final AtomicIntegerFieldUpdater <GroupState > COMPLETED_UPDATER
168
- = AtomicIntegerFieldUpdater .newUpdater (GroupState .class , "completed" );
160
+ static final AtomicIntegerFieldUpdater <GroupState > COMPLETED_UPDATER = AtomicIntegerFieldUpdater .newUpdater (GroupState .class , "completed" );
169
161
170
- public GroupState (ChainedSubscription parentSubscription , Subscriber <? super GroupedObservable <K2 , GroupedObservable <K1 , T >>> child ) {
162
+ public GroupState (Subscription parentSubscription , Subscriber <? super GroupedObservable <K2 , GroupedObservable <K1 , T >>> child ) {
171
163
this .parentSubscription = parentSubscription ;
172
164
this .child = child ;
173
165
}
0 commit comments