capnproto-java-rpc/runtime/src/main/java/org/capnproto/ClientHook.java

57 lines
1.5 KiB
Java
Raw Normal View History

package org.capnproto;
import java.util.concurrent.CompletableFuture;
2020-10-13 16:19:24 +00:00
import java.util.concurrent.CompletionStage;
public interface ClientHook {
Object NULL_CAPABILITY_BRAND = new Object();
Object BROKEN_CAPABILITY_BRAND = new Object();
2020-10-13 16:19:24 +00:00
Request<AnyPointer.Builder, AnyPointer.Pipeline> newCall(long interfaceId, short methodId);
VoidPromiseAndPipeline call(long interfaceId, short methodId, CallContextHook context);
default ClientHook getResolved() {
return null;
}
2020-10-13 16:19:24 +00:00
default CompletionStage<ClientHook> whenMoreResolved() {
return null;
}
default Object getBrand() {
return NULL_CAPABILITY_BRAND;
}
2020-10-13 16:19:24 +00:00
default CompletionStage<?> whenResolved() {
var promise = whenMoreResolved();
return promise != null
? promise.thenCompose(ClientHook::whenResolved)
: CompletableFuture.completedFuture(null);
}
default boolean isNull() {
return getBrand() == NULL_CAPABILITY_BRAND;
}
default boolean isError() {
return getBrand() == BROKEN_CAPABILITY_BRAND;
}
default Integer getFd() {
return null;
}
final class VoidPromiseAndPipeline {
2020-10-20 20:42:20 +00:00
public final CompletionStage<java.lang.Void> promise;
public final PipelineHook pipeline;
2020-10-20 20:42:20 +00:00
VoidPromiseAndPipeline(CompletionStage<java.lang.Void> promise, PipelineHook pipeline) {
this.promise = promise;
this.pipeline = pipeline;
}
}
}