2020
2121import org .elasticsearch .action .ActionListener ;
2222import org .elasticsearch .cluster .node .DiscoveryNode ;
23+ import org .elasticsearch .common .component .AbstractComponent ;
2324import org .elasticsearch .common .io .stream .StreamInput ;
25+ import org .elasticsearch .common .settings .Settings ;
2426import org .elasticsearch .threadpool .ThreadPool ;
2527import org .elasticsearch .transport .TransportException ;
2628import org .elasticsearch .transport .TransportRequestOptions ;
2931import org .elasticsearch .transport .TransportService ;
3032
3133import java .io .IOException ;
32- import java .util .function .Consumer ;
34+ import java .util .function .BiConsumer ;
3335import java .util .function .Function ;
3436
35- public class PublicationTransportHandler {
37+ public class PublicationTransportHandler extends AbstractComponent {
3638
3739 public static final String PUBLISH_STATE_ACTION_NAME = "internal:cluster/coordination/publish_state" ;
3840 public static final String COMMIT_STATE_ACTION_NAME = "internal:cluster/coordination/commit_state" ;
3941
4042 private final TransportService transportService ;
4143
42- public PublicationTransportHandler (TransportService transportService ,
44+ public PublicationTransportHandler (Settings settings , TransportService transportService ,
4345 Function <PublishRequest , PublishWithJoinResponse > handlePublishRequest ,
44- Consumer <ApplyCommitRequest > handleApplyCommit ) {
46+ BiConsumer <ApplyCommitRequest , ActionListener <Void >> handleApplyCommit ) {
47+ super (settings );
4548 this .transportService = transportService ;
4649
4750 transportService .registerRequestHandler (PUBLISH_STATE_ACTION_NAME , ThreadPool .Names .GENERIC , false , false ,
@@ -50,10 +53,27 @@ public PublicationTransportHandler(TransportService transportService,
5053
5154 transportService .registerRequestHandler (COMMIT_STATE_ACTION_NAME , ThreadPool .Names .GENERIC , false , false ,
5255 ApplyCommitRequest ::new ,
53- (request , channel , task ) -> {
54- handleApplyCommit .accept (request );
55- channel .sendResponse (TransportResponse .Empty .INSTANCE );
56- });
56+ (request , channel , task ) -> handleApplyCommit .accept (request , new ActionListener <Void >() {
57+
58+ @ Override
59+ public void onResponse (Void aVoid ) {
60+ try {
61+ channel .sendResponse (TransportResponse .Empty .INSTANCE );
62+ } catch (IOException e ) {
63+ logger .debug ("failed to send response on commit" , e );
64+ }
65+ }
66+
67+ @ Override
68+ public void onFailure (Exception e ) {
69+ try {
70+ channel .sendResponse (e );
71+ } catch (IOException ie ) {
72+ e .addSuppressed (ie );
73+ logger .debug ("failed to send response on commit" , e );
74+ }
75+ }
76+ }));
5777 }
5878
5979 public void sendPublishRequest (DiscoveryNode destination , PublishRequest publishRequest ,
0 commit comments