@@ -336,7 +336,10 @@ public void connect(Consumer<? super Disposable> connection) {
336
336
}
337
337
338
338
@ SuppressWarnings ("rawtypes" )
339
- static final class ReplaySubscriber <T > implements Subscriber <T >, Disposable {
339
+ static final class ReplaySubscriber <T >
340
+ extends AtomicReference <Subscription >
341
+ implements Subscriber <T >, Disposable {
342
+ private static final long serialVersionUID = 7224554242710036740L ;
340
343
/** Holds notifications from upstream. */
341
344
final ReplayBuffer <T > buffer ;
342
345
/** Indicates this Subscriber received a terminal event. */
@@ -361,8 +364,6 @@ static final class ReplaySubscriber<T> implements Subscriber<T>, Disposable {
361
364
long maxChildRequested ;
362
365
/** Counts the outstanding upstream requests until the producer arrives. */
363
366
long maxUpstreamRequested ;
364
- /** The upstream producer. */
365
- volatile Subscription subscription ;
366
367
367
368
@ SuppressWarnings ("unchecked" )
368
369
ReplaySubscriber (ReplayBuffer <T > buffer ) {
@@ -386,7 +387,7 @@ public void dispose() {
386
387
// current.compareAndSet(ReplaySubscriber.this, null);
387
388
// we don't care if it fails because it means the current has
388
389
// been replaced in the meantime
389
- subscription .cancel ();
390
+ SubscriptionHelper .cancel (this );
390
391
}
391
392
392
393
/**
@@ -476,8 +477,7 @@ void remove(InnerSubscription<T> p) {
476
477
477
478
@ Override
478
479
public void onSubscribe (Subscription p ) {
479
- if (SubscriptionHelper .validate (subscription , p )) {
480
- subscription = p ;
480
+ if (SubscriptionHelper .setOnce (this , p )) {
481
481
manageRequests ();
482
482
for (InnerSubscription <T > rp : subscribers .get ()) {
483
483
buffer .replay (rp );
@@ -548,7 +548,7 @@ void manageRequests() {
548
548
}
549
549
550
550
long ur = maxUpstreamRequested ;
551
- Subscription p = subscription ;
551
+ Subscription p = get () ;
552
552
553
553
long diff = maxTotalRequests - ri ;
554
554
if (diff != 0L ) {
0 commit comments