Skip to content

Commit ca78d92

Browse files
authored
Remove LegacyCTRAListener usage in MasterService (#83796)
Relates #83784
1 parent 57be456 commit ca78d92

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

server/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private void waitForEventsAndExecuteHealth(
112112
if (request.local()) {
113113
new LocalMasterServiceTask(request.waitForEvents()) {
114114
@Override
115-
public void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
115+
protected void onPublicationComplete() {
116116
final long timeoutInMillis = Math.max(0, endTimeRelativeMillis - threadPool.relativeTimeInMillis());
117117
final TimeValue newTimeout = TimeValue.timeValueMillis(timeoutInMillis);
118118
request.timeout(newTimeout);

server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskExecutor.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,17 @@ public ClusterTasksResult<T> execute(ClusterState currentState, List<T> tasks) t
157157
assert tasks.size() == 1 : "this only supports a single task but received " + tasks;
158158
final T task = tasks.get(0);
159159
final ClusterState newState = task.execute(currentState);
160-
return ClusterTasksResult.<T>builder()
161-
.success(task, new LegacyClusterTaskResultActionListener(task, currentState))
162-
.build(newState);
160+
return ClusterTasksResult.<T>builder().success(task, new ActionListener<>() {
161+
@Override
162+
public void onResponse(ClusterState publishedState) {
163+
task.clusterStateProcessed(currentState, publishedState);
164+
}
165+
166+
@Override
167+
public void onFailure(Exception e) {
168+
task.onFailure(e);
169+
}
170+
}).build(newState);
163171
}
164172

165173
@Override

server/src/main/java/org/elasticsearch/cluster/LocalMasterServiceTask.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
package org.elasticsearch.cluster;
99

10+
import org.elasticsearch.action.ActionListener;
1011
import org.elasticsearch.cluster.service.MasterService;
1112
import org.elasticsearch.common.Priority;
1213

@@ -23,7 +24,14 @@ public LocalMasterServiceTask(Priority priority) {
2324
this.priority = priority;
2425
}
2526

26-
public void execute(ClusterState currentState) throws Exception {}
27+
protected void execute(ClusterState currentState) throws Exception {}
28+
29+
@Override
30+
public final void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
31+
assert false : "not called";
32+
}
33+
34+
protected void onPublicationComplete() {}
2735

2836
public void submit(MasterService masterService, String source) {
2937
masterService.submitStateUpdateTask(
@@ -51,9 +59,17 @@ public ClusterTasksResult<LocalMasterServiceTask> execute(ClusterState currentSt
5159
assert tasks.size() == 1 && tasks.get(0) == thisTask
5260
: "expected one-element task list containing current object but was " + tasks;
5361
thisTask.execute(currentState);
54-
return ClusterTasksResult.<LocalMasterServiceTask>builder()
55-
.success(thisTask, new LegacyClusterTaskResultActionListener(thisTask, currentState))
56-
.build(currentState);
62+
return ClusterTasksResult.<LocalMasterServiceTask>builder().success(thisTask, new ActionListener<>() {
63+
@Override
64+
public void onResponse(ClusterState clusterState) {
65+
onPublicationComplete();
66+
}
67+
68+
@Override
69+
public void onFailure(Exception e) {
70+
LocalMasterServiceTask.this.onFailure(e);
71+
}
72+
}).build(currentState);
5773
}
5874
}
5975
);

0 commit comments

Comments
 (0)