Example usage for java.util.concurrent CompletableFuture completedFuture

List of usage examples for java.util.concurrent CompletableFuture completedFuture

Introduction

In this page you can find the example usage for java.util.concurrent CompletableFuture completedFuture.

Prototype

public static <U> CompletableFuture<U> completedFuture(U value) 

Source Link

Document

Returns a new CompletableFuture that is already completed with the given value.

Usage

From source file:io.pravega.controller.store.stream.ZKStream.java

private CompletableFuture<CreateStreamResponse> handleConfigExists(long creationTime,
        boolean creationTimeMatched) {
    CreateStreamResponse.CreateStatus status = creationTimeMatched ? CreateStreamResponse.CreateStatus.NEW
            : CreateStreamResponse.CreateStatus.EXISTS_CREATING;

    return getConfiguration().thenCompose(config -> store.checkExists(statePath).thenCompose(stateExists -> {
        if (!stateExists) {
            return CompletableFuture.completedFuture(new CreateStreamResponse(status, config, creationTime));
        }//from w  w w . j  a  va  2s .  c o  m

        return getState().thenApply(state -> {
            if (state.equals(State.UNKNOWN) || state.equals(State.CREATING)) {
                return new CreateStreamResponse(status, config, creationTime);
            } else {
                return new CreateStreamResponse(CreateStreamResponse.CreateStatus.EXISTS_ACTIVE, config,
                        creationTime);
            }
        });
    }));
}

From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerManagerTest.java

private SegmentContainerRegistry createMockContainerRegistry() {
    SegmentContainerRegistry containerRegistry = mock(SegmentContainerRegistry.class);
    ContainerHandle containerHandle1 = mock(ContainerHandle.class);
    when(containerHandle1.getContainerId()).thenReturn(1);
    when(containerRegistry.startContainer(anyInt(), any()))
            .thenReturn(CompletableFuture.completedFuture(containerHandle1));
    when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
    return containerRegistry;
}

From source file:com.spotify.styx.api.MiddlewaresTest.java

@Test
public void testValidClient() {
    Supplier<Optional<List<String>>> supplier = () -> Optional.of(ImmutableList.of("Styx CLI 0.1.0"));
    RequestContext requestContext = mockRequestContext(true);
    CompletionStage completionStage = CompletableFuture
            .completedFuture(Response.forStatus(Status.OK.withReasonPhrase("")));
    assertThat(Middlewares.clientValidator(supplier).apply(mockInnerHandler(requestContext, completionStage))
            .invoke(requestContext), equalTo(completionStage));
}

From source file:com.ikanow.aleph2.data_model.interfaces.shared_services.MockManagementCrudService.java

@Override
public ManagementFuture<Optional<T>> getObjectBySpec(QueryComponent<T> unique_spec, List<String> field_list,
        boolean include) {
    // Get the 2nd object to diff from getObjectById
    if (_mutable_values.size() > 1) {
        return FutureUtils.createManagementFuture(
                CompletableFuture.completedFuture(_mutable_values.stream().skip(1).findFirst()));
    } else {/*from  w w w  . j  a v a2 s  .  c o m*/
        return FutureUtils.createManagementFuture(CompletableFuture.completedFuture(Optional.empty()));
    }
}

From source file:io.pravega.client.stream.mock.MockController.java

@Override
@Synchronized//from  www  .  jav a2 s .  c  om
public CompletableFuture<Boolean> deleteStream(String scope, String streamName) {
    Stream stream = new StreamImpl(scope, streamName);
    if (createdStreams.get(stream) == null) {
        return CompletableFuture.completedFuture(false);
    }
    for (Segment segment : getSegmentsForStream(stream)) {
        deleteSegment(segment.getScopedName(), new PravegaNodeUri(endpoint, port));
    }
    createdStreams.remove(stream);
    createdScopes.get(scope).remove(stream);
    return CompletableFuture.completedFuture(true);
}

From source file:io.pravega.controller.store.stream.InMemoryStream.java

@Override
CompletableFuture<StreamConfiguration> getConfigurationData() {
    synchronized (lock) {
        if (this.configuration == null) {
            return FutureHelpers
                    .failedFuture(StoreException.create(StoreException.Type.DATA_NOT_FOUND, getName()));
        }/* w ww .j a  va  2 s .com*/
        return CompletableFuture.completedFuture(this.configuration);
    }
}

From source file:io.sqp.client.impl.SqpConnectionImpl.java

@Override
public synchronized CompletableFuture<Void> setAutoCommit(boolean useAutoCommit) {
    if (useAutoCommit == _autocommit) {
        return CompletableFuture.completedFuture(null);
    }// w  w w  . jav  a  2s  .c om
    CompletableFuture<Void> future = new CompletableFuture<>();
    if (!checkOpenAndNoErrors(future)) {
        return future;
    }
    send(new SetFeatureMessage().setAutoCommit(useAutoCommit), new ConfirmationResponseHandler(future,
            MessageType.SetFeatureCompleteMessage, "waiting for a server settings complete message"));
    return future.thenApply(v -> {
        _autocommit = useAutoCommit;
        return null;
    });
}

From source file:com.ikanow.aleph2.data_model.interfaces.shared_services.MockManagementCrudService.java

@Override
public ManagementFuture<Optional<T>> getObjectById(Object id) {
    return FutureUtils
            .createManagementFuture(CompletableFuture.completedFuture(_mutable_values.stream().findFirst()));
}

From source file:com.ikanow.aleph2.storage_service_hdfs.services.HfdsDataWriteService.java

@Override
public CompletableFuture<Supplier<Object>> storeObject(T new_object) {
    setup();/*from w  w  w.j a  v  a2  s. c o  m*/
    _writer.get().storeObject(new_object);
    return CompletableFuture.completedFuture(() -> {
        return null;
    });
}

From source file:com.spotify.styx.api.MiddlewaresTest.java

@Test
public void testValidClientNoHeader() {
    Supplier<Optional<List<String>>> supplier = () -> Optional.of(ImmutableList.of("Styx CLI 0.1.0"));
    RequestContext requestContext = mockRequestContext(false);
    CompletionStage completionStage = CompletableFuture
            .completedFuture(Response.forStatus(Status.OK.withReasonPhrase("")));
    assertThat(Middlewares.clientValidator(supplier).apply(mockInnerHandler(requestContext, completionStage))
            .invoke(requestContext), equalTo(completionStage));
}