Java Code Examples for org.elasticsearch.action.support.PlainActionFuture#newFuture()

The following examples show how to use org.elasticsearch.action.support.PlainActionFuture#newFuture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TcpChannel.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Closes the channels.
 *
 * @param channels to close
 * @param blocking indicates if we should block on channel close
 */
static <C extends TcpChannel> void closeChannels(List<C> channels, boolean blocking) {
    if (blocking) {
        ArrayList<ActionFuture<Void>> futures = new ArrayList<>(channels.size());
        for (final C channel : channels) {
            if (channel.isOpen()) {
                PlainActionFuture<Void> closeFuture = PlainActionFuture.newFuture();
                channel.addCloseListener(closeFuture);
                channel.close();
                futures.add(closeFuture);
            }
        }
        blockOnFutures(futures);
    } else {
        Releasables.close(channels);
    }
}
 
Example 2
Source File: BlobStoreRepositoryTest.java    From crate with Apache License 2.0 6 votes vote down vote up
void assertBlobsByPrefix(BlobPath path, String prefix, Map<String, BlobMetaData> blobs) throws Exception {
    final PlainActionFuture<Map<String, BlobMetaData>> future = PlainActionFuture.newFuture();
    final BlobStoreRepository repository = getRepository();
    repository.threadPool().generic().execute(new ActionRunnable<>(future) {
        @Override
        protected void doRun() throws Exception {
            final BlobStore blobStore = repository.blobStore();
            future.onResponse(blobStore.blobContainer(path).listBlobsByPrefix(prefix));
        }
    });
    Map<String, BlobMetaData> foundBlobs = future.actionGet();
    if (blobs.isEmpty()) {
        assertThat(foundBlobs.keySet(), empty());
    } else {
        assertThat(foundBlobs.keySet(), containsInAnyOrder(blobs.keySet().toArray(Strings.EMPTY_ARRAY)));
        for (Map.Entry<String, BlobMetaData> entry : foundBlobs.entrySet()) {
            assertEquals(entry.getValue().length(), blobs.get(entry.getKey()).length());
        }
    }
}
 
Example 3
Source File: BlobStoreRepositoryTest.java    From crate with Apache License 2.0 6 votes vote down vote up
void assertChildren(BlobPath path, Collection<String> children) throws Exception {
    final PlainActionFuture<Set<String>> future = PlainActionFuture.newFuture();
    final BlobStoreRepository repository = getRepository();
    repository.threadPool().generic().execute(new ActionRunnable<>(future) {
        @Override
        protected void doRun() throws Exception {
            final BlobStore blobStore = repository.blobStore();
            future.onResponse(blobStore.blobContainer(path).children().keySet());
        }
    });
    Set<String> foundChildren = future.actionGet();
    if (children.isEmpty()) {
        assertThat(foundChildren, empty());
    } else {
        assertThat(foundChildren, containsInAnyOrder(children.toArray(Strings.EMPTY_ARRAY)));
    }
}
 
Example 4
Source File: AbstractClient.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public final <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute(
        Action<Request, Response, RequestBuilder> action, Request request) {
    PlainActionFuture<Response> actionFuture = PlainActionFuture.newFuture();
    execute(action, request, actionFuture);
    return actionFuture;
}
 
Example 5
Source File: BlobStoreRepositoryTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testListChildren() throws Exception {
    final BlobStoreRepository repo = getRepository();
    final PlainActionFuture<Void> future = PlainActionFuture.newFuture();
    final Executor genericExec = repo.threadPool().generic();
    final int testBlobLen = randomIntBetween(1, 100);
    genericExec.execute(new ActionRunnable<>(future) {
        @Override
        protected void doRun() throws Exception {
            final BlobStore blobStore = repo.blobStore();
            blobStore.blobContainer(repo.basePath().add("foo"))
                .writeBlob("nested-blob", new ByteArrayInputStream(randomByteArrayOfLength(testBlobLen)), testBlobLen, false);
            blobStore.blobContainer(repo.basePath().add("foo").add("nested"))
                .writeBlob("bar", new ByteArrayInputStream(randomByteArrayOfLength(testBlobLen)), testBlobLen, false);
            blobStore.blobContainer(repo.basePath().add("foo").add("nested2"))
                .writeBlob("blub", new ByteArrayInputStream(randomByteArrayOfLength(testBlobLen)), testBlobLen, false);
            future.onResponse(null);
        }
    });
    future.actionGet();
    assertChildren(repo.basePath(), Collections.singleton("foo"));
    assertBlobsByPrefix(repo.basePath(), "fo", Collections.emptyMap());
    assertChildren(repo.basePath().add("foo"), List.of("nested", "nested2"));
    assertBlobsByPrefix(repo.basePath().add("foo"), "nest",
                        Collections.singletonMap("nested-blob", new PlainBlobMetaData("nested-blob", testBlobLen)));
    assertChildren(repo.basePath().add("foo").add("nested"), Collections.emptyList());
}
 
Example 6
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public final <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder> action, Request request) {
    PlainActionFuture<Response> actionFuture = PlainActionFuture.newFuture();
    execute(action, request, actionFuture);
    return actionFuture;
}
 
Example 7
Source File: Retry.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static SyncRetryHandler create(Class<? extends Throwable> retryOnThrowable, BackoffPolicy backoffPolicy, Client client) {
    PlainActionFuture<BulkResponse> actionFuture = PlainActionFuture.newFuture();
    return new SyncRetryHandler(retryOnThrowable, backoffPolicy, client, actionFuture);
}
 
Example 8
Source File: TransportNodesListGatewayMetaState.java    From crate with Apache License 2.0 4 votes vote down vote up
public ActionFuture<NodesGatewayMetaState> list(DiscoveryNode[] discoveryNodes, @Nullable TimeValue timeout) {
    PlainActionFuture<NodesGatewayMetaState> future = PlainActionFuture.newFuture();
    execute(new Request(discoveryNodes).timeout(timeout), future);
    return future;
}