46
46
import org .elasticsearch .core .internal .io .IOUtils ;
47
47
import org .elasticsearch .node .NodeClosedException ;
48
48
import org .elasticsearch .tasks .Task ;
49
- import org .elasticsearch .tasks .TaskCancelledException ;
50
49
import org .elasticsearch .tasks .TaskManager ;
51
50
import org .elasticsearch .threadpool .Scheduler ;
52
51
import org .elasticsearch .threadpool .ThreadPool ;
@@ -519,37 +518,57 @@ public void removeConnectionListener(TransportConnectionListener listener) {
519
518
public <T extends TransportResponse > void sendRequest (final DiscoveryNode node , final String action ,
520
519
final TransportRequest request ,
521
520
final TransportResponseHandler <T > handler ) {
521
+ final Transport .Connection connection ;
522
522
try {
523
- Transport .Connection connection = getConnection (node );
524
- sendRequest (connection , action , request , TransportRequestOptions .EMPTY , handler );
525
- } catch (NodeNotConnectedException ex ) {
523
+ connection = getConnection (node );
524
+ } catch (final NodeNotConnectedException ex ) {
526
525
// the caller might not handle this so we invoke the handler
527
526
handler .handleException (ex );
527
+ return ;
528
528
}
529
+ sendRequest (connection , action , request , TransportRequestOptions .EMPTY , handler );
529
530
}
530
531
531
532
public final <T extends TransportResponse > void sendRequest (final DiscoveryNode node , final String action ,
532
533
final TransportRequest request ,
533
534
final TransportRequestOptions options ,
534
535
TransportResponseHandler <T > handler ) {
536
+ final Transport .Connection connection ;
535
537
try {
536
- Transport .Connection connection = getConnection (node );
537
- sendRequest (connection , action , request , options , handler );
538
- } catch (NodeNotConnectedException ex ) {
538
+ connection = getConnection (node );
539
+ } catch (final NodeNotConnectedException ex ) {
539
540
// the caller might not handle this so we invoke the handler
540
541
handler .handleException (ex );
542
+ return ;
541
543
}
544
+ sendRequest (connection , action , request , options , handler );
542
545
}
543
546
547
+ /**
548
+ * Sends a request on the specified connection. If there is a failure sending the request, the specified handler is invoked.
549
+ *
550
+ * @param connection the connection to send the request on
551
+ * @param action the name of the action
552
+ * @param request the request
553
+ * @param options the options for this request
554
+ * @param handler the response handler
555
+ * @param <T> the type of the transport response
556
+ */
544
557
public final <T extends TransportResponse > void sendRequest (final Transport .Connection connection , final String action ,
545
558
final TransportRequest request ,
546
559
final TransportRequestOptions options ,
547
560
TransportResponseHandler <T > handler ) {
548
561
try {
549
562
asyncSender .sendRequest (connection , action , request , options , handler );
550
- } catch (NodeNotConnectedException ex ) {
563
+ } catch (final Exception ex ) {
551
564
// the caller might not handle this so we invoke the handler
552
- handler .handleException (ex );
565
+ final TransportException te ;
566
+ if (ex instanceof TransportException ) {
567
+ te = (TransportException ) ex ;
568
+ } else {
569
+ te = new TransportException ("failure to send" , ex );
570
+ }
571
+ handler .handleException (te );
553
572
}
554
573
}
555
574
@@ -569,13 +588,15 @@ public final <T extends TransportResponse> void sendChildRequest(final Discovery
569
588
final TransportRequest request , final Task parentTask ,
570
589
final TransportRequestOptions options ,
571
590
final TransportResponseHandler <T > handler ) {
591
+ final Transport .Connection connection ;
572
592
try {
573
- Transport .Connection connection = getConnection (node );
574
- sendChildRequest (connection , action , request , parentTask , options , handler );
575
- } catch (NodeNotConnectedException ex ) {
593
+ connection = getConnection (node );
594
+ } catch (final NodeNotConnectedException ex ) {
576
595
// the caller might not handle this so we invoke the handler
577
596
handler .handleException (ex );
597
+ return ;
578
598
}
599
+ sendChildRequest (connection , action , request , parentTask , options , handler );
579
600
}
580
601
581
602
public <T extends TransportResponse > void sendChildRequest (final Transport .Connection connection , final String action ,
@@ -589,16 +610,7 @@ public <T extends TransportResponse> void sendChildRequest(final Transport.Conne
589
610
final TransportRequestOptions options ,
590
611
final TransportResponseHandler <T > handler ) {
591
612
request .setParentTask (localNode .getId (), parentTask .getId ());
592
- try {
593
- sendRequest (connection , action , request , options , handler );
594
- } catch (TaskCancelledException ex ) {
595
- // The parent task is already cancelled - just fail the request
596
- handler .handleException (new TransportException (ex ));
597
- } catch (NodeNotConnectedException ex ) {
598
- // the caller might not handle this so we invoke the handler
599
- handler .handleException (ex );
600
- }
601
-
613
+ sendRequest (connection , action , request , options , handler );
602
614
}
603
615
604
616
private <T extends TransportResponse > void sendRequestInternal (final Transport .Connection connection , final String action ,
0 commit comments