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


Java CompletableFuture.completedFuture方法代碼示例

本文整理匯總了Java中java.util.concurrent.CompletableFuture.completedFuture方法的典型用法代碼示例。如果您正苦於以下問題:Java CompletableFuture.completedFuture方法的具體用法?Java CompletableFuture.completedFuture怎麽用?Java CompletableFuture.completedFuture使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.CompletableFuture的用法示例。


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

示例1: cacheKeysToIds

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Nonnull
@Override
public CompletionStage<Map<String, String>> cacheKeysToIds() {
    if (isCached) {
        return CompletableFuture.completedFuture(keyToIdCache);
    }

    final Consumer<List<Product>> productPageConsumer = productsPage ->
        productsPage.forEach(product -> {
            final String key = product.getKey();
            final String id = product.getId();
            if (StringUtils.isNotBlank(key)) {
                keyToIdCache.put(key, id);
            } else {
                syncOptions.applyWarningCallback(format(PRODUCT_KEY_NOT_SET, id));
            }
        });

    return CtpQueryUtils.queryAll(syncOptions.getCtpClient(), ProductQuery.of(), productPageConsumer)
                        .thenAccept(result -> isCached = true)
                        .thenApply(result -> keyToIdCache);
}
 
開發者ID:commercetools,項目名稱:commercetools-sync-java,代碼行數:23,代碼來源:ProductServiceImpl.java

示例2: applyCallbackAndCreate

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
/**
 * Applies the BeforeCreateCallback function on a supplied draft, then attempts to create it on CTP if it's not
 * empty, then applies the supplied handler on the response from CTP. If the draft was empty after applying the
 * callback an empty optional is returned as the resulting future.
 *
 * @param resourceDraft         draft to apply callback on and then create on CTP.
 * @param draftKey              draft key.
 * @param createCommandFunction the create command query to create the resource on CTP.
 * @return a future containing an optional which might contain the resource if successfully created or empty
 *         otherwise.
 */
@Nonnull
CompletionStage<Optional<U>> applyCallbackAndCreate(
    @Nonnull final V resourceDraft,
    @Nullable final String draftKey,
    @Nonnull final Function<V, DraftBasedCreateCommand<U, V>> createCommandFunction) {
    if (isBlank(draftKey)) {
        syncOptions.applyErrorCallback(format(CREATE_FAILED, draftKey, "Draft key is blank!"));
        return CompletableFuture.completedFuture(Optional.empty());
    } else {
        final BiFunction<U, Throwable, Optional<U>> responseHandler =
            (createdResource, sphereException) ->
                handleResourceCreation(draftKey, createdResource, sphereException);
        return syncOptions.applyBeforeCreateCallBack(resourceDraft)
                          .map(mappedDraft ->
                              syncOptions.getCtpClient()
                                         .execute(createCommandFunction.apply(mappedDraft))
                                         .handle(responseHandler)
                          )
                          .orElseGet(() -> CompletableFuture.completedFuture(Optional.empty()));
    }
}
 
開發者ID:commercetools,項目名稱:commercetools-sync-java,代碼行數:33,代碼來源:BaseService.java

示例3: listAsync

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
/**
 * Return a list of alarms grouped by the rule from which the alarm is
 * created. The list can be paginated, and filtered by device, period of
 * time, status. The list is sorted chronologically, by default starting
 * from the oldest alarm, and optionally from the most recent.
 * <p>
 * The list can also contain zero alarms and only a count of occurrences,
 * for instance to know how many alarms are generated for each rule.
 *
 * @return List of alarms.
 */
public CompletionStage<Result> listAsync(String from, String to, String order, int skip,
                                         int limit, String devices) throws Exception {
    // TODO: move this logic to the storage engine, depending on the
    // storage type the limit will be different. 200 is DocumentDb
    // limit for the IN clause.
    String[] deviceIds = new String[0];
    if (devices != null) {
        deviceIds = devices.split(",");
    }
    if (deviceIds.length > 200) {
        log.warn("The client requested too many devices: {}", deviceIds.length);
        return CompletableFuture.completedFuture(
            badRequest("The number of devices cannot exceed 200"));
    }

    return this.rulesService.getAlarmCountForList(
        DateHelper.parseDate(from),
        DateHelper.parseDate(to),
        order,
        skip,
        limit,
        deviceIds)
        .thenApply(alarmByRuleList -> ok(toJson(
            new AlarmByRuleListApiModel(alarmByRuleList))));
}
 
開發者ID:Azure,項目名稱:device-telemetry-java,代碼行數:37,代碼來源:AlarmsByRuleController.java

示例4: resolveAttributeReference

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
CompletionStage<AttributeDraft> resolveAttributeReference(@Nonnull final AttributeDraft attributeDraft) {
    final JsonNode attributeDraftValue = attributeDraft.getValue();
    if (attributeDraftValue == null) {
        return CompletableFuture.completedFuture(attributeDraft);
    }
    if (attributeDraftValue.isArray()) {
        return resolveAttributeSetReferences(attributeDraft);
    } else {
        if (isProductReference(attributeDraftValue)) {
            return getResolvedIdFromKeyInReference(attributeDraftValue)
                .thenApply(productIdOptional ->
                    productIdOptional.map(productId ->
                        AttributeDraft.of(attributeDraft.getName(), createProductReferenceJson(productId)))
                                     .orElse(attributeDraft));
        }
        return CompletableFuture.completedFuture(attributeDraft);
    }
}
 
開發者ID:commercetools,項目名稱:commercetools-sync-java,代碼行數:19,代碼來源:VariantReferenceResolver.java

示例5: save

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
public CompletableFuture<Void> save(boolean saveInSession, CommonProfile profile, boolean multiProfile) {

        String clientName = this.retrieveClientName(profile);
        Pac4jUser vertxUser = Optional.ofNullable(this.vertxWebContext.getVertxUser()).orElse(new Pac4jUser());
        vertxUser.setUserProfile(clientName, profile, multiProfile);
        this.vertxWebContext.setVertxUser(vertxUser);
        return CompletableFuture.completedFuture(null);
    }
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:9,代碼來源:VertxAsyncProfileManager.java

示例6: close

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Void> close() {
    closeListeners.forEach(listener -> listener.accept(this));
    if (mode == CopycatTransport.Mode.CLIENT) {
        messagingService.unregisterHandler(inboundMessageSubject);
    }
    return CompletableFuture.completedFuture(null);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:9,代碼來源:CopycatTransportConnection.java

示例7: readDepartments

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<List<Department>> readDepartments() {
	try {
		System.out.println("readDepartments CompletableFuture login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
		Thread.sleep(5000);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	return CompletableFuture.completedFuture(departmentDaoImpl.getDepartments());
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:11,代碼來源:DepartmentServiceImpl.java

示例8: getCompletions

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<List<CompletionItem>> getCompletions(CompletableFuture<CamelCatalog> camelCatalog, int positionInCamelUri) {
	if(getStartPosition() <= positionInCamelUri && positionInCamelUri <= getEndPosition()) {
		return camelCatalog.thenApply(new CamelComponentSchemaCompletionsFuture());
	} else {
		return CompletableFuture.completedFuture(Collections.emptyList());
	}
}
 
開發者ID:lhein,項目名稱:camel-language-server,代碼行數:9,代碼來源:CamelURIInstance.java

示例9: nextEvent

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
public CompletableFuture<Change<Leadership>> nextEvent() {
    synchronized (this) {
        if (eventQueue.isEmpty()) {
            if (pendingFuture == null) {
                pendingFuture = new CompletableFuture<>();
            }
            return pendingFuture;
        } else {
            return CompletableFuture.completedFuture(eventQueue.poll());
        }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:13,代碼來源:AtomixLeaderElectorTest.java

示例10: contains

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Boolean> contains(E element) {
    return CompletableFuture.completedFuture(set.contains(element));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:5,代碼來源:TestDistributedSet.java

示例11: set

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public <T> CompletableFuture<Void> set(WebContext<AsyncSessionStore> context, String key, T value) {
    session.put(key, value);
    return CompletableFuture.completedFuture(null);
}
 
開發者ID:millross,項目名稱:pac4j-async,代碼行數:6,代碼來源:VertxAsyncSessionStore.java

示例12: addListener

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Void> addListener(SetEventListener<E> listener) {
    listeners.add(listener);
    return CompletableFuture.completedFuture(null);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:6,代碼來源:TestDistributedSet.java

示例13: close

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Void> close() {
    return client != null ? client.close() : CompletableFuture.completedFuture(null);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:5,代碼來源:StoragePartitionClient.java

示例14: getAndAdd

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Long> getAndAdd(long delta) {
    return CompletableFuture.completedFuture(value.getAndAdd(delta));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:5,代碼來源:TestAtomicCounter.java

示例15: aroundPipelinedSequence

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<List<SmtpResponse>> aroundPipelinedSequence(List<SmtpRequest> requests, Supplier<CompletableFuture<List<SmtpResponse>>> next) {
  return CompletableFuture.completedFuture(DEFAULT_RESPONSE);
}
 
開發者ID:HubSpot,項目名稱:NioSmtpClient,代碼行數:5,代碼來源:CompositeSendInterceptorTest.java


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