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