91
91
import static java .util .Collections .emptyMap ;
92
92
import static java .util .Collections .emptySet ;
93
93
import static org .elasticsearch .common .util .concurrent .ConcurrentCollections .newConcurrentMap ;
94
- import static org .elasticsearch .discovery .zen .ZenPing .PingResponse .readPingResponse ;
95
94
96
95
public class UnicastZenPing extends AbstractComponent implements ZenPing {
97
96
@@ -162,7 +161,7 @@ public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService
162
161
concurrentConnects ,
163
162
resolveTimeout );
164
163
165
- transportService .registerRequestHandler (ACTION_NAME , UnicastPingRequest :: new , ThreadPool .Names .SAME ,
164
+ transportService .registerRequestHandler (ACTION_NAME , ThreadPool .Names .SAME , UnicastPingRequest :: new ,
166
165
new UnicastPingRequestHandler ());
167
166
168
167
final ThreadFactory threadFactory = EsExecutors .daemonThreadFactory (settings , "[unicast_connect]" );
@@ -456,12 +455,8 @@ public ConnectionProfile getConnectionProfile() {
456
455
457
456
458
457
protected void sendPings (final TimeValue timeout , final PingingRound pingingRound ) {
459
- final UnicastPingRequest pingRequest = new UnicastPingRequest ();
460
- pingRequest .id = pingingRound .id ();
461
- pingRequest .timeout = timeout ;
462
- ClusterState lastState = contextProvider .clusterState ();
463
-
464
- pingRequest .pingResponse = createPingResponse (lastState );
458
+ final ClusterState lastState = contextProvider .clusterState ();
459
+ final UnicastPingRequest pingRequest = new UnicastPingRequest (pingingRound .id (), timeout , createPingResponse (lastState ));
465
460
466
461
Set <DiscoveryNode > nodesFromResponses = temporalResponses .stream ().map (pingResponse -> {
467
462
assert clusterName .equals (pingResponse .clusterName ()) :
@@ -553,8 +548,8 @@ protected TransportResponseHandler<UnicastPingResponse> getPingResponseHandler(f
553
548
return new TransportResponseHandler <UnicastPingResponse >() {
554
549
555
550
@ Override
556
- public UnicastPingResponse newInstance () {
557
- return new UnicastPingResponse ();
551
+ public UnicastPingResponse read ( StreamInput in ) throws IOException {
552
+ return new UnicastPingResponse (in );
558
553
}
559
554
560
555
@ Override
@@ -599,11 +594,7 @@ private UnicastPingResponse handlePingRequest(final UnicastPingRequest request)
599
594
List <PingResponse > pingResponses = CollectionUtils .iterableAsArrayList (temporalResponses );
600
595
pingResponses .add (createPingResponse (contextProvider .clusterState ()));
601
596
602
- UnicastPingResponse unicastPingResponse = new UnicastPingResponse ();
603
- unicastPingResponse .id = request .id ;
604
- unicastPingResponse .pingResponses = pingResponses .toArray (new PingResponse [pingResponses .size ()]);
605
-
606
- return unicastPingResponse ;
597
+ return new UnicastPingResponse (request .id , pingResponses .toArray (new PingResponse [pingResponses .size ()]));
607
598
}
608
599
609
600
class UnicastPingRequestHandler implements TransportRequestHandler <UnicastPingRequest > {
@@ -627,21 +618,28 @@ public void messageReceived(UnicastPingRequest request, TransportChannel channel
627
618
628
619
}
629
620
630
- public static class UnicastPingRequest extends TransportRequest {
621
+ static class UnicastPingRequest extends TransportRequest {
631
622
632
- int id ;
633
- TimeValue timeout ;
634
- PingResponse pingResponse ;
623
+ final int id ;
624
+ final TimeValue timeout ;
625
+ final PingResponse pingResponse ;
635
626
636
- public UnicastPingRequest () {
627
+ UnicastPingRequest (int id , TimeValue timeout , PingResponse pingResponse ) {
628
+ this .id = id ;
629
+ this .timeout = timeout ;
630
+ this .pingResponse = pingResponse ;
637
631
}
638
632
639
- @ Override
640
- public void readFrom (StreamInput in ) throws IOException {
641
- super .readFrom (in );
633
+ UnicastPingRequest (StreamInput in ) throws IOException {
634
+ super (in );
642
635
id = in .readInt ();
643
636
timeout = new TimeValue (in );
644
- pingResponse = readPingResponse (in );
637
+ pingResponse = new PingResponse (in );
638
+ }
639
+
640
+ @ Override
641
+ public void readFrom (StreamInput in ) throws IOException {
642
+ throw new UnsupportedOperationException ("usage of Streamable is to be replaced by Writeable" );
645
643
}
646
644
647
645
@ Override
@@ -660,23 +658,28 @@ private PingResponse createPingResponse(ClusterState clusterState) {
660
658
661
659
static class UnicastPingResponse extends TransportResponse {
662
660
663
- int id ;
661
+ final int id ;
664
662
665
- PingResponse [] pingResponses ;
663
+ final PingResponse [] pingResponses ;
666
664
667
- UnicastPingResponse () {
665
+ UnicastPingResponse (int id , PingResponse [] pingResponses ) {
666
+ this .id = id ;
667
+ this .pingResponses = pingResponses ;
668
668
}
669
669
670
- @ Override
671
- public void readFrom (StreamInput in ) throws IOException {
672
- super .readFrom (in );
670
+ UnicastPingResponse (StreamInput in ) throws IOException {
673
671
id = in .readInt ();
674
672
pingResponses = new PingResponse [in .readVInt ()];
675
673
for (int i = 0 ; i < pingResponses .length ; i ++) {
676
- pingResponses [i ] = readPingResponse (in );
674
+ pingResponses [i ] = new PingResponse (in );
677
675
}
678
676
}
679
677
678
+ @ Override
679
+ public void readFrom (StreamInput in ) throws IOException {
680
+ throw new UnsupportedOperationException ("usage of Streamable is to be replaced by Writeable" );
681
+ }
682
+
680
683
@ Override
681
684
public void writeTo (StreamOutput out ) throws IOException {
682
685
super .writeTo (out );
0 commit comments