|
21 | 21 |
|
22 | 22 | import org.apache.logging.log4j.message.ParameterizedMessage;
|
23 | 23 | import org.elasticsearch.action.ActionListener;
|
| 24 | +import org.elasticsearch.action.ActionRunnable; |
24 | 25 | import org.elasticsearch.action.NoShardAvailableActionException;
|
25 | 26 | import org.elasticsearch.action.support.ActionFilters;
|
26 | 27 | import org.elasticsearch.action.support.HandledTransportAction;
|
|
36 | 37 | import org.elasticsearch.cluster.service.ClusterService;
|
37 | 38 | import org.elasticsearch.common.Nullable;
|
38 | 39 | import org.elasticsearch.common.io.stream.StreamInput;
|
39 |
| -import org.elasticsearch.common.util.concurrent.AbstractRunnable; |
40 | 40 | import org.elasticsearch.tasks.Task;
|
41 | 41 | import org.elasticsearch.threadpool.ThreadPool;
|
42 | 42 | import org.elasticsearch.transport.TransportChannel;
|
@@ -287,45 +287,25 @@ class ShardTransportHandler implements TransportRequestHandler<ShardRequest> {
|
287 | 287 |
|
288 | 288 | @Override
|
289 | 289 | public void messageReceived(ShardRequest request, TransportChannel channel, Task task) throws Exception {
|
290 |
| - asyncShardOperation(request, task, new ActionListener<ShardResponse>() { |
291 |
| - @Override |
292 |
| - public void onResponse(ShardResponse response) { |
293 |
| - try { |
294 |
| - channel.sendResponse(response); |
295 |
| - } catch (Exception e) { |
296 |
| - onFailure(e); |
297 |
| - } |
298 |
| - } |
299 |
| - |
300 |
| - @Override |
301 |
| - public void onFailure(Exception e) { |
302 |
| - try { |
303 |
| - channel.sendResponse(e); |
304 |
| - } catch (Exception e1) { |
305 |
| - logger.warn(() -> new ParameterizedMessage( |
306 |
| - "Failed to send error response for action [{}] and request [{}]", actionName, request), e1); |
| 290 | + asyncShardOperation(request, task, |
| 291 | + ActionListener.wrap(channel::sendResponse, e -> { |
| 292 | + try { |
| 293 | + channel.sendResponse(e); |
| 294 | + } catch (Exception e1) { |
| 295 | + logger.warn(() -> new ParameterizedMessage( |
| 296 | + "Failed to send error response for action [{}] and request [{}]", actionName, request), e1); |
| 297 | + } |
307 | 298 | }
|
308 |
| - } |
309 |
| - }); |
| 299 | + )); |
310 | 300 | }
|
311 | 301 | }
|
312 | 302 |
|
313 | 303 | protected void asyncShardOperation(ShardRequest request, Task task, ActionListener<ShardResponse> listener) {
|
314 |
| - transportService.getThreadPool().executor(getExecutor(request)).execute(new AbstractRunnable() { |
315 |
| - @Override |
316 |
| - public void onFailure(Exception e) { |
317 |
| - listener.onFailure(e); |
318 |
| - } |
319 |
| - |
| 304 | + transportService.getThreadPool().executor(shardExecutor).execute(new ActionRunnable<ShardResponse>(listener) { |
320 | 305 | @Override
|
321 | 306 | protected void doRun() throws Exception {
|
322 | 307 | listener.onResponse(shardOperation(request, task));
|
323 | 308 | }
|
324 | 309 | });
|
325 | 310 | }
|
326 |
| - |
327 |
| - protected String getExecutor(ShardRequest request) { |
328 |
| - return shardExecutor; |
329 |
| - } |
330 |
| - |
331 | 311 | }
|
0 commit comments