@@ -259,7 +259,7 @@ public void onNext(Frame requestFrame) {
259
259
} else if (requestFrame .getType () == FrameType .CANCEL ) {
260
260
Subscription s ;
261
261
synchronized (Responder .this ) {
262
- s = cancellationSubscriptions .get (requestFrame . getStreamId () );
262
+ s = cancellationSubscriptions .get (streamId );
263
263
}
264
264
if (s != null ) {
265
265
s .cancel ();
@@ -268,7 +268,7 @@ public void onNext(Frame requestFrame) {
268
268
} else if (requestFrame .getType () == FrameType .REQUEST_N ) {
269
269
SubscriptionArbiter inFlightSubscription ;
270
270
synchronized (Responder .this ) {
271
- inFlightSubscription = inFlight .get (requestFrame . getStreamId () );
271
+ inFlightSubscription = inFlight .get (streamId );
272
272
}
273
273
if (inFlightSubscription != null ) {
274
274
long requestN = Frame .RequestN .requestN (requestFrame );
@@ -399,6 +399,7 @@ private Publisher<Frame> handleRequestResponse(
399
399
final RequestHandler requestHandler ,
400
400
final Int2ObjectHashMap <Subscription > cancellationSubscriptions ) {
401
401
402
+ final int streamId = requestFrame .getStreamId ();
402
403
return child -> {
403
404
Subscription s = new Subscription () {
404
405
@@ -408,8 +409,6 @@ private Publisher<Frame> handleRequestResponse(
408
409
@ Override
409
410
public void request (long n ) {
410
411
if (n > 0 && started .compareAndSet (false , true )) {
411
- final int streamId = requestFrame .getStreamId ();
412
-
413
412
try {
414
413
Publisher <Payload > responsePublisher =
415
414
requestHandler .handleRequestResponse (requestFrame );
@@ -477,13 +476,13 @@ public void cancel() {
477
476
478
477
private void cleanup () {
479
478
synchronized (Responder .this ) {
480
- cancellationSubscriptions .remove (requestFrame . getStreamId () );
479
+ cancellationSubscriptions .remove (streamId );
481
480
}
482
481
}
483
482
484
483
};
485
484
synchronized (Responder .this ) {
486
- cancellationSubscriptions .put (requestFrame . getStreamId () , s );
485
+ cancellationSubscriptions .put (streamId , s );
487
486
}
488
487
child .onSubscribe (s );
489
488
};
@@ -541,7 +540,7 @@ private Publisher<Frame> _handleRequestStream(
541
540
final Int2ObjectHashMap <Subscription > cancellationSubscriptions ,
542
541
final Int2ObjectHashMap <SubscriptionArbiter > inFlight ,
543
542
final boolean allowCompletion ) {
544
-
543
+ final int streamId = requestFrame . getStreamId ();
545
544
return child -> {
546
545
Subscription s = new Subscription () {
547
546
@@ -556,7 +555,6 @@ public void request(long n) {
556
555
}
557
556
if (started .compareAndSet (false , true )) {
558
557
arbiter .addTransportRequest (n );
559
- final int streamId = requestFrame .getStreamId ();
560
558
561
559
try {
562
560
Publisher <Payload > responses =
@@ -630,14 +628,14 @@ public void cancel() {
630
628
631
629
private void cleanup () {
632
630
synchronized (Responder .this ) {
633
- inFlight .remove (requestFrame . getStreamId () );
634
- cancellationSubscriptions .remove (requestFrame . getStreamId () );
631
+ inFlight .remove (streamId );
632
+ cancellationSubscriptions .remove (streamId );
635
633
}
636
634
}
637
635
638
636
};
639
637
synchronized (Responder .this ) {
640
- cancellationSubscriptions .put (requestFrame . getStreamId () , s );
638
+ cancellationSubscriptions .put (streamId , s );
641
639
}
642
640
child .onSubscribe (s );
643
641
@@ -704,8 +702,9 @@ private Publisher<Frame> handleRequestChannel(Frame requestFrame,
704
702
Int2ObjectHashMap <SubscriptionArbiter > inFlight ) {
705
703
706
704
UnicastSubject <Payload > channelSubject ;
705
+ final int streamId = requestFrame .getStreamId ();
707
706
synchronized (Responder .this ) {
708
- channelSubject = channels .get (requestFrame . getStreamId () );
707
+ channelSubject = channels .get (streamId );
709
708
}
710
709
if (channelSubject == null ) {
711
710
return child -> {
@@ -722,7 +721,6 @@ public void request(long n) {
722
721
}
723
722
if (started .compareAndSet (false , true )) {
724
723
arbiter .addTransportRequest (n );
725
- final int streamId = requestFrame .getStreamId ();
726
724
727
725
// first request on this channel
728
726
UnicastSubject <Payload > channelRequests =
@@ -816,14 +814,14 @@ public void cancel() {
816
814
817
815
private void cleanup () {
818
816
synchronized (Responder .this ) {
819
- inFlight .remove (requestFrame . getStreamId () );
820
- cancellationSubscriptions .remove (requestFrame . getStreamId () );
817
+ inFlight .remove (streamId );
818
+ cancellationSubscriptions .remove (streamId );
821
819
}
822
820
}
823
821
824
822
};
825
823
synchronized (Responder .this ) {
826
- cancellationSubscriptions .put (requestFrame . getStreamId () , s );
824
+ cancellationSubscriptions .put (streamId , s );
827
825
}
828
826
child .onSubscribe (s );
829
827
@@ -848,7 +846,7 @@ private void cleanup() {
848
846
// handle time-gap issues like this?
849
847
// TODO validate with unit tests.
850
848
return PublisherUtils .errorFrame (
851
- requestFrame . getStreamId () , new RuntimeException ("Channel unavailable" ));
849
+ streamId , new RuntimeException ("Channel unavailable" ));
852
850
}
853
851
}
854
852
}
0 commit comments