下面列出了java.util.concurrent.CompletableFuture#completedFuture ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(
CompletionParams completionParams) {
String uri = completionParams.getTextDocument().getUri();
LOGGER.debug("completion: {}", uri);
TextDocumentItem doc = openedDocuments.get(uri);
// get applicable completion items
List<CompletionItem> items = completionProvider.getCompletionItems(doc.getText(),
completionParams.getPosition());
// if items exist, return them
if (items != null && !items.isEmpty()) {
return CompletableFuture.completedFuture(Either.forLeft(items));
}
// if items do no exist return empty results
return CompletableFuture.completedFuture(Either.forLeft(Collections.emptyList()));
}
private CompletableFuture<CommandResult> processTellraw(CommandResult parent, String command,
ClassToInstanceMap<Context> contextMap)
{
Text text = TextSerializers.JSON.deserialize(command);
contextMap.getInstance(Context.PLAYER).getPlayer().ifPresent(p -> p.sendMessage(text));
return CompletableFuture.completedFuture(CommandResult.success());
}
@Override
public CompletableFuture<List<CompletionItem>> getCompletions(CompletableFuture<CamelCatalog> camelCatalog, int positionInCamelUri, TextDocumentItem docItem) {
if(getStartPositionInUri() <= positionInCamelUri && positionInCamelUri <= getEndPositionInUri()) {
return camelCatalog.thenApply(new CamelOptionValuesCompletionsFuture(this, getFilter(positionInCamelUri)));
} else {
return CompletableFuture.completedFuture(Collections.emptyList());
}
}
@Override
public CompletableFuture<Void> update() {
ObjectNode body = JsonNodeFactory.instance.objectNode();
if (prepareUpdateBody(body)) {
return new RestRequest<Void>(channel.getApi(), RestMethod.PATCH, RestEndpoint.CHANNEL)
.setUrlParameters(channel.getIdAsString())
.setBody(body)
.setAuditLogReason(reason)
.execute(result -> null);
} else {
return CompletableFuture.completedFuture(null);
}
}
@Override
public CompletionStage<JsonObject> retrievePartialThing(final ThingId thingId,
final JsonFieldSelector jsonFieldSelector,
final DittoHeaders dittoHeaders,
@Nullable final Signal<?> concernedSignal) {
if (concernedSignal instanceof ThingDeleted && !(ProtocolAdapter.isLiveSignal(concernedSignal))) {
// twin deleted events should not be enriched, return empty JsonObject
return CompletableFuture.completedFuture(JsonObject.empty());
}
// as second step only return what was originally requested as fields:
return doRetrievePartialThing(thingId, jsonFieldSelector, dittoHeaders, concernedSignal)
.thenApply(jsonObject -> jsonObject.get(jsonFieldSelector));
}
@Override
public @NotNull CompletableFuture<ResponseInfo<String>> execute(
@NotNull RequestInfo<Void> request,
@NotNull Executor longRunningTaskExecutor,
@NotNull ChannelHandlerContext ctx
) {
if (request.getContent() != null)
throw new IllegalStateException("Since the deserialized type is Void, getContent() should return null. Instead it returned: " + request.getContent());
verifyIncomingPayloadByteHash(request, false);
return CompletableFuture.completedFuture(ResponseInfo.newBuilder("success_void").build());
}
@Override
public @NotNull CompletableFuture<ResponseInfo<String>> execute(
@NotNull RequestInfo<Void> request,
@NotNull Executor longRunningTaskExecutor,
@NotNull ChannelHandlerContext ctx
) {
if ("true".equals(request.getHeaders().get(TRIGGER_DOWNSTREAM_ERROR_HEADER_KEY))) {
throw new RuntimeException("intentional downstream exception");
}
return CompletableFuture.completedFuture(
ResponseInfo.newBuilder(RESPONSE_PAYLOAD).build()
);
}
public CompletableFuture<ArrayList<DiagnosticsNode>> getBoundingBoxes(DiagnosticsNode root, DiagnosticsNode target) {
final JsonObject params = new JsonObject();
if (root == null || target == null || root.getValueRef() == null || target.getValueRef() == null) {
return CompletableFuture.completedFuture(new ArrayList<>());
}
params.addProperty("rootId", root.getValueRef().getId());
params.addProperty("targetId", target.getValueRef().getId());
params.addProperty("groupName", groupName);
return parseDiagnosticsNodesDaemon(
inspectorLibrary.invokeServiceMethod("ext.flutter.inspector.getBoundingBoxes", params).thenApplyAsync((o) -> {
if (o == null) return null;
return o.get("result");
}), null);
}
@Override
public CompletableFuture<RegionLocations> getMetaRegionLocations() {
return CompletableFuture.completedFuture(null);
}
@Incoming("sink-" + DEFAULT_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.NONE)
public CompletionStage<Void> sinkDefBuilder(Message<String> ignored) {
return CompletableFuture.completedFuture(null);
}
@Override
CompletableFuture<Boolean> takeBucketOwnership(int bucket, String processId, Executor executor) {
Preconditions.checkArgument(bucket < getBucketCount());
return CompletableFuture.completedFuture(true);
}
@Override
public CompletableFuture<JobExecutionResult> getJobExecutionResult(ClassLoader userClassloader) {
return CompletableFuture.completedFuture(jobExecutionResult);
}
@Override
public CompletableFuture<Void> writeBack(TestEvent1 event) {
queue.add(event);
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Boolean> removePreferredPartition(Endpoint serverEndpoint, int partitionId) throws InterruptedException {
return CompletableFuture.completedFuture(true);
}
@Override
public CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
return CompletableFuture.completedFuture(Collections.emptyList());
}
@Override
public CompletableFuture<Boolean> containsAll(Collection<? extends E> c) {
return CompletableFuture.completedFuture(collection.containsAll(c));
}
protected CompletableFuture<Void> closeHandlerAsync() {
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<byte[]> get(String id) {
return CompletableFuture.completedFuture(storage.get(id));
}
@Override
public CompletableFuture<Void> authorizeFileRequest(Request request) {
return CompletableFuture.completedFuture(null);
}
/**
* Ping a txn thereby updating its timeout to current time + lease.
*
* Post-condition:
* 1. If ping request completes successfully, then
* (a) txn timeout is set to lease + current time in timeout service,
* (b) txn version in timeout service equals version of txn node in store,
* (c) if txn's timeout was not previously tracked in timeout service of current process,
* then version of txn node in store is updated, thus fencing out other processes tracking timeout for this txn,
* (d) txn is present in the host-txn index of current host,
*
* 2. If process fails before responding to the client, then since txn is present in the host-txn index,
* some other controller process shall abort the txn after maxLeaseValue
*
* Store read/update operation is not invoked on receiving ping request for a txn that is being tracked in the
* timeout service. Otherwise, if the txn is not being tracked in the timeout service, txn node is read from
* the store and updated.
*
* @param scope scope name.
* @param stream stream name.
* @param txnId txn id.
* @param lease txn lease.
* @param ctx context.
* @return ping status.
*/
CompletableFuture<PingTxnStatus> pingTxnBody(final String scope,
final String stream,
final UUID txnId,
final long lease,
final OperationContext ctx) {
if (!timeoutService.isRunning()) {
return CompletableFuture.completedFuture(createStatus(Status.DISCONNECTED));
}
log.debug("Txn={}, updating txn node in store and extending lease", txnId);
return fenceTxnUpdateLease(scope, stream, txnId, lease, ctx);
}