@Override public void onResponse(Response response) { if (task != null) { taskManager.unregister(task); } listener.onResponse(task, response); }
@Override public void onFailure(Exception e) { if (task != null) { taskManager.unregister(task); } listener.onFailure(task, e); } });
/** * Build a proper {@link TaskInfo} for this task. */ protected final TaskInfo taskInfo(String localNodeId, String description, Status status) { return new TaskInfo(new TaskId(localNodeId, getId()), getType(), getAction(), description, status, startTime, System.nanoTime() - startTimeNanos, this instanceof CancellableTask, parentTask, headers); }
/** * Set a reference to task that created this request. */ void setParentTask(TaskId taskId);
public boolean hasParent(TaskId parentTaskId) { return task.getParentTaskId().equals(parentTaskId); }
public TaskResult result(DiscoveryNode node, Exception error) throws IOException { return new TaskResult(taskInfo(node.getId(), true), error); }
/** * Returns the task object that should be used to keep track of the processing of the request. * * A request can override this method and return null to avoid being tracked by the task * manager. */ default Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { return new Task(id, type, action, getDescription(), parentTaskId, headers); }
@Override public String toString() { if (isSet()) { return nodeId + ":" + id; } else { return "unset"; } }
private static Request rethrottle(RethrottleRequest rethrottleRequest, String firstPathPart) { String endpoint = new EndpointBuilder().addPathPart(firstPathPart) .addPathPart(rethrottleRequest.getTaskId().toString()).addPathPart("_rethrottle").build(); Request request = new Request(HttpMethod.POST.name(), endpoint); Params params = new Params(request).withRequestsPerSecond(rethrottleRequest.getRequestsPerSecond()); // we set "group_by" to "none" because this is the response format we can parse back params.putParam("group_by", "none"); return request; }
private void endTask() { taskManager.unregister(task); } }
protected TaskManager createTaskManager(Settings settings, ThreadPool threadPool, Set<String> taskHeaders) { return new TaskManager(settings, threadPool, taskHeaders); }
@Override protected TaskInfo readTaskResponse(StreamInput in) throws IOException { return new TaskInfo(in); }
/** * Marks task as cancelled. * <p> * Returns true if cancellation was successful, false otherwise. */ public boolean cancel(String reason) { return cancel(reason, null); }
public long getId() { return taskId.getId(); }
/** * Construct a {@linkplain TaskResult} for a task that completed with an error. */ public TaskResult(TaskInfo task, Exception error) throws IOException { this(true, task, toXContent(error), null); }
public TransportRequest(StreamInput in) throws IOException { parentTaskId = TaskId.readFromStream(in); }
@Override protected TaskInfo readTaskResponse(StreamInput in) throws IOException { return new TaskInfo(in); }