3838import org .elasticsearch .common .io .stream .Writeable ;
3939import org .elasticsearch .common .settings .Settings ;
4040import org .elasticsearch .common .unit .TimeValue ;
41- import org .elasticsearch .discovery .Discovery ;
41+ import org .elasticsearch .discovery .Discovery . FailedToCommitClusterStateException ;
4242import org .elasticsearch .discovery .MasterNotDiscoveredException ;
4343import org .elasticsearch .node .NodeClosedException ;
4444import org .elasticsearch .tasks .Task ;
5353/**
5454 * A base class for operations that needs to be performed on the master node.
5555 */
56- public abstract class TransportMasterNodeAction <Request extends MasterNodeRequest <Request >, Response extends ActionResponse > extends HandledTransportAction <Request , Response > {
56+ public abstract class TransportMasterNodeAction <Request extends MasterNodeRequest <Request >, Response extends ActionResponse >
57+ extends HandledTransportAction <Request , Response > {
58+
5759 protected final ThreadPool threadPool ;
5860 protected final TransportService transportService ;
5961 protected final ClusterService clusterService ;
6062 protected final IndexNameExpressionResolver indexNameExpressionResolver ;
6163
62- final String executor ;
64+ private final String executor ;
6365
6466 protected TransportMasterNodeAction (Settings settings , String actionName , TransportService transportService ,
6567 ClusterService clusterService , ThreadPool threadPool , ActionFilters actionFilters ,
@@ -75,7 +77,8 @@ protected TransportMasterNodeAction(Settings settings, String actionName, Transp
7577
7678 protected TransportMasterNodeAction (Settings settings , String actionName , boolean canTripCircuitBreaker ,
7779 TransportService transportService , ClusterService clusterService , ThreadPool threadPool ,
78- ActionFilters actionFilters , IndexNameExpressionResolver indexNameExpressionResolver , Supplier <Request > request ) {
80+ ActionFilters actionFilters , IndexNameExpressionResolver indexNameExpressionResolver ,
81+ Supplier <Request > request ) {
7982 super (settings , actionName , canTripCircuitBreaker , transportService , actionFilters , request );
8083 this .transportService = transportService ;
8184 this .clusterService = clusterService ;
@@ -138,7 +141,8 @@ class AsyncSingleAction {
138141
139142 public void start () {
140143 ClusterState state = clusterService .state ();
141- this .observer = new ClusterStateObserver (state , clusterService , request .masterNodeTimeout (), logger , threadPool .getThreadContext ());
144+ this .observer
145+ = new ClusterStateObserver (state , clusterService , request .masterNodeTimeout (), logger , threadPool .getThreadContext ());
142146 doStart (state );
143147 }
144148
@@ -174,16 +178,16 @@ public void onResponse(Response response) {
174178
175179 @ Override
176180 public void onFailure (Exception t ) {
177- if (t instanceof Discovery . FailedToCommitClusterStateException
178- || ( t instanceof NotMasterException )) {
179- logger . debug (() -> new ParameterizedMessage ( "master could not publish cluster state or stepped down before publishing action [{}], scheduling a retry" , actionName ), t );
181+ if (t instanceof FailedToCommitClusterStateException || t instanceof NotMasterException ) {
182+ logger . debug (() -> new ParameterizedMessage ( "master could not publish cluster state or " +
183+ " stepped down before publishing action [{}], scheduling a retry" , actionName ), t );
180184 retry (t , masterChangePredicate );
181185 } else {
182186 listener .onFailure (t );
183187 }
184188 }
185189 };
186- threadPool .executor (executor ).execute (new ActionRunnable (delegate ) {
190+ threadPool .executor (executor ).execute (new ActionRunnable < Response > (delegate ) {
187191 @ Override
188192 protected void doRun () throws Exception {
189193 masterOperation (task , request , clusterState , delegate );
@@ -204,7 +208,8 @@ public void handleException(final TransportException exp) {
204208 Throwable cause = exp .unwrapCause ();
205209 if (cause instanceof ConnectTransportException ) {
206210 // we want to retry here a bit to see if a new master is elected
207- logger .debug ("connection exception while trying to forward request with action name [{}] to master node [{}], scheduling a retry. Error: [{}]" ,
211+ logger .debug ("connection exception while trying to forward request with action name [{}] to " +
212+ "master node [{}], scheduling a retry. Error: [{}]" ,
208213 actionName , nodes .getMasterNode (), exp .getDetailedMessage ());
209214 retry (cause , masterChangePredicate );
210215 } else {
@@ -234,7 +239,8 @@ public void onClusterServiceClose() {
234239
235240 @ Override
236241 public void onTimeout (TimeValue timeout ) {
237- logger .debug (() -> new ParameterizedMessage ("timed out while retrying [{}] after failure (timeout [{}])" , actionName , timeout ), failure );
242+ logger .debug (() -> new ParameterizedMessage ("timed out while retrying [{}] after failure (timeout [{}])" ,
243+ actionName , timeout ), failure );
238244 listener .onFailure (new MasterNotDiscoveredException (failure ));
239245 }
240246 }, statePredicate
0 commit comments