当前位置: 首页>>代码示例>>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;未经允许,请勿转载。