All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.client.TasksClient Maven / Gradle / Ivy

There is a newer version: 8.0.0-alpha2
Show newest version
/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.elasticsearch.client;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;

import java.io.IOException;

import static java.util.Collections.emptySet;

/**
 * A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Tasks API.
 * 

* See Task Management API on elastic.co */ public final class TasksClient { private final RestHighLevelClient restHighLevelClient; TasksClient(RestHighLevelClient restHighLevelClient) { this.restHighLevelClient = restHighLevelClient; } /** * Get current tasks using the Task Management API. * See * Task Management API on elastic.co * @param request the request * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized * @return the response * @throws IOException in case there is a problem sending the request or parsing back the response */ public ListTasksResponse list(ListTasksRequest request, RequestOptions options) throws IOException { return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::listTasks, options, ListTasksResponse::fromXContent, emptySet()); } /** * Asynchronously get current tasks using the Task Management API. * See * Task Management API on elastic.co * @param request the request * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized * @param listener the listener to be notified upon request completion */ public void listAsync(ListTasksRequest request, RequestOptions options, ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::listTasks, options, ListTasksResponse::fromXContent, listener, emptySet()); } /** * Cancel one or more cluster tasks using the Task Management API. * * See * Task Management API on elastic.co * @param cancelTasksRequest the request * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized * @return the response * @throws IOException in case there is a problem sending the request or parsing back the response * */ public CancelTasksResponse cancel(CancelTasksRequest cancelTasksRequest, RequestOptions options ) throws IOException { return restHighLevelClient.performRequestAndParseEntity( cancelTasksRequest, RequestConverters::cancelTasks, options, CancelTasksResponse::fromXContent, emptySet() ); } /** * Asynchronously cancel one or more cluster tasks using the Task Management API. * * See * Task Management API on elastic.co * @param cancelTasksRequest the request * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized * @param listener the listener to be notified upon request completion */ public void cancelAsync(CancelTasksRequest cancelTasksRequest, RequestOptions options, ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity( cancelTasksRequest, RequestConverters::cancelTasks, options, CancelTasksResponse::fromXContent, listener, emptySet() ); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy