19
19
20
20
#include < folly/tracing/StaticTracepoint.h>
21
21
22
+ #include < thrift/lib/cpp/StreamEventHandler.h>
22
23
#include < thrift/lib/cpp2/async/InterceptorFlags.h>
23
24
#include < thrift/lib/cpp2/detail/EventHandlerRuntime.h>
24
25
#include < thrift/lib/cpp2/server/Cpp2ConnContext.h>
@@ -369,7 +370,9 @@ void ContextStack::onStreamSubscribe() {
369
370
370
371
if (handlers_) {
371
372
for (size_t i = 0 ; i < handlers_->size (); i++) {
372
- (*handlers_)[i]->onStreamSubscribe (contextAt (i));
373
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
374
+ streamEventHandler->onStreamSubscribe (contextAt (i));
375
+ }
373
376
}
374
377
}
375
378
}
@@ -382,7 +385,9 @@ void ContextStack::onStreamCredit(uint32_t credits) {
382
385
methodNamePrefixed_);
383
386
if (handlers_) {
384
387
for (size_t i = 0 ; i < handlers_->size (); i++) {
385
- (*handlers_)[i]->onStreamCredit (contextAt (i), credits);
388
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
389
+ streamEventHandler->onStreamCredit (contextAt (i), credits);
390
+ }
386
391
}
387
392
}
388
393
}
@@ -395,7 +400,9 @@ void ContextStack::onStreamNext() {
395
400
methodNamePrefixed_);
396
401
if (handlers_) {
397
402
for (size_t i = 0 ; i < handlers_->size (); i++) {
398
- (*handlers_)[i]->onStreamNext (contextAt (i));
403
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
404
+ streamEventHandler->onStreamNext (contextAt (i));
405
+ }
399
406
}
400
407
}
401
408
}
@@ -409,7 +416,9 @@ void ContextStack::onStreamPauseReceive() {
409
416
410
417
if (handlers_) {
411
418
for (size_t i = 0 ; i < handlers_->size (); i++) {
412
- (*handlers_)[i]->onStreamPauseReceive (contextAt (i));
419
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
420
+ streamEventHandler->onStreamPauseReceive (contextAt (i));
421
+ }
413
422
}
414
423
}
415
424
}
@@ -423,7 +432,9 @@ void ContextStack::onStreamResumeReceive() {
423
432
424
433
if (handlers_) {
425
434
for (size_t i = 0 ; i < handlers_->size (); i++) {
426
- (*handlers_)[i]->onStreamResumeReceive (contextAt (i));
435
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
436
+ streamEventHandler->onStreamResumeReceive (contextAt (i));
437
+ }
427
438
}
428
439
}
429
440
}
@@ -438,7 +449,9 @@ void ContextStack::handleStreamErrorWrapped(
438
449
439
450
if (handlers_) {
440
451
for (size_t i = 0 ; i < handlers_->size (); i++) {
441
- (*handlers_)[i]->handleStreamErrorWrapped (contextAt (i), ew);
452
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
453
+ streamEventHandler->handleStreamErrorWrapped (contextAt (i), ew);
454
+ }
442
455
}
443
456
}
444
457
}
@@ -452,7 +465,9 @@ void ContextStack::onStreamFinally(details::STREAM_ENDING_TYPES endReason) {
452
465
453
466
if (handlers_) {
454
467
for (size_t i = 0 ; i < handlers_->size (); i++) {
455
- (*handlers_)[i]->onStreamFinally (contextAt (i), endReason);
468
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
469
+ streamEventHandler->onStreamFinally (contextAt (i), endReason);
470
+ }
456
471
}
457
472
}
458
473
}
@@ -465,7 +480,9 @@ void ContextStack::onSinkSubscribe() {
465
480
methodNamePrefixed_);
466
481
if (handlers_) {
467
482
for (size_t i = 0 ; i < handlers_->size (); i++) {
468
- (*handlers_)[i]->onSinkSubscribe (contextAt (i));
483
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
484
+ streamEventHandler->onSinkSubscribe (contextAt (i));
485
+ }
469
486
}
470
487
}
471
488
}
@@ -478,7 +495,9 @@ void ContextStack::onSinkNext() {
478
495
methodNamePrefixed_);
479
496
if (handlers_) {
480
497
for (size_t i = 0 ; i < handlers_->size (); i++) {
481
- (*handlers_)[i]->onSinkNext (contextAt (i));
498
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
499
+ streamEventHandler->onSinkNext (contextAt (i));
500
+ }
482
501
}
483
502
}
484
503
}
@@ -491,7 +510,9 @@ void ContextStack::onSinkCancel() {
491
510
methodNamePrefixed_);
492
511
if (handlers_) {
493
512
for (size_t i = 0 ; i < handlers_->size (); i++) {
494
- (*handlers_)[i]->onSinkCancel (contextAt (i));
513
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
514
+ streamEventHandler->onSinkCancel (contextAt (i));
515
+ }
495
516
}
496
517
}
497
518
}
@@ -504,7 +525,9 @@ void ContextStack::onSinkCredit(uint32_t credits) {
504
525
methodNamePrefixed_);
505
526
if (handlers_) {
506
527
for (size_t i = 0 ; i < handlers_->size (); i++) {
507
- (*handlers_)[i]->onSinkCredit (contextAt (i), credits);
528
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
529
+ streamEventHandler->onSinkCredit (contextAt (i), credits);
530
+ }
508
531
}
509
532
}
510
533
}
@@ -518,7 +541,9 @@ void ContextStack::onSinkFinally(details::SINK_ENDING_TYPES endReason) {
518
541
519
542
if (handlers_) {
520
543
for (size_t i = 0 ; i < handlers_->size (); i++) {
521
- (*handlers_)[i]->onSinkFinally (contextAt (i), endReason);
544
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
545
+ streamEventHandler->onSinkFinally (contextAt (i), endReason);
546
+ }
522
547
}
523
548
}
524
549
}
@@ -532,7 +557,9 @@ void ContextStack::handleSinkError(const folly::exception_wrapper& ew) {
532
557
533
558
if (handlers_) {
534
559
for (size_t i = 0 ; i < handlers_->size (); i++) {
535
- (*handlers_)[i]->handleSinkError (contextAt (i), ew);
560
+ if (auto * streamEventHandler = (*handlers_)[i]->getStreamEventHandler ()) {
561
+ streamEventHandler->handleSinkError (contextAt (i), ew);
562
+ }
536
563
}
537
564
}
538
565
}
0 commit comments