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