當前位置: 首頁>>代碼示例>>Java>>正文


Java ActionFuture類代碼示例

本文整理匯總了Java中org.elasticsearch.action.ActionFuture的典型用法代碼示例。如果您正苦於以下問題:Java ActionFuture類的具體用法?Java ActionFuture怎麽用?Java ActionFuture使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ActionFuture類屬於org.elasticsearch.action包,在下文中一共展示了ActionFuture類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
private ActionFuture<String> start(String method, String path, HttpEntity body) {
    PlainActionFuture<String> future = new PlainActionFuture<>();
    Map<String, String> params = new HashMap<>();
    params.put("refresh", "wait_for");
    params.put("error_trace", "");
    client().performRequestAsync(method, docPath() + path, params, body, new ResponseListener() {
        @Override
        public void onSuccess(Response response) {
            try {
                future.onResponse(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
            } catch (IOException e) {
                future.onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception exception) {
            future.onFailure(exception);
        }
    });
    return future;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:WaitForRefreshAndCloseTests.java

示例2: testTokenizer

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
@Test
public void testTokenizer() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest();
    analyzeRequest.text("My œsophagus caused a débâcle");
    /**
     * whitespace (空白字符)分詞器按空白字符 —— 空格、tabs、換行符等等進行簡單拆分
     * letter 分詞器 ,采用另外一種策略,按照任何非字符進行拆分
     * standard 分詞器使用 Unicode 文本分割算法
     */
    analyzeRequest.addTokenFilter("standard");
    analyzeRequest.addCharFilter("asciifolding");
    ActionFuture<AnalyzeResponse> analyzeResponseActionFuture =  client.admin().indices().analyze(analyzeRequest);
    List<AnalyzeResponse.AnalyzeToken> analyzeTokens =  analyzeResponseActionFuture.actionGet().getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken : analyzeTokens){
        System.out.println(analyzeToken.getTerm());
    }
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:18,代碼來源:AnalyzeDemo.java

示例3: ping

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
/**
 * 檢查健康狀態
 *
 * @return
 */
@Override
public boolean ping() {
    try {
        ActionFuture<ClusterHealthResponse> health = esClient.admin().cluster().health(new ClusterHealthRequest());
        ClusterHealthStatus status = health.actionGet().getStatus();
        if (status.value() == ClusterHealthStatus.RED.value()) {
            throw new RuntimeException(
                    "elasticsearch cluster health status is red.");
        }
        return true;
    } catch (Exception e) {
        logger.error("ping elasticsearch error.", e);
        return false;
    }

}
 
開發者ID:aillamsun,項目名稱:spring-boot-elastcsearch-example,代碼行數:22,代碼來源:EsBaseDaoImpl.java

示例4: testTaskManagementOptOut

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
public void testTaskManagementOptOut() throws Exception {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch checkLatch = new CountDownLatch(1);
    // Starting actions that disable task manager
    ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch, new NodesRequest("Test Request", false));

    TestNode testNode = testNodes[randomIntBetween(0, testNodes.length - 1)];

    // Get the parent task
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setActions("testAction*");
    ListTasksResponse response = testNode.transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(0, response.getTasks().size());

    // Release all tasks and wait for response
    checkLatch.countDown();
    NodesResponse responses = future.get();
    assertEquals(0, responses.failureCount());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:TransportTasksActionTests.java

示例5: assertThrows

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
/**
 * Run future.actionGet() and check that it throws an exception of the right type, optionally checking the exception's rest status
 *
 * @param exceptionClass expected exception class
 * @param status         {@link org.elasticsearch.rest.RestStatus} to check for. Can be null to disable the check
 * @param extraInfo      extra information to add to the failure message. Can be null.
 */
public static <E extends Throwable> void assertThrows(ActionFuture future, Class<E> exceptionClass, @Nullable RestStatus status, @Nullable String extraInfo) {
    boolean fail = false;
    extraInfo = extraInfo == null || extraInfo.isEmpty() ? "" : extraInfo + ": ";
    extraInfo += "expected a " + exceptionClass + " exception to be thrown";

    if (status != null) {
        extraInfo += " with status [" + status + "]";
    }

    try {
        future.actionGet();
        fail = true;

    } catch (ElasticsearchException esException) {
        assertThat(extraInfo, esException.unwrapCause(), instanceOf(exceptionClass));
        if (status != null) {
            assertThat(extraInfo, ExceptionsHelper.status(esException), equalTo(status));
        }
    } catch (Exception e) {
        assertThat(extraInfo, e, instanceOf(exceptionClass));
        if (status != null) {
            assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status));
        }
    }
    // has to be outside catch clause to get a proper message
    if (fail) {
        throw new AssertionError(extraInfo);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:37,代碼來源:ElasticsearchAssertions.java

示例6: testElasticsearchTemplateConnection

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
@Test
public void testElasticsearchTemplateConnection() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest();
    analyzeRequest.text("中華人民共和國");
    ActionFuture<AnalyzeResponse> analyzeResponseActionFuture =  elasticsearchTemplate.getClient().admin().indices().analyze(analyzeRequest);
    List<AnalyzeResponse.AnalyzeToken> analyzeTokens =  analyzeResponseActionFuture.actionGet().getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken  : analyzeTokens){
        System.out.println(analyzeToken.getTerm());
    }
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:11,代碼來源:BaseDemo.java

示例7: assertListenerThrows

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
void assertListenerThrows(String msg, ActionFuture<?> listener, Class<?> klass) throws InterruptedException {
    try {
        listener.get();
        fail(msg);
    } catch (ExecutionException ex) {
        assertThat(ex.getCause(), instanceOf(klass));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:TransportMasterNodeActionTests.java

示例8: testTaskNodeFiltering

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
/**
 * This test starts nodes actions that blocks on all nodes. While node actions are blocked in the middle of execution
 * it executes a tasks action that targets these blocked node actions. The test verifies that task actions are only
 * getting executed on nodes that are not listed in the node filter.
 */
public void testTaskNodeFiltering() throws ExecutionException, InterruptedException, IOException {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch checkLatch = new CountDownLatch(1);
    // Start some test nodes action so we could have something to run tasks actions on
    ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch);

    String[] allNodes = new String[testNodes.length];
    for (int i = 0; i < testNodes.length; i++) {
        allNodes[i] = testNodes[i].getNodeId();
    }

    int filterNodesSize = randomInt(allNodes.length);
    Set<String> filterNodes = new HashSet<>(randomSubsetOf(filterNodesSize, allNodes));
    logger.info("Filtering out nodes {} size: {}", filterNodes, filterNodesSize);

    TestTasksAction[] tasksActions = new TestTasksAction[nodesCount];
    for (int i = 0; i < testNodes.length; i++) {
        final int node = i;
        // Simulate a task action that works on all nodes except nodes listed in filterNodes.
        // We are testing that it works.
        tasksActions[i] = new TestTasksAction(CLUSTER_SETTINGS, "testTasksAction", threadPool,
            testNodes[i].clusterService, testNodes[i].transportService) {

            @Override
            protected String[] filterNodeIds(DiscoveryNodes nodes, String[] nodesIds) {
                String[] superNodes = super.filterNodeIds(nodes, nodesIds);
                List<String> filteredNodes = new ArrayList<>();
                for (String node : superNodes) {
                    if (filterNodes.contains(node) == false) {
                        filteredNodes.add(node);
                    }
                }
                return filteredNodes.toArray(new String[filteredNodes.size()]);
            }

            @Override
            protected void taskOperation(TestTasksRequest request, Task task, ActionListener<TestTaskResponse> listener) {
                if (randomBoolean()) {
                    listener.onResponse(new TestTaskResponse(testNodes[node].getNodeId()));
                } else {
                    threadPool.generic().execute(() -> listener.onResponse(new TestTaskResponse(testNodes[node].getNodeId())));
                }
            }
        };
    }

    // Run task action on node tasks that are currently running
    // should be successful on all nodes except nodes that we filtered out
    TestTasksRequest testTasksRequest = new TestTasksRequest();
    testTasksRequest.setActions("testAction[n]"); // pick all test actions
    TestTasksResponse response = tasksActions[randomIntBetween(0, nodesCount - 1)].execute(testTasksRequest).get();

    // Get successful responses from all nodes except nodes that we filtered out
    assertEquals(testNodes.length - filterNodes.size(), response.tasks.size());
    assertEquals(0, response.getTaskFailures().size()); // no task failed
    assertEquals(0, response.getNodeFailures().size()); // no nodes failed

    // Make sure that filtered nodes didn't send any responses
    for (TestTaskResponse taskResponse : response.tasks) {
        String nodeId = taskResponse.getStatus();
        assertFalse("Found response from filtered node " + nodeId, filterNodes.contains(nodeId));
    }

    // Release all node tasks and wait for response
    checkLatch.countDown();
    NodesResponse responses = future.get();
    assertEquals(0, responses.failureCount());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:75,代碼來源:TransportTasksActionTests.java

示例9: putMapping

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
@Override
public ActionFuture<PutMappingResponse> putMapping(final PutMappingRequest request) {
    return execute(PutMappingAction.INSTANCE, request);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:5,代碼來源:AbstractClient.java

示例10: stats

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
@Override
public ActionFuture<IndicesStatsResponse> stats(final IndicesStatsRequest request) {
    return execute(IndicesStatsAction.INSTANCE, request);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:5,代碼來源:AbstractClient.java

示例11: execute

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
@Override
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute(
        Action<Request, Response, RequestBuilder> action, Request request) {
    return client.execute(action, request);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:6,代碼來源:AbstractClient.java

示例12: execute

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
public final ActionFuture<Response> execute(Request request) {
    PlainActionFuture<Response> future = newFuture();
    execute(request, future);
    return future;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:6,代碼來源:TransportAction.java

示例13: list

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
public ActionFuture<NodesGatewayMetaState> list(String[] nodesIds, @Nullable TimeValue timeout) {
    return execute(new Request(nodesIds).timeout(timeout));
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:4,代碼來源:TransportNodesListGatewayMetaState.java

示例14: updateSettings

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
@Override
public ActionFuture<UpdateSettingsResponse> updateSettings(final UpdateSettingsRequest request) {
    return execute(UpdateSettingsAction.INSTANCE, request);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:5,代碼來源:AbstractClient.java

示例15: open

import org.elasticsearch.action.ActionFuture; //導入依賴的package包/類
@Override
public ActionFuture<OpenIndexResponse> open(final OpenIndexRequest request) {
    return execute(OpenIndexAction.INSTANCE, request);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:5,代碼來源:AbstractClient.java


注:本文中的org.elasticsearch.action.ActionFuture類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。