本文整理匯總了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);
}
示例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()));
}
}
示例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))));
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
}
示例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());
}
}
}
示例10: contains
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Boolean> contains(E element) {
return CompletableFuture.completedFuture(set.contains(element));
}
示例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);
}
示例12: addListener
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Void> addListener(SetEventListener<E> listener) {
listeners.add(listener);
return CompletableFuture.completedFuture(null);
}
示例13: close
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Void> close() {
return client != null ? client.close() : CompletableFuture.completedFuture(null);
}
示例14: getAndAdd
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public CompletableFuture<Long> getAndAdd(long delta) {
return CompletableFuture.completedFuture(value.getAndAdd(delta));
}
示例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);
}