Java Code Examples for org.elasticsearch.common.util.concurrent.FutureUtils#get()

The following examples show how to use org.elasticsearch.common.util.concurrent.FutureUtils#get() . These examples are extracted from open source projects. 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 Project: crate   File: MasterService.java    License: Apache License 2.0 6 votes vote down vote up
protected void publish(ClusterChangedEvent clusterChangedEvent, TaskOutputs taskOutputs, long startTimeNS) {
    final PlainActionFuture<Void> fut = new PlainActionFuture<Void>() {
        @Override
        protected boolean blockingAllowed() {
            return isMasterUpdateThread() || super.blockingAllowed();
        }
    };
    clusterStatePublisher.publish(clusterChangedEvent, fut, taskOutputs.createAckListener(threadPool, clusterChangedEvent.state()));

    // indefinitely wait for publication to complete
    try {
        FutureUtils.get(fut);
        onPublicationSuccess(clusterChangedEvent, taskOutputs, startTimeNS);
    } catch (Exception e) {
        onPublicationFailed(clusterChangedEvent, taskOutputs, startTimeNS, e);
    }
}
 
Example 2
Source Project: crate   File: StepListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the result of this step. This method will throw {@link IllegalStateException} if this step is not completed yet.
 */
public Response result() {
    if (delegate.isDone() == false) {
        throw new IllegalStateException("step is not completed yet");
    }
    return FutureUtils.get(delegate, 0L, TimeUnit.NANOSECONDS); // this future is done already - use a non-blocking method.
}
 
Example 3
Source Project: crate   File: NodeJoinTests.java    License: Apache License 2.0 5 votes vote down vote up
public void testJoinAccumulation() {
    DiscoveryNode node0 = newNode(0, true);
    DiscoveryNode node1 = newNode(1, true);
    DiscoveryNode node2 = newNode(2, true);
    long initialTerm = randomLongBetween(1, 10);
    long initialVersion = randomLongBetween(1, 10);
    setupFakeMasterServiceAndCoordinator(initialTerm, initialState(node0, initialTerm, initialVersion,
        new VotingConfiguration(Collections.singleton(node2.getId()))));
    assertFalse(isLocalNodeElectedMaster());
    long newTerm = initialTerm + randomLongBetween(1, 10);
    SimpleFuture futNode0 = joinNodeAsync(new JoinRequest(node0, Optional.of(
        new Join(node0, node0, newTerm, initialTerm, initialVersion))));
    deterministicTaskQueue.runAllRunnableTasks();
    assertFalse(futNode0.isDone());
    assertFalse(isLocalNodeElectedMaster());
    SimpleFuture futNode1 = joinNodeAsync(new JoinRequest(node1, Optional.of(
        new Join(node1, node0, newTerm, initialTerm, initialVersion))));
    deterministicTaskQueue.runAllRunnableTasks();
    assertFalse(futNode1.isDone());
    assertFalse(isLocalNodeElectedMaster());
    joinNodeAndRun(new JoinRequest(node2, Optional.of(new Join(node2, node0, newTerm, initialTerm, initialVersion))));
    assertTrue(isLocalNodeElectedMaster());
    assertTrue(clusterStateHasNode(node1));
    assertTrue(clusterStateHasNode(node2));
    FutureUtils.get(futNode0);
    FutureUtils.get(futNode1);
}
 
Example 4
Source Project: crate   File: AdapterActionFuture.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public T actionGet() {
    return FutureUtils.get(this);
}
 
Example 5
Source Project: crate   File: AdapterActionFuture.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public T actionGet(long timeout, TimeUnit unit) {
    return FutureUtils.get(this, timeout, unit);
}
 
Example 6
Source Project: crate   File: NodeJoinTests.java    License: Apache License 2.0 4 votes vote down vote up
private void joinNode(final JoinRequest joinRequest) {
    FutureUtils.get(joinNodeAsync(joinRequest));
}
 
Example 7
Source Project: crate   File: NodeJoinTests.java    License: Apache License 2.0 4 votes vote down vote up
private void joinNodeAndRun(final JoinRequest joinRequest) {
    SimpleFuture fut = joinNodeAsync(joinRequest);
    deterministicTaskQueue.runAllRunnableTasks();
    assertTrue(fut.isDone());
    FutureUtils.get(fut);
}