20
20
import org .elasticsearch .common .settings .Settings ;
21
21
import org .elasticsearch .tasks .Task ;
22
22
import org .elasticsearch .tasks .TaskCancelledException ;
23
- import org .elasticsearch .tasks .TaskListener ;
24
23
import org .elasticsearch .tasks .TaskManager ;
25
24
import org .elasticsearch .threadpool .ThreadPool ;
26
25
import org .elasticsearch .transport .RemoteClusterService ;
@@ -41,7 +40,7 @@ public class NodeClient extends AbstractClient {
41
40
42
41
/**
43
42
* The id of the local {@link DiscoveryNode}. Useful for generating task ids from tasks returned by
44
- * {@link #executeLocally(ActionType, ActionRequest, TaskListener )}.
43
+ * {@link #executeLocally(ActionType, ActionRequest, ActionListener )}.
45
44
*/
46
45
private Supplier <String > localNodeId ;
47
46
private Transport .Connection localConnection ;
@@ -115,27 +114,13 @@ public <Request extends ActionRequest, Response extends ActionResponse> Task exe
115
114
transportAction (action ),
116
115
request ,
117
116
localConnection ,
118
- new ActionResponseTaskListener <>(listener )
117
+ new SafelyWrappedActionListener <>(listener )
119
118
);
120
119
}
121
120
122
- /**
123
- * Execute an {@link ActionType} locally, returning that {@link Task} used to track it, and linking an {@link TaskListener}.
124
- * Prefer this method if you need access to the task when listening for the response.
125
- *
126
- * @throws TaskCancelledException if the request's parent task has been cancelled already
127
- */
128
- public <Request extends ActionRequest , Response extends ActionResponse > Task executeLocally (
129
- ActionType <Response > action ,
130
- Request request ,
131
- TaskListener <Response > listener
132
- ) {
133
- return taskManager .registerAndExecute ("transport" , transportAction (action ), request , localConnection , listener );
134
- }
135
-
136
121
/**
137
122
* The id of the local {@link DiscoveryNode}. Useful for generating task ids from tasks returned by
138
- * {@link #executeLocally(ActionType, ActionRequest, TaskListener )}.
123
+ * {@link #executeLocally(ActionType, ActionRequest, ActionListener )}.
139
124
*/
140
125
public String getLocalNodeId () {
141
126
return localNodeId .get ();
@@ -167,10 +152,10 @@ public NamedWriteableRegistry getNamedWriteableRegistry() {
167
152
return namedWriteableRegistry ;
168
153
}
169
154
170
- private record ActionResponseTaskListener <Response > (ActionListener <Response > listener ) implements TaskListener <Response > {
155
+ private record SafelyWrappedActionListener <Response > (ActionListener <Response > listener ) implements ActionListener <Response > {
171
156
172
157
@ Override
173
- public void onResponse (Task task , Response response ) {
158
+ public void onResponse (Response response ) {
174
159
try {
175
160
listener .onResponse (response );
176
161
} catch (Exception e ) {
@@ -180,7 +165,7 @@ public void onResponse(Task task, Response response) {
180
165
}
181
166
182
167
@ Override
183
- public void onFailure (Task task , Exception e ) {
168
+ public void onFailure (Exception e ) {
184
169
try {
185
170
listener .onFailure (e );
186
171
} catch (Exception ex ) {
0 commit comments